forked from etienne-napoleone/chalk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chalk.v
92 lines (82 loc) · 2.27 KB
/
chalk.v
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
module chalk
import strconv
const (
prefix = '\e['
suffix = 'm'
foreground_colors = {
'black': 30
'red': 31
'green': 32
'yellow': 33
'blue': 34
'magenta': 35
'cyan': 36
'default': 39
'light_gray': 37
'dark_gray': 90
'light_red': 91
'light_green': 92
'light_yellow': 93
'light_blue': 94
'light_magenta': 95
'light_cyan': 96
'white': 97
}
background_colors = {
'black': 40
'red': 41
'green': 42
'yellow': 44
'blue': 44
'magenta': 45
'cyan': 46
'default': 49
'light_gray': 47
'dark_gray': 100
'light_red': 101
'light_green': 102
'light_yellow': 103
'light_blue': 104
'light_magenta': 105
'light_cyan': 106
'white': 107
}
style = {
'bold': 1
'dim': 2
'underline': 4
'blink': 5
'reverse': 7
'hidden': 8
}
fg_rgb = 38
bg_rgb = 48
reset = '${prefix}0${suffix}'
)
pub fn fg(text string, color string) string {
return '$prefix${foreground_colors[color]}$suffix$text$reset'
}
pub fn fg_rgb(text string, r int, g int, b int) string {
return '$prefix$fg_rgb;2;$r;$g;${b}$suffix$text$reset'
}
pub fn fg_hex(text string, hex string) string {
r := strconv.common_parse_int(hex[1..3], 16, 16, true, false) or { 0 }
g := strconv.common_parse_int(hex[3..5], 16, 16, true, false) or { 0 }
b := strconv.common_parse_int(hex[5..7], 16, 16, true, false) or { 0 }
return fg_rgb(text, int(r), int(g), int(b))
}
pub fn bg(text string, color string) string {
return '$prefix${background_colors[color]}$suffix$text$reset'
}
pub fn bg_rgb(text string, r int, g int, b int) string {
return '$prefix$bg_rgb;2;$r;$g;${b}$suffix$text$reset'
}
pub fn bg_hex(text string, hex string) string {
r := strconv.common_parse_int(hex[1..3], 16, 16, true, false) or { 0 }
g := strconv.common_parse_int(hex[3..5], 16, 16, true, false) or { 0 }
b := strconv.common_parse_int(hex[5..7], 16, 16, true, false) or { 0 }
return bg_rgb(text, int(r), int(g), int(b))
}
pub fn style(text string, color string) string {
return '$prefix${style[color]}$suffix$text$reset'
}