aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorFatih Arslan <ftharsln@gmail.com>2015-04-22 12:11:12 +0000
committerFatih Arslan <ftharsln@gmail.com>2015-04-22 12:11:12 +0000
commit191595cfb2ec9522680470397712a174a5684bb5 (patch)
tree8861c864098c45ffd8257a0b09839b58b875a12b /README.md
parent987617d12c58bfdcef4537354ddb5f1305c75765 (diff)
downloadcolour-191595cfb2ec9522680470397712a174a5684bb5.tar.gz
colour-191595cfb2ec9522680470397712a174a5684bb5.tar.bz2
color: add doc about NoColor
Diffstat (limited to 'README.md')
-rw-r--r--README.md31
1 files changed, 31 insertions, 0 deletions
diff --git a/README.md b/README.md
index 1d04bf1..d6fb06a 100644
--- a/README.md
+++ b/README.md
@@ -103,6 +103,37 @@ defer color.Unset() // Use it in your function
fmt.Println("All text will now be bold magenta.")
```
+### Disable color
+
+There might be a case where you want to disable color output (for example to
+pipe the standard output of your app to somewhere else). `Color` has support to
+disable colors both globally and for single color definition. For example
+suppose you have a CLI app and a `--no-color` bool flag. You can easily disable
+the color output with:
+
+```go
+
+var flagNoColor = flag.Bool("no-color", false, "Disable color output")
+
+if *flagNoColor {
+ color.NoColor = true // disables colorized output
+}
+```
+
+It also has support for single color definitions (local). You can
+disable/enable color output on the fly:
+
+```go
+c := color.New(color.FgCyan)
+c.Println("Prints cyan text")
+
+c.DisableColor()
+c.Println("This is printed without any color")
+
+c.EnableColor()
+c.Println("This prints again cyan...")
+```
+
## Todo
* Save/Return previous values