OSDN Git Service

new repo
[bytom/vapor.git] / vendor / github.com / tendermint / tmlibs / common / colors.go
1 package common
2
3 import (
4         "fmt"
5         "strings"
6 )
7
8 const (
9         ANSIReset      = "\x1b[0m"
10         ANSIBright     = "\x1b[1m"
11         ANSIDim        = "\x1b[2m"
12         ANSIUnderscore = "\x1b[4m"
13         ANSIBlink      = "\x1b[5m"
14         ANSIReverse    = "\x1b[7m"
15         ANSIHidden     = "\x1b[8m"
16
17         ANSIFgBlack   = "\x1b[30m"
18         ANSIFgRed     = "\x1b[31m"
19         ANSIFgGreen   = "\x1b[32m"
20         ANSIFgYellow  = "\x1b[33m"
21         ANSIFgBlue    = "\x1b[34m"
22         ANSIFgMagenta = "\x1b[35m"
23         ANSIFgCyan    = "\x1b[36m"
24         ANSIFgWhite   = "\x1b[37m"
25
26         ANSIBgBlack   = "\x1b[40m"
27         ANSIBgRed     = "\x1b[41m"
28         ANSIBgGreen   = "\x1b[42m"
29         ANSIBgYellow  = "\x1b[43m"
30         ANSIBgBlue    = "\x1b[44m"
31         ANSIBgMagenta = "\x1b[45m"
32         ANSIBgCyan    = "\x1b[46m"
33         ANSIBgWhite   = "\x1b[47m"
34 )
35
36 // color the string s with color 'color'
37 // unless s is already colored
38 func treat(s string, color string) string {
39         if len(s) > 2 && s[:2] == "\x1b[" {
40                 return s
41         } else {
42                 return color + s + ANSIReset
43         }
44 }
45
46 func treatAll(color string, args ...interface{}) string {
47         var parts []string
48         for _, arg := range args {
49                 parts = append(parts, treat(fmt.Sprintf("%v", arg), color))
50         }
51         return strings.Join(parts, "")
52 }
53
54 func Black(args ...interface{}) string {
55         return treatAll(ANSIFgBlack, args...)
56 }
57
58 func Red(args ...interface{}) string {
59         return treatAll(ANSIFgRed, args...)
60 }
61
62 func Green(args ...interface{}) string {
63         return treatAll(ANSIFgGreen, args...)
64 }
65
66 func Yellow(args ...interface{}) string {
67         return treatAll(ANSIFgYellow, args...)
68 }
69
70 func Blue(args ...interface{}) string {
71         return treatAll(ANSIFgBlue, args...)
72 }
73
74 func Magenta(args ...interface{}) string {
75         return treatAll(ANSIFgMagenta, args...)
76 }
77
78 func Cyan(args ...interface{}) string {
79         return treatAll(ANSIFgCyan, args...)
80 }
81
82 func White(args ...interface{}) string {
83         return treatAll(ANSIFgWhite, args...)
84 }