|
1 | 1 | package etc |
2 | 2 |
|
3 | | -import "fmt" |
4 | | - |
5 | | -func PrintHeader(message string, args ...interface{}) { |
6 | | - fmt.Printf(message, args...) |
7 | | -} |
| 3 | +import ( |
| 4 | + "encoding/json" |
| 5 | + "github.com/fatih/color" |
| 6 | +) |
8 | 7 |
|
9 | 8 | func PrintInfo(message string, args ...interface{}) { |
10 | | - fmt.Printf(message, args...) |
| 9 | + c := color.New(color.FgCyan) |
| 10 | + _, _ = c.Printf(message, args...) |
11 | 11 | } |
12 | 12 |
|
13 | 13 | func PrintResponse(message string, args ...interface{}) { |
14 | | - fmt.Printf(message, args...) |
| 14 | + c := color.New(color.FgYellow).Add(color.Italic) |
| 15 | + _, _ = c.Printf(message, args...) |
| 16 | +} |
| 17 | + |
| 18 | +func PrettyPrintJson(m map[string]interface{}) { |
| 19 | + bytes, err := json.MarshalIndent(m, "", " ") |
| 20 | + if err != nil { |
| 21 | + PrintError(err.Error()) |
| 22 | + return |
| 23 | + } |
| 24 | + |
| 25 | + PrintResponse("%s\n", string(bytes)) |
15 | 26 | } |
16 | 27 |
|
17 | 28 | func PrintError(message string, args ...interface{}) { |
18 | | - fmt.Printf(message, args...) |
| 29 | + c := color.New(color.FgRed).Add(color.Bold) |
| 30 | + _, _ = c.Printf(message, args...) |
19 | 31 | } |
20 | 32 |
|
21 | 33 | func PrintSuccess(message string, args ...interface{}) { |
22 | | - fmt.Printf(message, args...) |
| 34 | + c := color.New(color.FgGreen).Add(color.Bold) |
| 35 | + _, _ = c.Printf(message, args...) |
23 | 36 | } |
0 commit comments