1
0
mirror of https://github.com/fatih/color.git synced 2025-02-10 18:31:11 +02:00

color: export back color.Set(), fixes #13

This commit is contained in:
Fatih Arslan 2015-05-04 21:28:38 +03:00
parent 191595cfb2
commit b82cd6d93d
2 changed files with 9 additions and 6 deletions

View File

@ -75,7 +75,7 @@ func New(value ...Attribute) *Color {
// output with the given SGR parameters until color.Unset() is called.
func Set(p ...Attribute) *Color {
c := New(p...)
c.set()
c.Set()
return c
}
@ -89,8 +89,8 @@ func Unset() {
fmt.Fprintf(Output, "%s[%dm", escape, Reset)
}
// set sets the SGR sequence.
func (c *Color) set() *Color {
// Set sets the SGR sequence.
func (c *Color) Set() *Color {
if c.isNoColorSet() {
return c
}
@ -130,7 +130,7 @@ var Output io.Writer = ansicolor.NewAnsiColorWriter(os.Stdout)
// encountered. This is the standard fmt.Print() method wrapped with the given
// color.
func (c *Color) Print(a ...interface{}) (n int, err error) {
c.set()
c.Set()
defer c.unset()
return fmt.Fprint(Output, a...)
@ -140,7 +140,7 @@ func (c *Color) Print(a ...interface{}) (n int, err error) {
// It returns the number of bytes written and any write error encountered.
// This is the standard fmt.Printf() method wrapped with the given color.
func (c *Color) Printf(format string, a ...interface{}) (n int, err error) {
c.set()
c.Set()
defer c.unset()
return fmt.Fprintf(Output, format, a...)
@ -152,7 +152,7 @@ func (c *Color) Printf(format string, a ...interface{}) (n int, err error) {
// encountered. This is the standard fmt.Print() method wrapped with the given
// color.
func (c *Color) Println(a ...interface{}) (n int, err error) {
c.set()
c.Set()
defer c.unset()
return fmt.Fprintln(Output, a...)

View File

@ -77,6 +77,9 @@ func TestNoColor(t *testing.T) {
// global check
NoColor = true
defer func() {
NoColor = false
}()
for _, c := range testColors {
p := New(c.code)
p.Print(c.text)