Skip to content

Commit e8d5d45

Browse files
committed
Refactoring formats
1 parent 6ff5e46 commit e8d5d45

File tree

7 files changed

+201
-99
lines changed

7 files changed

+201
-99
lines changed

src/ansi/controls/controls.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@ const controls = {
1717

1818
export default controls;
1919

20+
/**
21+
* This type gets generated from the values of {@linkcode controls}.
22+
*/
2023
export type Control = C0Control | C1Control;

src/ansi/formats/colors.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { ValuesFromObject } from "../../type/mod.ts";
2+
3+
/**
4+
* This object contains all color format codes.
5+
*
6+
* Use the control sequence `CSI <colors.<color>> m`, named Select Graphic Rendition (SGR), to set color format
7+
* attributes.
8+
*
9+
* [Wikipedia](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters)
10+
*/
11+
const colors = {
12+
// FOREGROUND_COLOR: 30 - 37
13+
/** Set foreground [color](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) */
14+
FOREGROUND_COLOR: '38',
15+
/** Default foreground color */
16+
FOREGROUND_COLOR_DEFAULT: '39',
17+
// BACKGROUND_COLOR: 40 - 47
18+
/** Set background [color](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) */
19+
BACKGROUND_COLOR: '48',
20+
/** Default background color */
21+
BACKGROUND_COLOR_DEFAULT: '49',
22+
/** Set underline [color](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) */
23+
UNDERLINE_COLOR: '58',
24+
/** Default underline color */
25+
UNDERLINE_COLOR_DEFAULT: '59',
26+
/** [Reverse video](https://en.wikipedia.org/wiki/Reverse_video) or invert */
27+
SWAP_FOREGROUND_BACKGROUND_COLOR: '7',
28+
} as const;
29+
30+
export default colors;
31+
32+
/**
33+
* This type gets generated from the values of {@linkcode colors}.
34+
*/
35+
export type Color = ValuesFromObject<typeof colors>;

src/ansi/formats/fonts.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { ValuesFromObject } from "../../type/mod.ts";
2+
3+
/**
4+
* This object contains all font format codes.
5+
*
6+
* Use the control sequence `CSI <fonts.<font>> m`, named Select Graphic Rendition (SGR), to set font format attributes.
7+
*
8+
* [Wikipedia](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters)
9+
*/
10+
const fonts = {
11+
/** Primary (default) font */
12+
FONT_DEFAULT: '10',
13+
/** Alternative font 1 */
14+
FONT_ALTERNATIVE_1: '11',
15+
/** Alternative font 2 */
16+
FONT_ALTERNATIVE_2: '12',
17+
/** Alternative font 3 */
18+
FONT_ALTERNATIVE_3: '13',
19+
/** Alternative font 4 */
20+
FONT_ALTERNATIVE_4: '14',
21+
/** Alternative font 5 */
22+
FONT_ALTERNATIVE_5: '15',
23+
/** Alternative font 6 */
24+
FONT_ALTERNATIVE_6: '16',
25+
/** Alternative font 7 */
26+
FONT_ALTERNATIVE_7: '17',
27+
/** Alternative font 8 */
28+
FONT_ALTERNATIVE_8: '18',
29+
/** Alternative font 9 */
30+
FONT_ALTERNATIVE_9: '19',
31+
/** [Fraktur](https://en.wikipedia.org/wiki/Fraktur) (Gothic) */
32+
FONT_FRACTURE: '20',
33+
} as const;
34+
35+
export default fonts;
36+
37+
/**
38+
* This type gets generated from the values of {@linkcode fonts}.
39+
*/
40+
export type Font = ValuesFromObject<typeof fonts>;

src/ansi/formats/format.ts

Lines changed: 10 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
import { ValuesFromObject } from "../../type/mod.ts";
2+
import colors from './colors.ts';
3+
import fonts from './fonts.ts';
4+
import ideograms from './ideograms.ts';
5+
import scripts from './scripts.ts';
6+
import textDecorations from './text_decoreations.ts';
27

38
/**
49
* This object contains all format codes.
@@ -10,113 +15,19 @@ import { ValuesFromObject } from "../../type/mod.ts";
1015
const formats = {
1116
/** Reset or normal */
1217
RESET: '0',
13-
/** Bold or increased intensity */
14-
FONT_WEIGHT_BOLD: '1',
15-
/** Faint, decreased intensity, or dim */
16-
FONT_WEIGHT_DIM: '2',
17-
/** Italic */
18-
ITALIC: '3',
19-
/** Underline */
20-
UNDERLINE: '4',
2118
/** Slow blink */
2219
BLINK_SLOW: '5',
2320
/** Rapid blink */
2421
BLINK_RAPID: '6',
25-
/** [Reverse video](https://en.wikipedia.org/wiki/Reverse_video) or invert */
26-
SWAP_FOREGROUND_BACKGROUND_COLOR: '7',
2722
/** Conceal or hide */
2823
HIDE: '8',
29-
/** [Crosser-out](https://en.wikipedia.org/wiki/Strikethrough), or strike */
30-
STRIKETHROUGH: '9',
31-
/** Primary (default) font */
32-
FONT_DEFAULT: '10',
33-
/** Alternative font 1 */
34-
FONT_ALTERNATIVE_1: '11',
35-
/** Alternative font 2 */
36-
FONT_ALTERNATIVE_2: '12',
37-
/** Alternative font 3 */
38-
FONT_ALTERNATIVE_3: '13',
39-
/** Alternative font 4 */
40-
FONT_ALTERNATIVE_4: '14',
41-
/** Alternative font 5 */
42-
FONT_ALTERNATIVE_5: '15',
43-
/** Alternative font 6 */
44-
FONT_ALTERNATIVE_6: '16',
45-
/** Alternative font 7 */
46-
FONT_ALTERNATIVE_7: '17',
47-
/** Alternative font 8 */
48-
FONT_ALTERNATIVE_8: '18',
49-
/** Alternative font 9 */
50-
FONT_ALTERNATIVE_9: '19',
51-
/** [Fraktur](https://en.wikipedia.org/wiki/Fraktur) (Gothic) */
52-
FONT_FRACTURE: '20',
53-
/** Doubly underlined; or: not bold */
54-
DOUBLE_UNDERLINE: '21',
55-
/** Normal intensity */
56-
FONT_WEIGHT_NORMAL: '22',
57-
/** Neither italic, nor blackletter */
58-
ITALIC_RESET: '23',
59-
/** Not underlined */
60-
UNDERLINE_RESET: '24',
61-
/** Not blinking */
62-
BLINK_RESET: '25',
63-
/** Proportional spacing */
64-
PROPORTIONAL_SPACING: '26',
65-
/** Not reversed */
66-
REVERSED_RESET: '27',
6724
/** Reveal */
6825
HIDE_RESET: '28',
69-
/** Not crossed out */
70-
STRIKETHROUGH_RESET: '29',
71-
// FOREGROUND_COLOR: 30 - 37
72-
/** Set foreground [color](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) */
73-
FOREGROUND_COLOR: '38',
74-
/** Default foreground color */
75-
FOREGROUND_COLOR_DEFAULT: '39',
76-
// BACKGROUND_COLOR: 40 - 47
77-
/** Set background [color](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) */
78-
BACKGROUND_COLOR: '48',
79-
/** Default background color */
80-
BACKGROUND_COLOR_DEFAULT: '49',
81-
/** Disable proportional spacing */
82-
PROPORTIONAL_SPACING_RESET: '50',
83-
/** Framed */
84-
FRAME: '51',
85-
/** Encircled */
86-
ENCIRCLE: '52',
87-
/** Overlined */
88-
OVERLINE: '53',
89-
/** Neither framed nor encircled */
90-
FRAME_ENCIRCLE_RESET: '54',
91-
/** Not overlined */
92-
OVERLINE_RESET: '55',
93-
// 56 - 57
94-
/** Set underline [color](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) */
95-
UNDERLINE_COLOR: '58',
96-
/** Default underline color */
97-
UNDERLINE_COLOR_DEFAULT: '59',
98-
/** Ideogram underline or right side line */
99-
IDEOGRAM_RIGHT_SIDE_LINE: '60',
100-
/** Ideogram double underline, or double line on the right side */
101-
IDEOGRAM_DOUBLE_RIGHT_SIDE_LINE: '61',
102-
/** Ideogram overline or left side line */
103-
IDEOGRAM_LEFT_SIDE_LINE: '62',
104-
/** Ideogram double overline, or double line on the left side */
105-
IDEOGRAM_DOUBLE_LEFT_SIDE_LINE: '63',
106-
/** Ideogram stress marking */
107-
IDEOGRAM_STRESS_ERROR_MARK: '64',
108-
/** No ideogram attributes */
109-
IDEOGRAM_REST: '65',
110-
// 66 - 72
111-
/** Superscript */
112-
SUPERSCRIPT: '73',
113-
/** Subscript */
114-
SUBSCRIPT: '74',
115-
/** Neither superscript nor subscript */
116-
SUPERSCRIPT_SUBSCRIPT_RESET: '75'
117-
// BRIGHT_FOREGROUND_COLOR: 90 - 97
118-
// 98 - 99
119-
// BRIGHT_BACKGROUND_COLOR: 100 - 107
26+
...colors,
27+
...fonts,
28+
...ideograms,
29+
...scripts,
30+
...textDecorations
12031
} as const;
12132

