-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprinter.go
More file actions
65 lines (57 loc) · 1.27 KB
/
printer.go
File metadata and controls
65 lines (57 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"fmt"
"os"
"runtime"
)
type Color string
const (
colorReset Color = "\u001B[0m"
ColorBlack Color = "\u001B[30m"
ColorRed Color = "\u001B[31m"
ColorGreen Color = "\u001B[32m"
ColorYellow Color = "\u001B[33m"
ColorBlue Color = "\u001B[34m"
ColorPurple Color = "\u001B[35m"
ColorCyan Color = "\u001B[36m"
ColorWhite Color = "\u001B[37m"
)
func Println(color Color, v ...interface{}) {
if colorDisabled() {
fmt.Println(v...)
return
}
fmt.Print(color)
fmt.Print(v...)
fmt.Println(colorReset)
}
func Printf(color Color, format string, v ...interface{}) {
if colorDisabled() {
fmt.Printf(format, v...)
return
}
fmt.Print(color)
fmt.Printf(format, v...)
fmt.Print(colorReset)
}
func ErrPrintln(color Color, v ...interface{}) {
if colorDisabled() {
fmt.Fprintln(os.Stderr, v...)
return
}
fmt.Fprint(os.Stderr, color)
fmt.Fprint(os.Stderr, v...)
fmt.Fprintln(os.Stderr, colorReset)
}
func ErrPrintf(color Color, format string, v ...interface{}) {
if colorDisabled() {
fmt.Fprintf(os.Stderr, format, v...)
return
}
fmt.Fprint(os.Stderr, color)
fmt.Fprintf(os.Stderr, format, v...)
fmt.Fprint(os.Stderr, colorReset)
}
func colorDisabled() bool {
return runtime.GOOS == "windows" || os.Getenv("IMLADRIS_NO_COLOR") == "1"
}