File tree 2 files changed +15
-2
lines changed
2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ const (
44
44
*************************************************************/
45
45
46
46
// RGBColor definition.
47
+ // Support RGB color on Windows CMD, PowerShell
47
48
//
48
49
// The first to third digits represent the color value.
49
50
// The last digit represents the foreground(0), background(1), >1 is unset value
@@ -54,8 +55,6 @@ const (
54
55
// // 3rd: Fg=0, Bg=1, >1: unset value
55
56
// RGBColor{30,144,255, 0}
56
57
// RGBColor{30,144,255, 1}
57
- //
58
- // NOTICE: now support RGB color on Windows CMD, PowerShell
59
58
type RGBColor [4 ]uint8
60
59
61
60
// create an empty RGBColor
@@ -251,6 +250,18 @@ func (c RGBColor) String() string {
251
250
return ""
252
251
}
253
252
253
+ // ToBg convert to background color
254
+ func (c RGBColor ) ToBg () RGBColor {
255
+ c [3 ] = AsBg
256
+ return c
257
+ }
258
+
259
+ // ToFg convert to foreground color
260
+ func (c RGBColor ) ToFg () RGBColor {
261
+ c [3 ] = AsFg
262
+ return c
263
+ }
264
+
254
265
// IsEmpty value
255
266
func (c RGBColor ) IsEmpty () bool {
256
267
return c [3 ] > AsBg
Original file line number Diff line number Diff line change @@ -26,12 +26,14 @@ func TestRGBColor(t *testing.T) {
26
26
is .False (c .IsEmpty ())
27
27
is .Equal ("48;2;204;204;204" , c .FullCode ())
28
28
is .Equal ("48;2;204;204;204" , c .String ())
29
+ is .Equal ("38;2;204;204;204" , c .ToFg ().FullCode ())
29
30
30
31
// fg
31
32
c = RGB (204 , 204 , 204 )
32
33
is .False (c .IsEmpty ())
33
34
is .Equal ("38;2;204;204;204" , c .FullCode ())
34
35
is .Equal ("38;2;204;204;204" , c .String ())
36
+ is .Equal ("48;2;204;204;204" , c .ToBg ().FullCode ())
35
37
36
38
// RGBColor.Sprint
37
39
str := c .Sprint ("msg" )
You can’t perform that action at this time.
0 commit comments