• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..20-Jul-2016-

LICENSEH A D20-Jul-20161.1 KiB105

README.mdH A D20-Jul-20162.4 KiB12087

ansi.goH A D20-Jul-20164.4 KiB247182

doc.goH A D20-Jul-20161.5 KiB661

print.goH A D20-Jul-2016887 4337

README.md

1# ansi
2
3Package ansi is a small, fast library to create ANSI colored strings and codes.
4
5## Install
6
7This install the color viewer and the package itself
8
9```sh
10go get -u github.com/mgutz/ansi/cmd/ansi-mgutz
11```
12
13## Example
14
15```go
16import "github.com/mgutz/ansi"
17
18// colorize a string, SLOW
19msg := ansi.Color("foo", "red+b:white")
20
21// create a closure to avoid recalculating ANSI code compilation
22phosphorize := ansi.ColorFunc("green+h:black")
23msg = phosphorize("Bring back the 80s!")
24msg2 := phospohorize("Look, I'm a CRT!")
25
26// cache escape codes and build strings manually
27lime := ansi.ColorCode("green+h:black")
28reset := ansi.ColorCode("reset")
29
30fmt.Println(lime, "Bring back the 80s!", reset)
31```
32
33Other examples
34
35```go
36Color(s, "red")            // red
37Color(s, "red+b")          // red bold
38Color(s, "red+B")          // red blinking
39Color(s, "red+u")          // red underline
40Color(s, "red+bh")         // red bold bright
41Color(s, "red:white")      // red on white
42Color(s, "red+b:white+h")  // red bold on white bright
43Color(s, "red+B:white+h")  // red blink on white bright
44Color(s, "off")            // turn off ansi codes
45```
46
47To view color combinations, from terminal.
48
49```sh
50ansi-mgutz
51```
52
53## Style format
54
55```go
56"foregroundColor+attributes:backgroundColor+attributes"
57```
58
59Colors
60
61* black
62* red
63* green
64* yellow
65* blue
66* magenta
67* cyan
68* white
69* 0...255 (256 colors)
70
71Attributes
72
73*   b = bold foreground
74*   B = Blink foreground
75*   u = underline foreground
76*   i = inverse
77*   h = high intensity (bright) foreground, background
78
79    does not work with 256 colors
80
81## Constants
82
83* ansi.Reset
84* ansi.DefaultBG
85* ansi.DefaultFG
86* ansi.Black
87* ansi.Red
88* ansi.Green
89* ansi.Yellow
90* ansi.Blue
91* ansi.Magenta
92* ansi.Cyan
93* ansi.White
94* ansi.LightBlack
95* ansi.LightRed
96* ansi.LightGreen
97* ansi.LightYellow
98* ansi.LightBlue
99* ansi.LightMagenta
100* ansi.LightCyan
101* ansi.LightWhite
102
103
104## References
105
106Wikipedia ANSI escape codes [Colors](http://en.wikipedia.org/wiki/ANSI_escape_code#Colors)
107
108General [tips and formatting](http://misc.flogisoft.com/bash/tip_colors_and_formatting)
109
110What about support on Windows? Use [colorable by mattn](https://github.com/mattn/go-colorable).
111Ansi and colorable are used by [logxi](https://github.com/mgutz/logxi) to support logging in
112color on Windows.
113
114## MIT License
115
116Copyright (c) 2013 Mario Gutierrez mario@mgutz.com
117
118See the file LICENSE for copying permission.
119
120