-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.lua
268 lines (229 loc) · 6.18 KB
/
settings.lua
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
-- functions related to configuration, both on the command-line and from config files
-- set intital value of all settings
function SettingsInit()
settings.display="~w$(day_name)~0 $(day) $(month_name) ~y$(time)~0 $(bats:color) fs:$(fs:/:color)% mem:$(mem:color)% load:$(load_percent:color)% cputemp:$(cpu_temp:color)c ~y$(ip4address:default)~0"
settings.config_files="~/.config/barmaid.lua/barmaid.conf:~/.config/barmaid.conf"
settings.config_files=settings.config_files .. ":" .. "~/.barmaid.conf"
settings.config_files=settings.config_files .. ":/etc/.barmaid.conf"
settings.modules_dir="/usr/local/lib/barmaid/:/usr/lib/barmaid:~/.local/lib/barmaid"
settings.datasock=""
settings.win_width=800
settings.win_height=40
settings.font=""
settings.output="default"
settings.foreground=""
settings.background=""
settings.xpos="center"
settings.ypos=""
settings.align=""
settings.icon_path=".:/usr/share/icons"
--steal lines is lines to take from the terminal when acting as a terminal bar
settings.steal_lines=0
settings.datafeeds={}
settings.onclicks={}
settings.modsettings={}
return settings
end
function GeometryStringNext(toks)
local tok
tok=toks:next()
if tok=="+" then return(tonumber(toks:next()))
elseif tok=="-" then return(0-tonumber(toks:next()))
else return(tonumber(toks:next()))
end
end
function ParseGeometryString(geometry)
local toks, tok
toks=strutil.TOKENIZER(geometry, "+|-", "ms")
settings.x=GeometryStringNext(toks)
settings.y=GeometryStringNext(toks)
settings.width=GeometryStringNext(toks)
settings.length=GeometryStringNext(toks)
end
function LoadConfigFile(path)
local S, str, name, value
local retval=true
if strutil.strlen(path) ==0 then return false end
if string.sub(path, 1, 1) == "~" then path=process.getenv("HOME") .. string.sub(path, 2) end
S=stream.STREAM(path, "r")
if S ~= nil
then
retval=true
str=S:readln()
while str ~= nil
do
str=strutil.trim(str)
--if string starts with '#' then it's a comment
if strutil.strlen(str) > 0 and string.sub(1,1) ~= '#'
then
toks=strutil.TOKENIZER(str, " ")
name=toks:next()
value=strutil.stripQuotes(toks:remaining())
if name=="display" or name=="display-string"
then
settings.display=value
elseif name=="xpos"
then
settings.xpos=value
elseif name=="ypos"
then
settings.ypos=value
elseif name=="width"
then
settings.win_width=tonumber(value)
elseif name=="height"
then
settings.win_height=tonumber(value)
elseif name=="geometry"
then
ParseGeometryString(value)
elseif name=="align"
then
settings.align=value
elseif name=="font" or name=="fn"
then
settings.font=value
elseif name=="foreground" or name=="fg"
then
settings.foreground=value
elseif name=="background" or name=="bg"
then
settings.background=value
elseif name=="translate" or name=="tr"
then
display_translations:parse(value)
elseif name=="output" or name=="outtype"
then
settings.output=value
elseif name=="kvfile"
then
KvFileAdd(value)
elseif name=="icon_path"
then
settings.icon_path=value
elseif name=="icon-path"
then
settings.icon_path=value
elseif name=="iconpath"
then
settings.icon_path=value
elseif name=="datasock"
then
settings.datasock=value
elseif name=="onclick"
then
OnClickAdd(value)
end
end
str=S:readln()
end
S:close()
end
return retval
end
function LoadConfigFiles()
local toks, path
toks=strutil.TOKENIZER(settings.config_files, ":")
path=toks:next()
while path ~= nil
do
if LoadConfigFile(path) then break end
path=toks:next()
end
end
function ParseCommandLineConfigFiles(args)
for i,str in ipairs(args)
do
if str=="-c"
then
settings.config_files=args[i+1]
args[i+1]=""
end
end
end
function ParseCommandLine(args)
for i,str in ipairs(args)
do
if str=="-c" then
--ignore this as we've already parsed it in 'ParseCommandLineConfigFiles'
args[i+1]=""
elseif str=="-w" then
settings.win_width=args[i+1]
args[i+1]=""
elseif str=="-h" then
settings.win_height=args[i+1]
args[i+1]=""
elseif str=="-t" or str=="-type" then
settings.output=args[i+1]
args[i+1]=""
elseif str=="-fn" or str=="-font" then
settings.font=args[i+1]
args[i+1]=""
elseif str=="-x" then
settings.xpos=args[i+1]
args[i+1]=""
elseif str=="-y" then
settings.ypos=args[i+1]
args[i+1]=""
elseif str=="-a" or str=="-align" then
settings.align=args[i+1]
args[i+1]=""
elseif str=="-fg" or str=="-foreground" then
settings.foreground=args[i+1]
args[i+1]=""
elseif str=="-bg" or str=="-background" then
settings.background=args[i+1]
args[i+1]=""
if string.sub(settings.background, 1, 1) ~= "#" and TranslateColorName(settings.background)=="" then settings.background="#"..settings.background end
elseif str=="-fg" or str=="-foreground" then
settings.foreground=args[i+1]
if string.sub(settings.foreground, 1, 1) ~= "#" and TranslateColorName(settings.foreground)=="" then settings.foreground="#"..settings.foreground end
elseif str=="-kvfile"
then
KvFileAdd(args[i+1])
args[i+1]=""
elseif str=="-tr"
then
ParseDisplayTranslation(args[i+1])
args[i+1]=""
elseif str=="-sock"
then
settings.datasock=args[i+1]
args[i+1]=""
elseif str=="-onclick"
then
OnClickAdd(args[i+1])
args[i+1]=""
elseif str=="-help-colors" or str=="--help-colors" or str=="-help-colours"
then
DisplayHelpColors()
elseif str=="-help-images" or str=="--help-images"
then
DisplayHelpImages()
elseif str=="-help-values" or str=="--help-values"
then
DisplayHelpValues()
elseif str=="-help-sock" or str=="--help-sock"
then
DisplayHelpDatasocket()
elseif str=="-help-onclick" or str=="--help-onclick"
then
DisplayHelpOnClick()
elseif str=="-help-translate" or str=="--help-translate"
then
DisplayHelpTranslate()
elseif str=="-help-config" or str=="--help-config"
then
DisplayHelpConfig()
elseif str=="-?" or str=="-help" or str=="--help"
then
DisplayHelp()
elseif strutil.strlen(args[i]) > 0
then
settings.display=args[i]
end
end
if settings.output=="terminal" then settings.output="term" end
if settings.output=="term" then settings.steal_lines=2 end
SelectOutput(settings)
end