12233
export default formats;

src/ansi/formats/ideograms.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { ValuesFromObject } from "../../type/mod.ts";
2+
3+
/**
4+
* This object contains all ideogram format codes.
5+
*
6+
* Use the control sequence `CSI <formats.<format>> m`, named Select Graphic Rendition (SGR), to set ideogram format
7+
* attributes.
8+
*
9+
* [Wikipedia](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters)
10+
*/
11+
const ideograms = {
12+
/** Ideogram underline or right side line */
13+
IDEOGRAM_RIGHT_SIDE_LINE: '60',
14+
/** Ideogram double underline, or double line on the right side */
15+
IDEOGRAM_DOUBLE_RIGHT_SIDE_LINE: '61',
16+
/** Ideogram overline or left side line */
17+
IDEOGRAM_LEFT_SIDE_LINE: '62',
18+
/** Ideogram double overline, or double line on the left side */
19+
IDEOGRAM_DOUBLE_LEFT_SIDE_LINE: '63',
20+
/** Ideogram stress marking */
21+
IDEOGRAM_STRESS_ERROR_MARK: '64',
22+
/** No ideogram attributes */
23+
IDEOGRAM_RESET: '65',
24+
} as const;
25+
26+
export default ideograms;
27+
28+
/**
29+
* This type gets generated from the values of {@linkcode ideograms}.
30+
*/
31+
export type Ideogram = ValuesFromObject<typeof ideograms>;

