beautiful: use regex instead of helper function
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
f9c2ee62a3
commit
1e93dda065
|
@ -26,25 +26,6 @@ module("beautiful")
|
||||||
-- Local data
|
-- Local data
|
||||||
local theme = {}
|
local theme = {}
|
||||||
|
|
||||||
--- Split line in two if it contains the '=' character.
|
|
||||||
-- @param line The line to split.
|
|
||||||
-- @return nil if the '=' character is not in the string
|
|
||||||
local function split_line(line)
|
|
||||||
local split_val = line:find('=')
|
|
||||||
|
|
||||||
if split_val and line:sub(1, 1) ~= '#' and line:sub(1, 2) ~= '--' then
|
|
||||||
-- Remove spaces and tabulations in key
|
|
||||||
local key = line:sub(1, split_val - 1):gsub(' ', ''):gsub('\t', '')
|
|
||||||
-- and extra spaces and tabulations before value
|
|
||||||
local value = line:sub(split_val + 1, -1)
|
|
||||||
while value:sub(1, 1) == ' ' or value:sub(1, 1) == '\t' do
|
|
||||||
value = value:sub(2, -1)
|
|
||||||
end
|
|
||||||
|
|
||||||
return key, value
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Get a value directly.
|
--- Get a value directly.
|
||||||
-- @param key The key.
|
-- @param key The key.
|
||||||
-- @return The value.
|
-- @return The value.
|
||||||
|
@ -64,10 +45,7 @@ function init(path)
|
||||||
return print("E: unable to load theme " .. path)
|
return print("E: unable to load theme " .. path)
|
||||||
end
|
end
|
||||||
|
|
||||||
for line in f:lines() do
|
for key, value in f:read("*all"):gsub("^","\n"):gmatch("\n[\t ]*([a-z_]+)[\t ]*=[\t ]*([^\n\t]+)") do
|
||||||
local key, value
|
|
||||||
key, value = split_line(line)
|
|
||||||
if key then
|
|
||||||
if key == "wallpaper_cmd" then
|
if key == "wallpaper_cmd" then
|
||||||
for s = 1, capi.screen.count() do
|
for s = 1, capi.screen.count() do
|
||||||
util.spawn(value, s)
|
util.spawn(value, s)
|
||||||
|
@ -82,7 +60,6 @@ function init(path)
|
||||||
-- Store.
|
-- Store.
|
||||||
theme[key] = value
|
theme[key] = value
|
||||||
end
|
end
|
||||||
end
|
|
||||||
f:close()
|
f:close()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue