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

..01-Dec-2021-

ansi-d51e80ef957d/H06-Jul-2020-755546

.gitignoreH A D01-Dec-20217 21

LICENSEH A D01-Dec-20211.1 KiB105

README.mdH A D01-Dec-20212.3 KiB12491

ansi.goH A D01-Dec-20215.5 KiB292227

doc.goH A D01-Dec-20211.5 KiB671

print.goH A D01-Dec-20211.2 KiB5846

README.md

1# ansi
2
3Package ansi is a small, fast library to create ANSI colored strings and codes.
4
5## Install
6
7Get it
8
9```sh
10go get -u github.com/mgutz/ansi
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 FAST closure function to avoid computation of ANSI code
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+d")          // red dim
38Color(s, "red+b")          // red bold
39Color(s, "red+B")          // red blinking
40Color(s, "red+u")          // red underline
41Color(s, "red+bh")         // red bold bright
42Color(s, "red:white")      // red on white
43Color(s, "red+b:white+h")  // red bold on white bright
44Color(s, "red+B:white+h")  // red blink on white bright
45Color(s, "off")            // turn off ansi codes
46```
47
48To view color combinations, from project directory in terminal.
49
50```sh
51go test
52```
53
54## Style format
55
56```go
57"foregroundColor+attributes:backgroundColor+attributes"
58```
59
60Colors
61
62* black
63* red
64* green
65* yellow
66* blue
67* magenta
68* cyan
69* white
70* 0...255 (256 colors)
71
72Foreground Attributes
73
74* B = Blink
75* b = bold
76* h = high intensity (bright)
77* d = dim
78* i = inverse
79* s = strikethrough
80* u = underline
81
82Background Attributes
83
84* h = high intensity (bright)
85
86## Constants
87
88* ansi.Reset
89* ansi.DefaultBG
90* ansi.DefaultFG
91* ansi.Black
92* ansi.Red
93* ansi.Green
94* ansi.Yellow
95* ansi.Blue
96* ansi.Magenta
97* ansi.Cyan
98* ansi.White
99* ansi.LightBlack
100* ansi.LightRed
101* ansi.LightGreen
102* ansi.LightYellow
103* ansi.LightBlue
104* ansi.LightMagenta
105* ansi.LightCyan
106* ansi.LightWhite
107
108## References
109
110Wikipedia ANSI escape codes [Colors](http://en.wikipedia.org/wiki/ANSI_escape_code#Colors)
111
112General [tips and formatting](http://misc.flogisoft.com/bash/tip_colors_and_formatting)
113
114What about support on Windows? Use [colorable by mattn](https://github.com/mattn/go-colorable).
115Ansi and colorable are used by [logxi](https://github.com/mgutz/logxi) to support logging in
116color on Windows.
117
118## MIT License
119
120Copyright (c) 2013 Mario Gutierrez mario@mgutz.com
121
122See the file LICENSE for copying permission.
123
124