abzcoding /
hget
| 1 | package main |
||
| 2 | |||
| 3 | import ( |
||
| 4 | "fmt" |
||
| 5 | "io" |
||
| 6 | "os" |
||
| 7 | |||
| 8 | "github.com/fatih/color" |
||
| 9 | "github.com/mattn/go-colorable" |
||
| 10 | "github.com/mattn/go-isatty" |
||
| 11 | ) |
||
| 12 | |||
| 13 | var ( |
||
| 14 | Stdout = colorable.NewColorableStdout() |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 15 | Stderr = colorable.NewColorableStderr() |
||
| 16 | Default UI = Console{Stdout: Stdout, Stderr: Stderr} |
||
| 17 | ) |
||
| 18 | |||
| 19 | type UI interface { |
||
|
0 ignored issues
–
show
|
|||
| 20 | Printf(format string, a ...interface{}) (n int, err error) |
||
| 21 | Println(a ...interface{}) (n int, err error) |
||
| 22 | Errorf(format string, a ...interface{}) (n int, err error) |
||
| 23 | Errorln(a ...interface{}) (n int, err error) |
||
| 24 | } |
||
| 25 | |||
| 26 | func Printf(format string, a ...interface{}) (n int, err error) { |
||
|
0 ignored issues
–
show
|
|||
| 27 | return Default.Printf(color.CyanString("INFO: ")+format, a...) |
||
|
0 ignored issues
–
show
|
|||
| 28 | } |
||
| 29 | |||
| 30 | func Errorf(format string, a ...interface{}) (n int, err error) { |
||
|
0 ignored issues
–
show
|
|||
| 31 | return Default.Errorf(color.RedString("ERROR: ")+format, a...) |
||
|
0 ignored issues
–
show
|
|||
| 32 | } |
||
| 33 | |||
| 34 | func Warnf(format string, a ...interface{}) (n int, err error) { |
||
|
0 ignored issues
–
show
|
|||
| 35 | return Default.Errorf(color.YellowString("WARN: ")+format, a...) |
||
|
0 ignored issues
–
show
|
|||
| 36 | } |
||
| 37 | |||
| 38 | func Errorln(a ...interface{}) (n int, err error) { |
||
|
0 ignored issues
–
show
|
|||
| 39 | return Default.Errorln(a...) |
||
| 40 | } |
||
| 41 | |||
| 42 | func IsTerminal(f *os.File) bool { |
||
|
0 ignored issues
–
show
|
|||
| 43 | return isatty.IsTerminal(f.Fd()) |
||
| 44 | } |
||
| 45 | |||
| 46 | type Console struct { |
||
|
0 ignored issues
–
show
|
|||
| 47 | Stdout io.Writer |
||
| 48 | Stderr io.Writer |
||
| 49 | } |
||
| 50 | |||
| 51 | func (c Console) Printf(format string, a ...interface{}) (n int, err error) { |
||
|
0 ignored issues
–
show
|
|||
| 52 | return fmt.Fprintf(c.Stdout, format, a...) |
||
|
0 ignored issues
–
show
|
|||
| 53 | } |
||
| 54 | |||
| 55 | func (c Console) Println(a ...interface{}) (n int, err error) { |
||
|
0 ignored issues
–
show
|
|||
| 56 | return fmt.Fprintln(c.Stdout, a...) |
||
| 57 | } |
||
| 58 | |||
| 59 | func (c Console) Errorf(format string, a ...interface{}) (n int, err error) { |
||
|
0 ignored issues
–
show
|
|||
| 60 | return fmt.Fprintf(c.Stderr, format, a...) |
||
|
0 ignored issues
–
show
|
|||
| 61 | } |
||
| 62 | |||
| 63 | func (c Console) Errorln(a ...interface{}) (n int, err error) { |
||
|
0 ignored issues
–
show
|
|||
| 64 | return fmt.Fprintln(c.Stderr, a...) |
||
| 65 | } |
||
| 66 |