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

..03-May-2022-

cmd/ansi-mgutz/H06-Feb-2017-

.gitignoreH A D06-Feb-20177

LICENSEH A D06-Feb-20171.1 KiB

README.mdH A D06-Feb-20172.3 KiB

ansi.goH A D06-Feb-20175.3 KiB

ansi_test.goH A D06-Feb-2017699

doc.goH A D06-Feb-20171.5 KiB

print.goH A D06-Feb-20171.2 KiB

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+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 project directory in terminal.
48
49```sh
50go test
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
71Foreground Attributes
72
73* B = Blink
74* b = bold
75* h = high intensity (bright)
76* i = inverse
77* s = strikethrough
78* u = underline
79
80Background Attributes
81
82* h = high intensity (bright)
83
84## Constants
85
86* ansi.Reset
87* ansi.DefaultBG
88* ansi.DefaultFG
89* ansi.Black
90* ansi.Red
91* ansi.Green
92* ansi.Yellow
93* ansi.Blue
94* ansi.Magenta
95* ansi.Cyan
96* ansi.White
97* ansi.LightBlack
98* ansi.LightRed
99* ansi.LightGreen
100* ansi.LightYellow
101* ansi.LightBlue
102* ansi.LightMagenta
103* ansi.LightCyan
104* ansi.LightWhite
105
106## References
107
108Wikipedia ANSI escape codes [Colors](http://en.wikipedia.org/wiki/ANSI_escape_code#Colors)
109
110General [tips and formatting](http://misc.flogisoft.com/bash/tip_colors_and_formatting)
111
112What about support on Windows? Use [colorable by mattn](https://github.com/mattn/go-colorable).
113Ansi and colorable are used by [logxi](https://github.com/mgutz/logxi) to support logging in
114color on Windows.
115
116## MIT License
117
118Copyright (c) 2013 Mario Gutierrez mario@mgutz.com
119
120See the file LICENSE for copying permission.
121
122