|
1 | 1 | package cfmt
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "fmt" |
4 | 5 | "io"
|
5 | 6 |
|
6 |
| - "github.com/fatih/color" |
| 7 | + "github.com/logrusorgru/aurora" |
| 8 | + "github.com/mattn/go-colorable" |
| 9 | +) |
| 10 | + |
| 11 | +var ( |
| 12 | + output = colorable.NewColorableStdout() |
7 | 13 | )
|
8 | 14 |
|
9 | 15 | // Fsuccessf writes green colored text in manner of fmt.Fprintf
|
10 | 16 | func Fsuccessf(w io.Writer, format string, a ...interface{}) (n int, err error) {
|
11 |
| - n, err = color.New(color.FgGreen).Fprintf(w, format, a...) |
| 17 | + n, err = fmt.Fprint(w, aurora.Sprintf(aurora.Green(format), a...)) |
12 | 18 | return
|
13 | 19 | }
|
14 | 20 |
|
15 | 21 | // Successf prints green colored text in manner of fmt.Printf
|
16 | 22 | func Successf(format string, a ...interface{}) (n int, err error) {
|
17 |
| - n, err = Fsuccessf(color.Output, format, a...) |
| 23 | + n, err = Fsuccessf(output, format, a...) |
18 | 24 | return
|
19 | 25 | }
|
20 | 26 |
|
21 | 27 | // Ssuccessf returns green colored string in manner of fmt.Sprintf
|
22 | 28 | func Ssuccessf(format string, a ...interface{}) string {
|
23 |
| - return color.New(color.FgGreen).Sprintf(format, a...) |
| 29 | + return aurora.Sprintf(aurora.Green(format), a...) |
24 | 30 | }
|
25 | 31 |
|
26 | 32 | // Finfof writes cyan colored text in manner of fmt.Fprintf
|
27 | 33 | func Finfof(w io.Writer, format string, a ...interface{}) (n int, err error) {
|
28 |
| - n, err = color.New(color.FgCyan).Fprintf(w, format, a...) |
| 34 | + n, err = fmt.Fprint(w, aurora.Sprintf(aurora.Cyan(format), a...)) |
29 | 35 | return
|
30 | 36 | }
|
31 | 37 |
|
32 | 38 | // Infof prints cyan colored text in manner of fmt.Printf
|
33 | 39 | func Infof(format string, a ...interface{}) (n int, err error) {
|
34 |
| - n, err = Finfof(color.Output, format, a...) |
| 40 | + n, err = Finfof(output, format, a...) |
35 | 41 | return
|
36 | 42 | }
|
37 | 43 |
|
38 | 44 | // Sinfof returns cyan colored string in manner of fmt.Sprintf
|
39 | 45 | func Sinfof(format string, a ...interface{}) string {
|
40 |
| - return color.New(color.FgCyan).Sprintf(format, a...) |
| 46 | + return aurora.Sprintf(aurora.Cyan(format), a...) |
41 | 47 | }
|
42 | 48 |
|
43 | 49 | // Fwarningf writes yellow colored text in manner of fmt.Fprintf
|
44 | 50 | func Fwarningf(w io.Writer, format string, a ...interface{}) (n int, err error) {
|
45 |
| - n, err = color.New(color.FgYellow).Fprintf(w, format, a...) |
| 51 | + n, err = fmt.Fprint(w, aurora.Sprintf(aurora.Brown(format), a...)) |
46 | 52 | return
|
47 | 53 | }
|
48 | 54 |
|
49 | 55 | // Warningf prints yellow colored text in manner of fmt.Printf
|
50 | 56 | func Warningf(format string, a ...interface{}) (n int, err error) {
|
51 |
| - n, err = Fwarningf(color.Output, format, a...) |
| 57 | + n, err = Fwarningf(output, format, a...) |
52 | 58 | return
|
53 | 59 | }
|
54 | 60 |
|
55 | 61 | // Swarningf returns yellow colored string in manner of fmt.Sprintf
|
56 | 62 | func Swarningf(format string, a ...interface{}) string {
|
57 |
| - return color.New(color.FgYellow).Sprintf(format, a...) |
| 63 | + return aurora.Sprintf(aurora.Brown(format), a...) |
58 | 64 | }
|
59 | 65 |
|
60 | 66 | // Ferrorf writes red colored text in manner of fmt.Fprintf
|
61 | 67 | func Ferrorf(w io.Writer, format string, a ...interface{}) (n int, err error) {
|
62 |
| - n, err = color.New(color.FgRed).Fprintf(w, format, a...) |
| 68 | + n, err = fmt.Fprint(w, aurora.Sprintf(aurora.Red(format), a...)) |
63 | 69 | return
|
64 | 70 | }
|
65 | 71 |
|
66 | 72 | // Errorf prints red colored text in manner of fmt.Printf
|
67 | 73 | func Errorf(format string, a ...interface{}) (n int, err error) {
|
68 |
| - n, err = Ferrorf(color.Output, format, a...) |
| 74 | + n, err = Ferrorf(output, format, a...) |
69 | 75 | return
|
70 | 76 | }
|
71 | 77 |
|
72 | 78 | // Serrorf returns red colored string in manner of fmt.Sprintf
|
73 | 79 | func Serrorf(format string, a ...interface{}) string {
|
74 |
| - return color.New(color.FgRed).Sprintf(format, a...) |
| 80 | + return aurora.Sprintf(aurora.Red(format), a...) |
75 | 81 | }
|
76 | 82 |
|
77 | 83 | // Fsuccess prints green colored text in manner of fmt.Fprint
|
78 | 84 | func Fsuccess(w io.Writer, a ...interface{}) (n int, err error) {
|
79 |
| - n, err = color.New(color.FgGreen).Fprint(w, a...) |
| 85 | + n, err = fmt.Fprint(w, aurora.Green(fmt.Sprint(a...))) |
80 | 86 | return
|
81 | 87 | }
|
82 | 88 |
|
83 | 89 | // Success prints green colored text in manner of fmt.Print
|
84 | 90 | func Success(a ...interface{}) (n int, err error) {
|
85 |
| - n, err = Fsuccess(color.Output, a...) |
| 91 | + n, err = Fsuccess(output, a...) |
86 | 92 | return
|
87 | 93 | }
|
88 | 94 |
|
89 | 95 | // Ssuccess returns green colored string in manner of fmt.Sprint
|
90 | 96 | func Ssuccess(a ...interface{}) string {
|
91 |
| - return color.New(color.FgGreen).Sprint(a...) |
| 97 | + return fmt.Sprint(aurora.Green(fmt.Sprint(a...))) |
92 | 98 | }
|
93 | 99 |
|
94 | 100 | // Finfo prints cyan colored text in manner of fmt.Fprint
|
95 | 101 | func Finfo(w io.Writer, a ...interface{}) (n int, err error) {
|
96 |
| - n, err = color.New(color.FgCyan).Fprint(w, a...) |
| 102 | + n, err = fmt.Fprint(w, aurora.Cyan(fmt.Sprint(a...))) |
97 | 103 | return
|
98 | 104 | }
|
99 | 105 |
|
100 | 106 | // Info prints cyan colored text in manner of fmt.Print
|
101 | 107 | func Info(a ...interface{}) (n int, err error) {
|
102 |
| - n, err = Finfo(color.Output, a...) |
| 108 | + n, err = Finfo(output, a...) |
103 | 109 | return
|
104 | 110 | }
|
105 | 111 |
|
106 | 112 | // Sinfo returns cyan colored string in manner of fmt.Sprint
|
107 | 113 | func Sinfo(a ...interface{}) string {
|
108 |
| - return color.New(color.FgCyan).Sprint(a...) |
| 114 | + return fmt.Sprint(aurora.Cyan(fmt.Sprint(a...))) |
109 | 115 | }
|
110 | 116 |
|
111 | 117 | // Fwarning prints yellow colored text in manner of fmt.Fprint
|
112 | 118 | func Fwarning(w io.Writer, a ...interface{}) (n int, err error) {
|
113 |
| - n, err = color.New(color.FgYellow).Fprint(w, a...) |
| 119 | + n, err = fmt.Fprint(w, aurora.Brown(fmt.Sprint(a...))) |
114 | 120 | return
|
115 | 121 | }
|
116 | 122 |
|
117 | 123 | // Warning prints yellow colored text in manner of fmt.Print
|
118 | 124 | func Warning(a ...interface{}) (n int, err error) {
|
119 |
| - n, err = Fwarning(color.Output, a...) |
| 125 | + n, err = Fwarning(output, a...) |
120 | 126 | return
|
121 | 127 | }
|
122 | 128 |
|
123 | 129 | // Swarning returns yellow colored string in manner of fmt.Sprint
|
124 | 130 | func Swarning(a ...interface{}) string {
|
125 |
| - return color.New(color.FgYellow).Sprint(a...) |
| 131 | + return fmt.Sprint(aurora.Brown(fmt.Sprint(a...))) |
126 | 132 | }
|
127 | 133 |
|
128 | 134 | // Ferror prints red colored text in manner of fmt.Fprint
|
129 | 135 | func Ferror(w io.Writer, a ...interface{}) (n int, err error) {
|
130 |
| - n, err = color.New(color.FgRed).Fprint(w, a...) |
| 136 | + n, err = fmt.Fprint(w, aurora.Red(fmt.Sprint(a...))) |
131 | 137 | return
|
132 | 138 | }
|
133 | 139 |
|
134 | 140 | // Error prints red colored text in manner of fmt.Print
|
135 | 141 | func Error(a ...interface{}) (n int, err error) {
|
136 |
| - n, err = Ferror(color.Output, a...) |
| 142 | + n, err = Ferror(output, a...) |
137 | 143 | return
|
138 | 144 | }
|
139 | 145 |
|
140 | 146 | // Serror returns red colored string in manner of fmt.Sprint
|
141 | 147 | func Serror(a ...interface{}) string {
|
142 |
| - return color.New(color.FgRed).Sprint(a...) |
| 148 | + return fmt.Sprint(aurora.Red(fmt.Sprint(a...))) |
143 | 149 | }
|
144 | 150 |
|
145 | 151 | // Fsuccessln prints green colored text in manner of fmt.Fprintln
|
146 | 152 | func Fsuccessln(w io.Writer, a ...interface{}) (n int, err error) {
|
147 |
| - n, err = color.New(color.FgGreen).Fprintln(w, a...) |
| 153 | + n, err = fmt.Fprintln(w, aurora.Green(fmt.Sprint(a...))) |
148 | 154 | return
|
149 | 155 | }
|
150 | 156 |
|
151 | 157 | // Successln prints green colored text in manner of fmt.Println
|
152 | 158 | func Successln(a ...interface{}) (n int, err error) {
|
153 |
| - n, err = Fsuccessln(color.Output, a...) |
| 159 | + n, err = Fsuccessln(output, a...) |
154 | 160 | return
|
155 | 161 | }
|
156 | 162 |
|
157 | 163 | // Ssuccessln returns green colored string in manner of fmt.Sprintln
|
158 | 164 | func Ssuccessln(a ...interface{}) string {
|
159 |
| - return color.New(color.FgGreen).Sprintln(a...) |
| 165 | + return fmt.Sprintln(aurora.Green(fmt.Sprint(a...))) |
160 | 166 | }
|
161 | 167 |
|
162 | 168 | // Finfoln prints cyan colored text in manner of fmt.Fprintln
|
163 | 169 | func Finfoln(w io.Writer, a ...interface{}) (n int, err error) {
|
164 |
| - n, err = color.New(color.FgCyan).Fprintln(w, a...) |
| 170 | + n, err = fmt.Fprintln(w, aurora.Cyan(fmt.Sprint(a...))) |
165 | 171 | return
|
166 | 172 | }
|
167 | 173 |
|
168 | 174 | // Infoln prints cyan colored text in manner of fmt.Println
|
169 | 175 | func Infoln(a ...interface{}) (n int, err error) {
|
170 |
| - n, err = Finfoln(color.Output, a...) |
| 176 | + n, err = Finfoln(output, a...) |
171 | 177 | return
|
172 | 178 | }
|
173 | 179 |
|
174 | 180 | // Sinfoln returns cyan colored string in manner of fmt.Sprintln
|
175 | 181 | func Sinfoln(a ...interface{}) string {
|
176 |
| - return color.New(color.FgCyan).Sprintln(a...) |
| 182 | + return fmt.Sprintln(aurora.Cyan(fmt.Sprint(a...))) |
177 | 183 | }
|
178 | 184 |
|
179 | 185 | // Fwarningln prints yellow colored text in manner of fmt.Fprintln
|
180 | 186 | func Fwarningln(w io.Writer, a ...interface{}) (n int, err error) {
|
181 |
| - n, err = color.New(color.FgYellow).Fprintln(w, a...) |
| 187 | + n, err = fmt.Fprintln(w, aurora.Brown(fmt.Sprint(a...))) |
182 | 188 | return
|
183 | 189 | }
|
184 | 190 |
|
185 | 191 | // Warningln prints yellow colored text in manner of fmt.Println
|
186 | 192 | func Warningln(a ...interface{}) (n int, err error) {
|
187 |
| - n, err = Fwarningln(color.Output, a...) |
| 193 | + n, err = Fwarningln(output, a...) |
188 | 194 | return
|
189 | 195 | }
|
190 | 196 |
|
191 | 197 | // Swarningln returns yellow colored string in manner of fmt.Sprintln
|
192 | 198 | func Swarningln(a ...interface{}) string {
|
193 |
| - return color.New(color.FgYellow).Sprintln(a...) |
| 199 | + return fmt.Sprintln(aurora.Brown(fmt.Sprint(a...))) |
194 | 200 | }
|
195 | 201 |
|
196 | 202 | // Ferrorln prints red colored text in manner of fmt.Fprintln
|
197 | 203 | func Ferrorln(w io.Writer, a ...interface{}) (n int, err error) {
|
198 |
| - n, err = color.New(color.FgRed).Fprintln(w, a...) |
| 204 | + n, err = fmt.Fprintln(w, aurora.Red(fmt.Sprint(a...))) |
199 | 205 | return
|
200 | 206 | }
|
201 | 207 |
|
202 | 208 | // Errorln prints red colored text in manner of fmt.Println
|
203 | 209 | func Errorln(a ...interface{}) (n int, err error) {
|
204 |
| - n, err = Ferrorln(color.Output, a...) |
| 210 | + n, err = Ferrorln(output, a...) |
205 | 211 | return
|
206 | 212 | }
|
207 | 213 |
|
208 | 214 | // Serrorln returns red colored string in manner of fmt.Sprintln
|
209 | 215 | func Serrorln(a ...interface{}) string {
|
210 |
| - return color.New(color.FgRed).Sprintln(a...) |
| 216 | + return fmt.Sprintln(aurora.Red(fmt.Sprint(a...))) |
211 | 217 | }
|
0 commit comments