@@ -94,6 +94,8 @@ func main() {
94
94
95
95
// use style tag
96
96
color.Print (" <suc>he</><comment>llo</>, <cyan>wel</><red>come</>\n " )
97
+ // Custom label attr: Supports the use of 16 color names, 256 color values, rgb color values and hex color values
98
+ color.Println (" <fg=11aa23>he</><bg=120,35,156>llo</>, <fg=167;bg=232>wel</><fg=red>come</>" )
97
99
98
100
// apply a style tag
99
101
color.Tag (" info" ).Println (" info style text" )
@@ -112,14 +114,34 @@ Run demo: `go run ./_examples/demo.go`
112
114
113
115
![ colored-out] ( _examples/images/color-demo.jpg )
114
116
115
- ## Custom Build Color
117
+ ## Basic/16 color
118
+
119
+ Supported on any Windows version. Provide generic API methods: ` Print ` , ` Printf ` , ` Println ` , ` Sprint ` , ` Sprintf `
116
120
117
121
``` go
122
+ color.Bold .Println (" bold message" )
123
+ color.Black .Println (" bold message" )
124
+ color.White .Println (" bold message" )
125
+ color.Gray .Println (" bold message" )
126
+ color.Red .Println (" yellow message" )
127
+ color.Blue .Println (" yellow message" )
128
+ color.Cyan .Println (" yellow message" )
129
+ color.Yellow .Println (" yellow message" )
130
+ color.Magenta .Println (" yellow message" )
131
+
118
132
// Only use foreground color
119
133
color.FgCyan .Printf (" Simple to use %s \n " , " color" )
120
134
// Only use background color
121
135
color.BgRed .Printf (" Simple to use %s \n " , " color" )
136
+ ```
122
137
138
+ Run demo: ` go run ./_examples/color_16.go `
139
+
140
+ ![ basic-color] ( _examples/images/basic-color.png )
141
+
142
+ ### Custom build color
143
+
144
+ ``` go
123
145
// Full custom: foreground, background, option
124
146
myStyle := color.New (color.FgWhite , color.BgBlack , color.OpBold )
125
147
myStyle.Println (" custom color style" )
@@ -141,49 +163,9 @@ fmt.Print("message")
141
163
color.Reset ()
142
164
```
143
165
144
- ## Basic Color
166
+ ### Additional styles
145
167
146
- Supported on any Windows version.
147
-
148
- - ` color.Bold `
149
- - ` color.Black `
150
- - ` color.White `
151
- - ` color.Gray `
152
- - ` color.Red `
153
- - ` color.Green `
154
- - ` color.Yellow `
155
- - ` color.Blue `
156
- - ` color.Magenta `
157
- - ` color.Cyan `
158
-
159
- ``` go
160
- color.Bold .Println (" bold message" )
161
- color.Yellow .Println (" yellow message" )
162
- ```
163
-
164
- Run demo: ` go run ./_examples/color_16.go `
165
-
166
- ![ basic-color] ( _examples/images/basic-color.png )
167
-
168
- ## Additional styles
169
-
170
- Supported on any Windows version.
171
-
172
- - ` color.Info `
173
- - ` color.Note `
174
- - ` color.Warn `
175
- - ` color.Light `
176
- - ` color.Error `
177
- - ` color.Danger `
178
- - ` color.Debug `
179
- - ` color.Notice `
180
- - ` color.Success `
181
- - ` color.Comment `
182
- - ` color.Primary `
183
- - ` color.Question `
184
- - ` color.Secondary `
185
-
186
- ### Basic Style
168
+ provide generic API methods: ` Print ` , ` Printf ` , ` Println ` , ` Sprint ` , ` Sprintf `
187
169
188
170
print message use defined style:
189
171
@@ -204,7 +186,7 @@ Run demo: `go run ./_examples/theme_basic.go`
204
186
205
187
![ theme-basic] ( _examples/images/theme-basic.png )
206
188
207
- ### Tips Style
189
+ ** Tips style **
208
190
209
191
``` go
210
192
color.Info .Tips (" Info tips message" )
@@ -223,7 +205,7 @@ Run demo: `go run ./_examples/theme_tips.go`
223
205
224
206
![ theme-tips] ( _examples/images/theme-tips.png )
225
207
226
- ### Prompt Style
208
+ ** Prompt Style**
227
209
228
210
``` go
229
211
color.Info .Prompt (" Info prompt message" )
@@ -242,7 +224,7 @@ Run demo: `go run ./_examples/theme_prompt.go`
242
224
243
225
![ theme-prompt] ( _examples/images/theme-prompt.png )
244
226
245
- ### Block Style
227
+ ** Block Style**
246
228
247
229
``` go
248
230
color.Info .Block (" Info block message" )
@@ -261,34 +243,6 @@ Run demo: `go run ./_examples/theme_block.go`
261
243
262
244
![ theme-block] ( _examples/images/theme-block.png )
263
245
264
- ## HTML-like tag usage
265
-
266
- ** Supported** on Windows ` cmd.exe ` ` PowerShell ` .
267
-
268
- ``` go
269
- // use style tag
270
- color.Print (" <suc>he</><comment>llo</>, <cyan>wel</><red>come</>" )
271
- color.Println (" <suc>hello</>" )
272
- color.Println (" <error>hello</>" )
273
- color.Println (" <warning>hello</>" )
274
-
275
- // custom color attributes
276
- color.Print (" <fg=yellow;bg=black;op=underscore;>hello, welcome</>\n " )
277
- ```
278
-
279
- - ` color.Tag `
280
-
281
- ``` go
282
- // set a style tag
283
- color.Tag (" info" ).Print (" info style text" )
284
- color.Tag (" info" ).Printf (" %s style text" , " info" )
285
- color.Tag (" info" ).Println (" info style text" )
286
- ```
287
-
288
- Run demo: ` go run ./_examples/color_tag.go `
289
-
290
- ![ color-tags] ( _examples/images/color-tags.png )
291
-
292
246
## 256-color usage
293
247
294
248
> 256 colors support Windows CMD, PowerShell environment after ` v1.2.4 `
@@ -307,7 +261,7 @@ c.Println("message")
307
261
c.Printf (" format %s " , " message" )
308
262
```
309
263
310
- ### Use a 256-color style
264
+ ### 256-color style
311
265
312
266
Can be used to set foreground and background colors at the same time.
313
267
@@ -333,7 +287,7 @@ Run demo: `go run ./_examples/color_256.go`
333
287
334
288
![ color-tags] ( _examples/images/color-256.png )
335
289
336
- ## Use RGB color
290
+ ## RGB/True color
337
291
338
292
> RGB colors support Windows ` CMD ` , ` PowerShell ` environment after ` v1.2.4 `
339
293
@@ -383,7 +337,7 @@ c.Println("message")
383
337
c.Printf (" format %s " , " message" )
384
338
```
385
339
386
- ### Use an RGB color style
340
+ ### RGB color style
387
341
388
342
Can be used to set the foreground and background colors at the same time.
389
343
@@ -415,6 +369,37 @@ s.Println("style with options")
415
369
s.Printf (" style with %s \n " , " options" )
416
370
```
417
371
372
+ ## HTML-like tag usage
373
+
374
+ ** Supported** on Windows ` cmd.exe ` ` PowerShell ` .
375
+
376
+ ``` go
377
+ // use style tag
378
+ color.Print (" <suc>he</><comment>llo</>, <cyan>wel</><red>come</>" )
379
+ color.Println (" <suc>hello</>" )
380
+ color.Println (" <error>hello</>" )
381
+ color.Println (" <warning>hello</>" )
382
+
383
+ // custom color attributes
384
+ color.Print (" <fg=yellow;bg=black;op=underscore;>hello, welcome</>\n " )
385
+
386
+ // Custom label attr: Supports the use of 16 color names, 256 color values, rgb color values and hex color values
387
+ color.Println (" <fg=11aa23>he</><bg=120,35,156>llo</>, <fg=167;bg=232>wel</><fg=red>come</>" )
388
+ ```
389
+
390
+ - ` color.Tag `
391
+
392
+ ``` go
393
+ // set a style tag
394
+ color.Tag (" info" ).Print (" info style text" )
395
+ color.Tag (" info" ).Printf (" %s style text" , " info" )
396
+ color.Tag (" info" ).Println (" info style text" )
397
+ ```
398
+
399
+ Run demo: ` go run ./_examples/color_tag.go `
400
+
401
+ ![ color-tags] ( _examples/images/color-tags.png )
402
+
418
403
## Color convert
419
404
420
405
Supports conversion between Rgb, 256, 16 colors, ` Rgb <=> 256 <=> 16 `
0 commit comments