1
- <p style = " width : 100 % ; text-align : center ; font-size : 40 px ; margin-bottom : 30 px ; letter-spacing : 5 px ; font-family :consolas; " >
2
- < span style = " color : #ad7fa8 ; " >\x1b</ span >< span style = " color : #729fcf ; " > [ </ span >< span style = " color : #8ae234 ; " >1;43</ span >< span style = " color : #ef2929 ; " >m</ span >< span style = " font-weight : bold ; background-color : #fce94f ; color : #555753 ; " >ANSI</ span >< span style = " color : #ad7fa8 ; " >\x1b</ span >< span style = " color : #729fcf ; " > [ </ span >< span style = " color : #8ae234 ; " >0</ span >< span style = " color : #ef2929 ; " >m</ span >
3
- </p >
1
+ <div align = " center " >
2
+ < img src = " res/title.svg " alt = " Click to see the source " >
3
+ </div >
4
4
5
- <p style = " width : 100 % ; text-align : center ; margin-bottom : 30 px ; font-style : italic ; " >
6
- A simple, lightweight Golang package for working with ANSI escape codes.
5
+ <p align = " center " >
6
+ < i > A simple, lightweight Golang package for working with ANSI escape codes.</ i >
7
7
</p >
8
+ <br >
8
9
9
10
If you've ever worked on a CLI application before, you probably know the
10
11
struggle of working with ANSI escape codes. Often, you just want to quickly
@@ -14,20 +15,18 @@ that does more than you need.
14
15
15
16
The ` ansi ` package is extremely lightweight :feather : and has no external
16
17
dependencies :package : It allows you to quickly apply styles to strings using
17
- ** human-readable** style blocks. Because the styles are defined ** inline** , there is no
18
- need to call a function for each style, making it easy to apply/reset multiple
19
- styles to a single string.
18
+ ** human-readable** style blocks. Because the styles are defined ** inline** ,
19
+ there is no need to call a function for each style, making it easy to
20
+ apply/reset multiple styles to a single string.
20
21
21
- With ` ansi ` , the mess at the top of this page becomes: <span style =" font-size :20px ;letter-spacing :2px ;font-family :consolas;" >
22
- <span style =" color :#ad7fa8 ;" >[ </span ><span style =" color :#8ae234 ;" >bold: bg-yellow </span ><span style =" color :#ad7fa8 ;" >] </span ><span style =" font-weight :bold ;background-color :#fce94f ;color :#555753 ;" >ANSI</span ><span style =" color :#ad7fa8 ;" >[ </span ><span style =" color :#ef2929 ;" >/</span ><span style =" color :#ad7fa8 ;" >] </span >
23
- </span >
22
+ With ` ansi ` , the mess at the top of this page becomes: <img src =" res/ansi.svg " alt =" Click to see the source " >
24
23
25
24
## Usage
26
25
27
26
Strings are formatted using "style blocks". A style block is delimited by square
28
- brackets (` [] ` ) and contains a list of styles separated by colons. For
29
- example, the style block ` [red:bold] ` applies the red and bold styles to any
30
- text following the block.
27
+ brackets (` [] ` ) and contains a list of styles separated by colons. For example,
28
+ the style block ` [red:bold] ` applies the red and bold styles to any text
29
+ following the block.
31
30
32
31
Styles can be reset by using the corresponding reset code or by using the global
33
32
reset (` [/] ` ) to reset all styles.
@@ -54,7 +53,8 @@ ansi.Println("This is \\[red:bold]a normally formatted string because the style
54
53
ansi.Println (` This is \[red:bold]a normally formatted string because the style block is escaped\[/]` )
55
54
```
56
55
57
- For more info, check out the [ style reference] ( #style-reference ) below or take a look at our [ examples] ( ./examples/main.go ) .
56
+ For more info, check out the [ style reference] ( #style-reference ) below or take a
57
+ look at our [ examples] ( ./examples/main.go ) .
58
58
59
59
## Style Reference
60
60
@@ -66,20 +66,21 @@ For more info, check out the [style reference](#style-reference) below or take a
66
66
67
67
### Formatting
68
68
69
- | Code | ANSI Code | Example |
70
- | -------------- | --------: | ------------------------------------------------------------------------------------------------------------- |
71
- | ` bold ` | ` 1 ` | <span style =" font-weight :bold ;" >Sets the font weight to bold</span > |
72
- | ` faint ` , ` dim ` | ` 2 ` | <span style =" color :#d3d7cf ;" >Sets the text brightness to its faint/dim variant</span > \* |
73
- | ` italic ` | ` 3 ` | <span style =" font-style :italic ;" >Sets the font style to italic</span > |
74
- | ` underline ` | ` 4 ` | <span style =" text-decoration :underline ;" >Sets the text decoration to underline</span > |
75
- | ` blink ` | ` 5 ` | <span style =" text-decoration :blink ;" >Sets the text to blink in and out</span > |
76
- | ` invert ` | ` 7 ` | <span style =" backdrop-filter :invert (1 );filter :invert (1 );" >Inverts the foreground and background colors</span > |
77
- | ` hidden ` | ` 8 ` | <span style =" opacity :0 ;" >Sets the text to be hidden</span > |
78
- | ` strike ` | ` 9 ` | <span style =" text-decoration :line-through ;" >Sets the text decoration to line-through</span > |
79
-
80
- > \* ` faint ` and ` dim ` do not work when using 8-bit (256) or 24-bit (RGB) color modes.
81
-
82
- | Code | ANSI Code | Example |
69
+ | Code | ANSI Code | Description |
70
+ | -------------- | --------: | ---------------------------------------------------- |
71
+ | ` bold ` | ` 1 ` | Sets the font weight to bold |
72
+ | ` faint ` , ` dim ` | ` 2 ` | Sets the text brightness to its faint/dim variant \* |
73
+ | ` italic ` | ` 3 ` | Sets the font style to italic |
74
+ | ` underline ` | ` 4 ` | Sets the text decoration to underline |
75
+ | ` blink ` | ` 5 ` | Sets the text to blink in and out |
76
+ | ` invert ` | ` 7 ` | Inverts the foreground and background colors</span > |
77
+ | ` hidden ` | ` 8 ` | Sets the text to be hidden |
78
+ | ` strike ` | ` 9 ` | Sets the text decoration to line-through |
79
+
80
+ > \* ` faint ` and ` dim ` do not work when using 8-bit (256) or 24-bit (RGB) color
81
+ > modes.
82
+
83
+ | Code | ANSI Code | Description |
83
84
| ---------------- | --------: | --------------------------------------- |
84
85
| ` /bold ` | ` 22 ` | Resets the font weight \*\* |
85
86
| ` /faint ` , ` /dim ` | ` 22 ` | Resets the text brightness \*\* |
@@ -95,35 +96,35 @@ For more info, check out the [style reference](#style-reference) below or take a
95
96
96
97
### Foreground Colors
97
98
98
- | Code | ANSI Code | Reset Code |
99
- | --------- | -----------: | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
100
- | ` black ` | ` 30 ` | < span style = " color : #555753 ; " > Sets the text foreground to black</ span > |
101
- | ` red ` | ` 31 ` | < span style = " color : #ef2929 ; " > Sets the text foreground to red</ span > |
102
- | ` green ` | ` 32 ` | < span style = " color : #8ae234 ; " > Sets the text foreground to green</ span > |
103
- | ` yellow ` | ` 33 ` | < span style = " color : #fce94f ; " > Sets the text foreground to yellow</ span > |
104
- | ` blue ` | ` 34 ` | < span style = " color : #729fcf ; " > Sets the text foreground to blue</ span > |
105
- | ` magenta ` | ` 35 ` | < span style = " color : #ad7fa8 ; " > Sets the text foreground to magenta</ span > |
106
- | ` cyan ` | ` 36 ` | < span style = " color : #34e2e2 ; " > Sets the text foreground to cyan</ span > |
107
- | ` white ` | ` 37 ` | < span style = " color : #eeeeec ; " > Sets the text foreground to white</ span > |
108
- | ` R,G,B ` | ` 38;2;R;G;B ` | Sets the text foreground to the given [ 24-bit (< span style = " color : #ef2929 ; " >R</ span >< span style = " color : #8ae234 ; " >G</ span >< span style = " color : #729fcf ; " >B</ span > ) color] [ 24-bit ] |
109
- | ` N ` | ` 38;5;N ` | Sets the text foreground to the given [ 8-bit (256) color] [ 8-bit ] |
110
- | ` /fg ` | ` 39 ` | < span style = " color : auto ; " > Resets the text foreground to the default color</ span > |
99
+ | Code | ANSI Code | Description |
100
+ | --------- | -----------: | ------------------------------------------------------------------ |
101
+ | ` black ` | ` 30 ` | Sets the text foreground to black |
102
+ | ` red ` | ` 31 ` | Sets the text foreground to red |
103
+ | ` green ` | ` 32 ` | Sets the text foreground to green |
104
+ | ` yellow ` | ` 33 ` | Sets the text foreground to yellow |
105
+ | ` blue ` | ` 34 ` | Sets the text foreground to blue |
106
+ | ` magenta ` | ` 35 ` | Sets the text foreground to magenta |
107
+ | ` cyan ` | ` 36 ` | Sets the text foreground to cyan |
108
+ | ` white ` | ` 37 ` | Sets the text foreground to white |
109
+ | ` R,G,B ` | ` 38;2;R;G;B ` | Sets the text foreground to the given [ 24-bit (RGB ) color] [ 24-bit ] |
110
+ | ` N ` | ` 38;5;N ` | Sets the text foreground to the given [ 8-bit (256) color] [ 8-bit ] |
111
+ | ` /fg ` | ` 39 ` | Resets the text foreground to the default color |
111
112
112
113
### Background Colors
113
114
114
- | Code | ANSI Code | Reset Code |
115
- | ------------ | -----------: | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
116
- | ` bg-black ` | ` 40 ` | < span style = " background-color : #555753 ; " > Sets the text background to black</ span > |
117
- | ` bg-red ` | ` 41 ` | < span style = " background-color : #ef2929 ; " > Sets the text background to red</ span > |
118
- | ` bg-green ` | ` 42 ` | < span style = " background-color : #8ae234 ; color : #555753 ; " > Sets the text background to green</ span > |
119
- | ` bg-yellow ` | ` 43 ` | < span style = " background-color : #fce94f ; color : #555753 ; " > Sets the text background to yellow</ span > |
120
- | ` bg-blue ` | ` 44 ` | < span style = " background-color : #729fcf ; " > Sets the text background to blue</ span > |
121
- | ` bg-magenta ` | ` 45 ` | < span style = " background-color : #ad7fa8 ; " > Sets the text background to magenta</ span > |
122
- | ` bg-cyan ` | ` 46 ` | < span style = " background-color : #34e2e2 ; color : #555753 ; " > Sets the text background to cyan</ span > |
123
- | ` bg-white ` | ` 47 ` | < span style = " background-color : #eeeeec ; color : #555753 ; " > Sets the text background to white</ span > |
124
- | ` bg-R,G,B ` | ` 48;2;R;G;B ` | Sets the text background to the given [ 24-bit (< span style = " color : #ef2929 ; " >R</ span >< span style = " color : #8ae234 ; " >G</ span >< span style = " color : #729fcf ; " >B</ span > ) color] [ 24-bit ] |
125
- | ` bg-N ` | ` 48;5;N ` | Sets the text background to the given [ 8-bit (256) color] [ 8-bit ] |
126
- | ` /bg ` | ` 49 ` | < span style = " background-color : auto ; " > Resets the text background to the default color</ span > |
115
+ | Code | ANSI Code | Description |
116
+ | ------------ | -----------: | ------------------------------------------------------------------ |
117
+ | ` bg-black ` | ` 40 ` | Sets the text background to black |
118
+ | ` bg-red ` | ` 41 ` | Sets the text background to red |
119
+ | ` bg-green ` | ` 42 ` | Sets the text background to green |
120
+ | ` bg-yellow ` | ` 43 ` | Sets the text background to yellow |
121
+ | ` bg-blue ` | ` 44 ` | Sets the text background to blue |
122
+ | ` bg-magenta ` | ` 45 ` | Sets the text background to magenta |
123
+ | ` bg-cyan ` | ` 46 ` | Sets the text background to cyan |
124
+ | ` bg-white ` | ` 47 ` | Sets the text background to white |
125
+ | ` bg-R,G,B ` | ` 48;2;R;G;B ` | Sets the text background to the given [ 24-bit (RGB ) color] [ 24-bit ] |
126
+ | ` bg-N ` | ` 48;5;N ` | Sets the text background to the given [ 8-bit (256) color] [ 8-bit ] |
127
+ | ` /bg ` | ` 49 ` | Resets the text background to the default color |
127
128
128
129
[ 8-bit ] : https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
129
130
[ 24-bit ] : https://en.wikipedia.org/wiki/ANSI_escape_code#24-bit
0 commit comments