src/ansi/formats/scripts.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { ValuesFromObject } from "../../type/mod.ts";
2+
3+
/**
4+
* This object contains all script format codes.
5+
*
6+
* Use the control sequence `CSI <formats.<format>> m`, named Select Graphic Rendition (SGR), to set script format
7+
* attributes.
8+
*
9+
* [Wikipedia](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters)
10+
*/
11+
const scripts = {
12+
/** Superscript */
13+
SUPERSCRIPT: '73',
14+
/** Subscript */
15+
SUBSCRIPT: '74',
16+
/** Neither superscript nor subscript */
17+
SUPERSCRIPT_SUBSCRIPT_RESET: '75'
18+
} as const;
19+
20+
export default scripts;
21+
22+
/**
23+
* This type gets generated from the values of {@linkcode scripts}.
24+
*/
25+
export type Script = ValuesFromObject<typeof scripts>;
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { ValuesFromObject } from "../../type/mod.ts";
2+
3+
/**
4+
* This object contains all text decoration format codes.
5+
*
6+
* Use the control sequence `CSI <formats.<format>> m`, named Select Graphic Rendition (SGR), to set text decoration
7+
* format attributes.
8+
*
9+
* [Wikipedia](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters)
10+
*/
11+
const textDecorations = {
12+
/** Bold or increased intensity */
13+
FONT_WEIGHT_BOLD: '1',
14+
/** Faint, decreased intensity, or dim */
15+
FONT_WEIGHT_DIM: '2',
16+
/** Italic */
17+
ITALIC: '3',
18+
/** Underline */
19+
UNDERLINE: '4',
20+
/** [Crosser-out](https://en.wikipedia.org/wiki/Strikethrough), or strike */
21+
STRIKETHROUGH: '9',
22+
/** Doubly underlined; or: not bold */
23+
DOUBLE_UNDERLINE: '21',
24+
/** Normal intensity */
25+
FONT_WEIGHT_NORMAL: '22',
26+
/** Neither italic, nor blackletter */
27+
ITALIC_RESET: '23',
28+
/** Not underlined */
29+
UNDERLINE_RESET: '24',
30+
/** Not blinking */
31+
BLINK_RESET: '25',
32+
/** Proportional spacing */
33+
PROPORTIONAL_SPACING: '26',
34+
/** Not reversed */
35+
REVERSED_RESET: '27',
36+
/** Not crossed out */
37+
STRIKETHROUGH_RESET: '29',
38+
/** Disable proportional spacing */
39+
PROPORTIONAL_SPACING_RESET: '50',
40+
/** Framed */
41+
FRAME: '51',
42+
/** Encircled */
43+
ENCIRCLE: '52',
44+
/** Overlined */
45+
OVERLINE: '53',
46+
/** Neither framed nor encircled */
47+
FRAME_ENCIRCLE_RESET: '54',
48+
/** Not overlined */
49+
OVERLINE_RESET: '55',
50+
} as const;
51+
52+
export default textDecorations;
53+
54+
/**
55+
* This type gets generated from the values of {@linkcode textDecorations}.
56+
*/
57+
export type TextDecoration = ValuesFromObject<typeof textDecorations>;

0 commit comments

Comments
 (0)