mirror of
https://github.com/fatih/color.git
synced 2024-11-24 08:02:14 +02:00
Api and readme improvements
This commit is contained in:
parent
6ba802d6b6
commit
7dabc71cda
@ -16,9 +16,9 @@ go get github.com/fatih/color
|
||||
### Standard colors
|
||||
|
||||
```go
|
||||
// Print with default foreground colors
|
||||
color.Cyan.Print("Prints text in cyan.")
|
||||
color.Blue.Print("Prints text in blue.")
|
||||
// Print with default helper functions
|
||||
color.Cyan("Prints text in cyan.")
|
||||
color.Blue("Prints %s in blue.", "text") // a newline will be appended automatically
|
||||
|
||||
// Chain SGR paramaters
|
||||
color.Green.Add(color.Bold).Println("Green with bold")
|
||||
|
16
color.go
16
color.go
@ -103,11 +103,6 @@ func New(value ...Parameter) *Color {
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Color) Bold() *Color {
|
||||
c.Add(Bold)
|
||||
return c
|
||||
}
|
||||
|
||||
// Add is used to chain SGR parameters. Use as many as paramters to combine
|
||||
// and create custom color objects. Example: Add(color.FgRed, color.Underline)
|
||||
func (c *Color) Add(value ...Parameter) *Color {
|
||||
@ -121,12 +116,13 @@ func (c *Color) prepend(value Parameter) {
|
||||
c.params[0] = value
|
||||
}
|
||||
|
||||
// Output defines the standard output of the print functions. Any io.Writer
|
||||
// can be used.
|
||||
// Output defines the standard output of the print functions. By default
|
||||
// os.Stdout is used.
|
||||
var Output io.Writer = os.Stdout
|
||||
|
||||
// Printf formats according to a format specifier and writes to standard output.
|
||||
// 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()
|
||||
defer Unset()
|
||||
@ -137,7 +133,8 @@ func (c *Color) Printf(format string, a ...interface{}) (n int, err error) {
|
||||
// Print formats using the default formats for its operands and writes to
|
||||
// standard output. Spaces are added between operands when neither is a
|
||||
// string. It returns the number of bytes written and any write error
|
||||
// encountered.
|
||||
// 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()
|
||||
defer Unset()
|
||||
@ -148,7 +145,8 @@ func (c *Color) Print(a ...interface{}) (n int, err error) {
|
||||
// Println formats using the default formats for its operands and writes to
|
||||
// standard output. Spaces are always added between operands and a newline is
|
||||
// appended. It returns the number of bytes written and any write error
|
||||
// encountered.
|
||||
// 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()
|
||||
defer Unset()
|
||||
|
Loading…
Reference in New Issue
Block a user