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
|
### Standard colors
|
||||||
|
|
||||||
```go
|
```go
|
||||||
// Print with default foreground colors
|
// Print with default helper functions
|
||||||
color.Cyan.Print("Prints text in cyan.")
|
color.Cyan("Prints text in cyan.")
|
||||||
color.Blue.Print("Prints text in blue.")
|
color.Blue("Prints %s in blue.", "text") // a newline will be appended automatically
|
||||||
|
|
||||||
// Chain SGR paramaters
|
// Chain SGR paramaters
|
||||||
color.Green.Add(color.Bold).Println("Green with bold")
|
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
|
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
|
// 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)
|
// and create custom color objects. Example: Add(color.FgRed, color.Underline)
|
||||||
func (c *Color) Add(value ...Parameter) *Color {
|
func (c *Color) Add(value ...Parameter) *Color {
|
||||||
@ -121,12 +116,13 @@ func (c *Color) prepend(value Parameter) {
|
|||||||
c.params[0] = value
|
c.params[0] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
// Output defines the standard output of the print functions. Any io.Writer
|
// Output defines the standard output of the print functions. By default
|
||||||
// can be used.
|
// os.Stdout is used.
|
||||||
var Output io.Writer = os.Stdout
|
var Output io.Writer = os.Stdout
|
||||||
|
|
||||||
// Printf formats according to a format specifier and writes to standard output.
|
// Printf formats according to a format specifier and writes to standard output.
|
||||||
// It returns the number of bytes written and any write error encountered.
|
// 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) {
|
func (c *Color) Printf(format string, a ...interface{}) (n int, err error) {
|
||||||
c.Set()
|
c.Set()
|
||||||
defer Unset()
|
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
|
// Print formats using the default formats for its operands and writes to
|
||||||
// standard output. Spaces are added between operands when neither is a
|
// standard output. Spaces are added between operands when neither is a
|
||||||
// string. It returns the number of bytes written and any write error
|
// 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) {
|
func (c *Color) Print(a ...interface{}) (n int, err error) {
|
||||||
c.Set()
|
c.Set()
|
||||||
defer Unset()
|
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
|
// Println formats using the default formats for its operands and writes to
|
||||||
// standard output. Spaces are always added between operands and a newline is
|
// standard output. Spaces are always added between operands and a newline is
|
||||||
// appended. It returns the number of bytes written and any write error
|
// 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) {
|
func (c *Color) Println(a ...interface{}) (n int, err error) {
|
||||||
c.Set()
|
c.Set()
|
||||||
defer Unset()
|
defer Unset()
|
||||||
|
Loading…
Reference in New Issue
Block a user