-
Notifications
You must be signed in to change notification settings - Fork 0
/
color.go
112 lines (86 loc) · 1.92 KB
/
color.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package main
import (
"os"
"regexp"
"strconv"
"github.com/samber/mo"
)
type Color string
var rgbPattern = regexp.MustCompile("^#?([0-9a-fA-F]{6})$")
var ForegroundColor = foreground()
var HighlightColor = highlight()
var CursorColor = cursor()
var DisabledColor = disabled()
var SymLinkColor = symLink()
var CurrentDirectoryColor = currentDirectory()
var PromptColor = prompt()
var BorderColor = border()
func (c Color) String() string {
return string(c)
}
func symLink() string {
e := os.Getenv("ARROW_SYMLINK_COLOR")
if e == "" {
return "36"
}
return ColorFromString(e).OrElse(Color("36")).String()
}
func prompt() string {
e := os.Getenv("ARROW_PROMPT_COLOR")
if e == "" {
return "36"
}
return ColorFromString(e).OrElse(Color("36")).String()
}
func currentDirectory() string {
e := os.Getenv("ARROW_CURRENT_DIRECTORY_COLOR")
if e == "" {
return "57"
}
return ColorFromString(e).OrElse(Color("57")).String()
}
func disabled() string {
e := os.Getenv("ARROW_DISABLED_COLOR")
if e == "" {
return "240"
}
return ColorFromString(e).OrElse(Color("240")).String()
}
func cursor() string {
e := os.Getenv("ARROW_CURSOR_COLOR")
if e == "" {
return "57"
}
return ColorFromString(e).OrElse(Color("57")).String()
}
func foreground() string {
e := os.Getenv("ARROW_FOREGROUND_COLOR")
if e == "" {
return "15"
}
return ColorFromString(e).OrElse(Color("15")).String()
}
func highlight() string {
e := os.Getenv("ARROW_HIGHLIGHT_COLOR")
if e == "" {
return "80"
}
return ColorFromString(e).OrElse(Color("80")).String()
}
func border() string {
e := os.Getenv("ARROW_BORDER_COLOR")
if e == "" {
return "80"
}
return ColorFromString(e).OrElse(Color("80")).String()
}
func ColorFromString(s string) mo.Option[Color] {
i, err := strconv.Atoi(s)
if err == nil && i >= 0 && i <= 255 {
return mo.Some(Color(s))
}
if rgbPattern.MatchString(s) {
return mo.Some(Color(s))
}
return mo.None[Color]()
}