-
Notifications
You must be signed in to change notification settings - Fork 0
/
coloring.go
68 lines (61 loc) · 1.76 KB
/
coloring.go
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
66
67
68
package hobocode
import (
"fmt"
"os"
"github.com/jedib0t/go-pretty/v6/text"
)
/*
TODO: Should possibly check terminal width and try to nicely wrap to the indent if width is going to exceed
*/
// Icolor prints the given string at the given indent
// to the given os.File with the given text.Color, if colorable
// with newline
func Icolor(indent int, fd *os.File, color text.Color, message string) {
id := Tindent(indent)
if Colorable(fd) {
fmt.Fprint(fd, id)
Stdlin(fd, color.Sprint(message))
} else {
fmt.Fprint(fd, id)
Stdlin(fd, message)
}
}
// Icolorf prints the given format at the given indent
// to the given os.File with the given text.Color, if colorable
// with newline
func Icolorf(indent int, fd *os.File, color text.Color, format string, a ...interface{}) {
id := Tindent(indent)
if Colorable(fd) {
fmt.Fprint(fd, id)
Stdlin(fd, color.Sprintf(format, a...))
} else {
fmt.Fprint(fd, id)
Stdlin(fd, fmt.Sprintf(format, a...))
}
}
// Ficolor prints the given string at the given indent
// to the given os.File with the given text.Color, if colorable
// and does not newline
func Ficolor(indent int, fd *os.File, color text.Color, format string, a ...interface{}) {
id := Tindent(indent)
if Colorable(fd) {
fmt.Fprint(fd, id)
Std(fd, color.Sprintf(format, a...))
} else {
fmt.Fprint(fd, id)
Std(fd, fmt.Sprintf(format, a...))
}
}
// Ficolorf prints the given format at the given indent
// to the given os.File with the given text.Color, if colorable
// and does not newline
func Ficolorf(indent int, fd *os.File, color text.Color, format string, a ...interface{}) {
id := Tindent(indent)
if Colorable(fd) {
fmt.Fprint(fd, id)
Std(fd, color.Sprintf(format, a...))
} else {
fmt.Fprint(fd, id)
Std(fd, fmt.Sprintf(format, a...))
}
}