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

..03-May-2022-

.gitignoreH A D28-Apr-2019316 3524

.travis.ymlH A D28-Apr-2019215 109

AUTHORS.mdH A D28-Apr-2019128 86

CHANGELOG.mdH A D28-Apr-20191.3 KiB5444

LICENSEH A D28-Apr-2019484 149

README.mdH A D28-Apr-20196.1 KiB280196

aurora.goH A D28-Apr-201915.8 KiB716428

aurora_test.goH A D28-Apr-20197.7 KiB233188

bench_test.goH A D28-Apr-201912.7 KiB488386

color.goH A D28-Apr-20198.9 KiB389207

color_test.goH A D28-Apr-20193.3 KiB156105

example_test.goH A D28-Apr-20191.7 KiB7530

sprintf.goH A D28-Apr-20191.7 KiB5919

sprintf_test.goH A D28-Apr-20191.3 KiB4616

value.goH A D28-Apr-201917.6 KiB736463

value_test.goH A D28-Apr-201912.5 KiB334274

wrap.goH A D28-Apr-201912.5 KiB549338

wrap_test.goH A D28-Apr-201912.2 KiB401314

README.md

1Aurora
2======
3
4[![GoDoc](https://godoc.org/github.com/logrusorgru/aurora?status.svg)](https://godoc.org/github.com/logrusorgru/aurora)
5[![WTFPL License](https://img.shields.io/badge/license-wtfpl-blue.svg)](http://www.wtfpl.net/about/)
6[![Build Status](https://travis-ci.org/logrusorgru/aurora.svg)](https://travis-ci.org/logrusorgru/aurora)
7[![Coverage Status](https://coveralls.io/repos/logrusorgru/aurora/badge.svg?branch=master)](https://coveralls.io/r/logrusorgru/aurora?branch=master)
8[![GoReportCard](https://goreportcard.com/badge/logrusorgru/aurora)](https://goreportcard.com/report/logrusorgru/aurora)
9[![Gitter](https://img.shields.io/badge/chat-on_gitter-46bc99.svg?logo=data:image%2Fsvg%2Bxml%3Bbase64%2CPHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMTQiIHdpZHRoPSIxNCI%2BPGcgZmlsbD0iI2ZmZiI%2BPHJlY3QgeD0iMCIgeT0iMyIgd2lkdGg9IjEiIGhlaWdodD0iNSIvPjxyZWN0IHg9IjIiIHk9IjQiIHdpZHRoPSIxIiBoZWlnaHQ9IjciLz48cmVjdCB4PSI0IiB5PSI0IiB3aWR0aD0iMSIgaGVpZ2h0PSI3Ii8%2BPHJlY3QgeD0iNiIgeT0iNCIgd2lkdGg9IjEiIGhlaWdodD0iNCIvPjwvZz48L3N2Zz4%3D&logoWidth=10)](https://gitter.im/logrusorgru/aurora)
10
11Ultimate ANSI colors for Golang. The package supports Printf/Sprintf etc.
12
13
14![aurora logo](https://github.com/logrusorgru/aurora/blob/master/gopher_aurora.png)
15
16# Installation
17
18Get
19```
20go get -u github.com/logrusorgru/aurora
21```
22Test
23```
24go test -cover github.com/logrusorgru/aurora
25```
26
27# Usage
28
29### Simple
30
31```go
32package main
33
34import (
35	"fmt"
36
37	. "github.com/logrusorgru/aurora"
38)
39
40func main() {
41	fmt.Println("Hello,", Magenta("Aurora"))
42	fmt.Println(Bold(Cyan("Cya!")))
43}
44
45```
46
47![simple png](https://github.com/logrusorgru/aurora/blob/master/simple.png)
48
49### Printf
50
51```go
52package main
53
54import (
55	"fmt"
56
57	. "github.com/logrusorgru/aurora"
58)
59
60func main() {
61	fmt.Printf("Got it %d times\n", Green(1240))
62	fmt.Printf("PI is %+1.2e\n", Cyan(3.14))
63}
64
65```
66
67![printf png](https://github.com/logrusorgru/aurora/blob/master/printf.png)
68
69### aurora.Sprintf
70
71```go
72package main
73
74import (
75	"fmt"
76
77	. "github.com/logrusorgru/aurora"
78)
79
80func main() {
81	fmt.Println(Sprintf(Magenta("Got it %d times"), Green(1240)))
82}
83
84```
85
86![sprintf png](https://github.com/logrusorgru/aurora/blob/master/sprintf.png)
87
88### Enable/Disable colors
89
90```go
91package main
92
93import (
94	"fmt"
95	"flag"
96
97	"github.com/logrusorgru/aurora"
98)
99
100// colorizer
101var au aurora.Aurora
102
103var colors = flag.Bool("colors", false, "enable or disable colors")
104
105func init() {
106	flag.Parse()
107	au = aurora.NewAurora(*colors)
108}
109
110func main() {
111	// use colorizer
112	fmt.Println(au.Green("Hello"))
113}
114
115```
116Without flags:
117![disable png](https://github.com/logrusorgru/aurora/blob/master/disable.png)
118
119With `-colors` flag:
120![enable png](https://github.com/logrusorgru/aurora/blob/master/enable.png)
121
122# Chains
123
124The following samples are equal
125
126```go
127x := BgMagenta(Bold(Red("x")))
128```
129
130```go
131x := Red("x").Bold().BgMagenta()
132```
133
134The second is more readable
135
136# Colorize
137
138There is `Colorize` function that allows to choose some colors and
139format from a side
140
141```go
142
143func getColors() Color {
144	// some stuff that returns appropriate colors and format
145}
146
147// [...]
148
149func main() {
150	fmt.Println(Colorize("Greeting", getColors()))
151}
152
153```
154Less complicated example
155
156```go
157x := Colorize("Greeting", GreenFg|GrayBg|BoldFm)
158```
159
160Unlike other color functions and methods (such as Red/BgBlue etc)
161a `Colorize` clears previous colors
162
163```go
164x := Red("x").Colorize(BgGreen) // will be with green background only
165```
166
167# Grayscale
168
169```go
170fmt.Println("  ",
171	Gray(1-1, " 00-23 ").BgGray(24-1),
172	Gray(4-1, " 03-19 ").BgGray(20-1),
173	Gray(8-1, " 07-15 ").BgGray(16-1),
174	Gray(12-1, " 11-11 ").BgGray(12-1),
175	Gray(16-1, " 15-07 ").BgGray(8-1),
176	Gray(20-1, " 19-03 ").BgGray(4-1),
177	Gray(24-1, " 23-00 ").BgGray(1-1),
178)
179```
180
181![grayscale png](https://github.com/logrusorgru/aurora/blob/master/aurora_grayscale.png)
182
183# 8-bit colors
184
185Methods `Index` and `BgIndex` implements 8-bit colors.
186
187| Index/BgIndex  |    Meaning      | Foreground | Background |
188| -------------- | --------------- | ---------- | ---------- |
189|      0-  7     | standard colors |   30- 37   |   40- 47   |
190|      8- 15     | bright colors   |   90- 97   |  100-107   |
191|     16-231     | 216 colors      |   38;5;n   |   48;5;n   |
192|    232-255     | 24 grayscale    |   38;5;n   |   48;5;n   |
193
194
195# Supported colors & formats
196
197- formats
198  + bold (1)
199  + faint (2)
200  + doubly-underline (21)
201  + fraktur (20)
202  + italic (3)
203  + underline (4)
204  + slow blink (5)
205  + rapid blink (6)
206  + reverse video (7)
207  + conceal (8)
208  + crossed out (9)
209  + framed (51)
210  + encircled (52)
211  + overlined (53)
212- background and foreground colors, including bright
213  + black
214  + red
215  + green
216  + yellow (brown)
217  +  blue
218  + magenta
219  + cyan
220  + white
221  + 24 grayscale colors
222  + 216 8-bit colors
223
224### All colors
225
226![linux png](https://github.com/logrusorgru/aurora/blob/master/aurora_colors_black.png)
227![white png](https://github.com/logrusorgru/aurora/blob/master/aurora_colors_white.png)
228
229### Standard and bright colors
230
231![linux black standard png](https://github.com/logrusorgru/aurora/blob/master/aurora_black_standard.png)
232![linux white standard png](https://github.com/logrusorgru/aurora/blob/master/aurora_white_standard.png)
233
234### Formats are likely supported
235
236![formats supported gif](https://github.com/logrusorgru/aurora/blob/master/aurora_formats.gif)
237
238### Formats are likely unsupported
239
240![formats rarely supported png](https://github.com/logrusorgru/aurora/blob/master/aurora_rarely_supported.png)
241
242# Limitations
243
244There is no way to represent `%T` and `%p` with colors using
245a standard approach
246
247```go
248package main
249
250import (
251	"fmt"
252
253	. "github.com/logrusorgru/aurora"
254)
255
256func main() {
257	r := Red("red")
258	var i int
259	fmt.Printf("%T %p\n", r, Green(&i))
260}
261```
262
263Output will be without colors
264
265```
266aurora.value %!p(aurora.value={0xc42000a310 768 0})
267```
268
269The obvious workaround is `Red(fmt.Sprintf("%T", some))`
270
271### Licensing
272
273Copyright © 2016-2019 The Aurora Authors. This work is free.
274It comes without any warranty, to the extent permitted by applicable
275law. You can redistribute it and/or modify it under the terms of the
276Do What The Fuck You Want To Public License, Version 2, as published
277by Sam Hocevar. See the LICENSE file for more details.
278
279
280