-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvar.go
169 lines (154 loc) · 3.16 KB
/
var.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
const (
dir = "./config/"
file = "cfg"
colordir = "./config/colors/"
)
//init vars
var (
cfg = map[string]string{}
FileColors = map[string]string{}
colors = map[string]string{}
sws string
)
// run after Init
func debug () () {
//vars
for i:=0;i<Win.LenY-2;i++{
wprint(Win, i, 0, "\033[2K")
}
i:=0
for key, val := range cfg {
wprint(Win, i, 0, spf("%s:%s", key, val))
i++
}
wgtk(Win)
for i=0;i<Win.LenY-2;i++{
wprint(Win, i, 0, "\033[2K")
}
//colors
// add FileColors?
i=0
for key, val := range colors {
wprint(Win, i, 0, spf("%s:%spog████ %s", key, val, colors["nc"]))
i++
}
wgtk(Win)
}
func InitVars () {
cfg["flname"] = dir+file
cfg["colordir"] = colordir
sws = strings.Repeat(" ", Win.LenX)
load(dir+file)
}
func load (f string) () {
file := strings.Split(ReadFile(f), "\n")
line := ""
for i:=0;i<len(file);i++ {
line = file[i]
if len(line) < 2{continue}
value := line[strings.Index(line, ":")+1:]
name := line[:strings.Index(line, ":")]
cfg[name] = value
}
LoadColors(cfg["colorfile"])
}
func InterpretColorLine ( line string ) ( string, string ) {
h := line[0]=='"'
if h {
line = line[1:]
}
line = strings.Replace(line, " ", "", -1)
var ll = strings.Split(line, ":")
if len(ll) == 1 {
// can't use config colors lol
wuprint(Win, 0, 0, RGB(255,0,0)+"invalid color line"+RGB(255,255,255))
wuprint(Win, 1, 0, "\""+line+"\"")
exit(1)
}
var name = ""
var code = ""
name = ll[0]
cd := strings.Split(ll[1], ",")
if len(cd) == 1 {
code = colors[cd[0]]
} else if len(cd) == 3 {
if h{
code = bkcolor(cd[0], cd[1], cd[2])
} else {
code = RGB(cd[0], cd[1], cd[2])
}
} else if len(cd) == 6 {
code = color(cd[0],cd[1],cd[2], cd[3],cd[4],cd[5])
}
return name, code
}
func LoadColors ( f string ) ( ) {
var fl = strings.Split(ReadFile(cfg["colordir"]+f+".clrs"), "\n")
var line string
var cutoff int
var name string
var code string
for i:=0;i<len(fl);i++ {
line = fl[i]
cutoff = strings.Index(line, " ")
if cutoff != -1 {
line = line[:cutoff]
}
if len(line) < 3 {continue}
if line[0] == '.' {
name, code = InterpretColorLine(line)
if len(name) == 0 || len(code) == 0 {continue}
FileColors[name] = code
if line[0] == '"' {
name, code = InterpretColorLine(line)
if len(name) == 0 || len(code) == 0 {continue}
colors[name] = code
}
} else if line[0] != '#' {
name, code = InterpretColorLine(line)
if len(name) == 0 || len(code) == 0 {continue}
colors[name] = code
}
}
}
const (
T_bool = iota
T_string = iota
T_int = iota
)
func ReadCFG (name string, T int) (interface{}) {
var (
s = cfg[name]
te error
ti int
)
switch (T) {
case (T_bool):
if s == "false" || s == "true" {
return s == "true"
} else {
panic(
errors.New(spf("can't \"%s\" convert to bool", s)),
)
}
case (T_string):
return s
case (T_int):
ti, te = strconv.Atoi(s)
if te != nil {
clear()
panic(te)
}
return ti
}
return nil
}
func RCfgB(name string) (bool) {
return ReadCFG(name, T_bool).(bool)
}
func RCfgS(name string) (string) {
return ReadCFG(name, T_string).(string)
}
func RCfgI(name string) (int) {
return ReadCFG(name, T_int).(int)
}