Skip to content

Commit 5d7e63e

Browse files
authored
Merge branch 'main' into no-color-empty-val
2 parents b06fcbf + 98e6a4a commit 5d7e63e

File tree

5 files changed

+77
-75
lines changed

5 files changed

+77
-75
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ There might be a case where you want to explicitly disable/enable color output.
131131
The `color` package also disables color output if the [`NO_COLOR`](https://no-color.org) environment
132132
variable is set to a non-empty string.
133133

134-
`Color` has support to disable/enable colors programatically both globally and
134+
`Color` has support to disable/enable colors programmatically both globally and
135135
for single color definitions. For example suppose you have a CLI app and a
136136
`-no-color` bool flag. You can easily disable the color output with:
137137

color.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var (
2222
NoColor = noColorIsSet() || os.Getenv("TERM") == "dumb" ||
2323
(!isatty.IsTerminal(os.Stdout.Fd()) && !isatty.IsCygwinTerminal(os.Stdout.Fd()))
2424

25-
// Output defines the standard output of the print functions. By default
25+
// Output defines the standard output of the print functions. By default,
2626
// os.Stdout is used.
2727
Output = colorable.NewColorableStdout()
2828

@@ -389,7 +389,7 @@ func (c *Color) DisableColor() {
389389
}
390390

391391
// EnableColor enables the color output. Use it in conjunction with
392-
// DisableColor(). Otherwise this method has no side effects.
392+
// DisableColor(). Otherwise, this method has no side effects.
393393
func (c *Color) EnableColor() {
394394
c.noColor = boolPtr(false)
395395
}

doc.go

Lines changed: 68 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -5,131 +5,130 @@ that suits you.
55
66
Use simple and default helper functions with predefined foreground colors:
77
8-
color.Cyan("Prints text in cyan.")
8+
color.Cyan("Prints text in cyan.")
99
10-
// a newline will be appended automatically
11-
color.Blue("Prints %s in blue.", "text")
10+
// a newline will be appended automatically
11+
color.Blue("Prints %s in blue.", "text")
1212
13-
// More default foreground colors..
14-
color.Red("We have red")
15-
color.Yellow("Yellow color too!")
16-
color.Magenta("And many others ..")
13+
// More default foreground colors..
14+
color.Red("We have red")
15+
color.Yellow("Yellow color too!")
16+
color.Magenta("And many others ..")
1717
18-
// Hi-intensity colors
19-
color.HiGreen("Bright green color.")
20-
color.HiBlack("Bright black means gray..")
21-
color.HiWhite("Shiny white color!")
18+
// Hi-intensity colors
19+
color.HiGreen("Bright green color.")
20+
color.HiBlack("Bright black means gray..")
21+
color.HiWhite("Shiny white color!")
2222
23-
However there are times where custom color mixes are required. Below are some
23+
However, there are times when custom color mixes are required. Below are some
2424
examples to create custom color objects and use the print functions of each
2525
separate color object.
2626
27-
// Create a new color object
28-
c := color.New(color.FgCyan).Add(color.Underline)
29-
c.Println("Prints cyan text with an underline.")
27+
// Create a new color object
28+
c := color.New(color.FgCyan).Add(color.Underline)
29+
c.Println("Prints cyan text with an underline.")
3030
31-
// Or just add them to New()
32-
d := color.New(color.FgCyan, color.Bold)
33-
d.Printf("This prints bold cyan %s\n", "too!.")
31+
// Or just add them to New()
32+
d := color.New(color.FgCyan, color.Bold)
33+
d.Printf("This prints bold cyan %s\n", "too!.")
3434
3535
36-
// Mix up foreground and background colors, create new mixes!
37-
red := color.New(color.FgRed)
36+
// Mix up foreground and background colors, create new mixes!
37+
red := color.New(color.FgRed)
3838
39-
boldRed := red.Add(color.Bold)
40-
boldRed.Println("This will print text in bold red.")
39+
boldRed := red.Add(color.Bold)
40+
boldRed.Println("This will print text in bold red.")
4141
42-
whiteBackground := red.Add(color.BgWhite)
43-
whiteBackground.Println("Red text with White background.")
42+
whiteBackground := red.Add(color.BgWhite)
43+
whiteBackground.Println("Red text with White background.")
4444
45-
// Use your own io.Writer output
46-
color.New(color.FgBlue).Fprintln(myWriter, "blue color!")
45+
// Use your own io.Writer output
46+
color.New(color.FgBlue).Fprintln(myWriter, "blue color!")
4747
48-
blue := color.New(color.FgBlue)
49-
blue.Fprint(myWriter, "This will print text in blue.")
48+
blue := color.New(color.FgBlue)
49+
blue.Fprint(myWriter, "This will print text in blue.")
5050
5151
You can create PrintXxx functions to simplify even more:
5252
53-
// Create a custom print function for convenient
54-
red := color.New(color.FgRed).PrintfFunc()
55-
red("warning")
56-
red("error: %s", err)
53+
// Create a custom print function for convenient
54+
red := color.New(color.FgRed).PrintfFunc()
55+
red("warning")
56+
red("error: %s", err)
5757
58-
// Mix up multiple attributes
59-
notice := color.New(color.Bold, color.FgGreen).PrintlnFunc()
60-
notice("don't forget this...")
58+
// Mix up multiple attributes
59+
notice := color.New(color.Bold, color.FgGreen).PrintlnFunc()
60+
notice("don't forget this...")
6161
6262
You can also FprintXxx functions to pass your own io.Writer:
6363
64-
blue := color.New(FgBlue).FprintfFunc()
65-
blue(myWriter, "important notice: %s", stars)
66-
67-
// Mix up with multiple attributes
68-
success := color.New(color.Bold, color.FgGreen).FprintlnFunc()
69-
success(myWriter, don't forget this...")
64+
blue := color.New(FgBlue).FprintfFunc()
65+
blue(myWriter, "important notice: %s", stars)
7066
67+
// Mix up with multiple attributes
68+
success := color.New(color.Bold, color.FgGreen).FprintlnFunc()
69+
success(myWriter, don't forget this...")
7170
7271
Or create SprintXxx functions to mix strings with other non-colorized strings:
7372
74-
yellow := New(FgYellow).SprintFunc()
75-
red := New(FgRed).SprintFunc()
73+
yellow := New(FgYellow).SprintFunc()
74+
red := New(FgRed).SprintFunc()
7675
77-
fmt.Printf("this is a %s and this is %s.\n", yellow("warning"), red("error"))
76+
fmt.Printf("this is a %s and this is %s.\n", yellow("warning"), red("error"))
7877
79-
info := New(FgWhite, BgGreen).SprintFunc()
80-
fmt.Printf("this %s rocks!\n", info("package"))
78+
info := New(FgWhite, BgGreen).SprintFunc()
79+
fmt.Printf("this %s rocks!\n", info("package"))
8180
8281
Windows support is enabled by default. All Print functions work as intended.
83-
However only for color.SprintXXX functions, user should use fmt.FprintXXX and
82+
However, only for color.SprintXXX functions, user should use fmt.FprintXXX and
8483
set the output to color.Output:
8584
86-
fmt.Fprintf(color.Output, "Windows support: %s", color.GreenString("PASS"))
85+
fmt.Fprintf(color.Output, "Windows support: %s", color.GreenString("PASS"))
8786
88-
info := New(FgWhite, BgGreen).SprintFunc()
89-
fmt.Fprintf(color.Output, "this %s rocks!\n", info("package"))
87+
info := New(FgWhite, BgGreen).SprintFunc()
88+
fmt.Fprintf(color.Output, "this %s rocks!\n", info("package"))
9089
9190
Using with existing code is possible. Just use the Set() method to set the
9291
standard output to the given parameters. That way a rewrite of an existing
9392
code is not required.
9493
95-
// Use handy standard colors.
96-
color.Set(color.FgYellow)
94+
// Use handy standard colors.
95+
color.Set(color.FgYellow)
9796
98-
fmt.Println("Existing text will be now in Yellow")
99-
fmt.Printf("This one %s\n", "too")
97+
fmt.Println("Existing text will be now in Yellow")
98+
fmt.Printf("This one %s\n", "too")
10099
101-
color.Unset() // don't forget to unset
100+
color.Unset() // don't forget to unset
102101
103-
// You can mix up parameters
104-
color.Set(color.FgMagenta, color.Bold)
105-
defer color.Unset() // use it in your function
102+
// You can mix up parameters
103+
color.Set(color.FgMagenta, color.Bold)
104+
defer color.Unset() // use it in your function
106105
107-
fmt.Println("All text will be now bold magenta.")
106+
fmt.Println("All text will be now bold magenta.")
108107
109108
There might be a case where you want to disable color output (for example to
110109
pipe the standard output of your app to somewhere else). `Color` has support to
111110
disable colors both globally and for single color definition. For example
112111
suppose you have a CLI app and a `--no-color` bool flag. You can easily disable
113112
the color output with:
114113
115-
var flagNoColor = flag.Bool("no-color", false, "Disable color output")
114+
var flagNoColor = flag.Bool("no-color", false, "Disable color output")
116115
117-
if *flagNoColor {
118-
color.NoColor = true // disables colorized output
119-
}
116+
if *flagNoColor {
117+
color.NoColor = true // disables colorized output
118+
}
120119
121120
You can also disable the color by setting the NO_COLOR environment variable to any value.
122121
123122
It also has support for single color definitions (local). You can
124123
disable/enable color output on the fly:
125124
126-
c := color.New(color.FgCyan)
127-
c.Println("Prints cyan text")
125+
c := color.New(color.FgCyan)
126+
c.Println("Prints cyan text")
128127
129-
c.DisableColor()
130-
c.Println("This is printed without any color")
128+
c.DisableColor()
129+
c.Println("This is printed without any color")
131130
132-
c.EnableColor()
133-
c.Println("This prints again cyan...")
131+
c.EnableColor()
132+
c.Println("This prints again cyan...")
134133
*/
135134
package color

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ go 1.13
44

55
require (
66
github.com/mattn/go-colorable v0.1.13
7-
github.com/mattn/go-isatty v0.0.16
7+
github.com/mattn/go-isatty v0.0.17
8+
golang.org/x/sys v0.3.0 // indirect
89
)

go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
22
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
3-
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
43
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
5-
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab h1:2QkjZIsXupsJbJIdSjjUOgWK3aEtzyuh2mPt3l/CkeU=
4+
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
5+
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
66
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
7+
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
8+
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

0 commit comments

Comments
 (0)