refactor(menubar): simplify file handling for count_table
This commit is contained in:
parent
978889e739
commit
0089b5d7c7
|
@ -119,14 +119,10 @@ end
|
||||||
|
|
||||||
local function load_count_table()
|
local function load_count_table()
|
||||||
local count_file_name = awful.util.getdir("cache") .. "/menu_count_file"
|
local count_file_name = awful.util.getdir("cache") .. "/menu_count_file"
|
||||||
|
|
||||||
local count_file = io.open (count_file_name, "r")
|
|
||||||
local count_table = {}
|
local count_table = {}
|
||||||
|
local count_file = io.open (count_file_name, "r")
|
||||||
-- read weight file
|
|
||||||
if count_file then
|
if count_file then
|
||||||
io.input (count_file)
|
for line in count_file:lines() do
|
||||||
for line in io.lines() do
|
|
||||||
local name, count = string.match(line, "([^;]+);([^;]+)")
|
local name, count = string.match(line, "([^;]+);([^;]+)")
|
||||||
if name ~= nil and count ~= nil then
|
if name ~= nil and count ~= nil then
|
||||||
count_table[name] = count
|
count_table[name] = count
|
||||||
|
@ -134,25 +130,17 @@ local function load_count_table()
|
||||||
end
|
end
|
||||||
count_file:close()
|
count_file:close()
|
||||||
end
|
end
|
||||||
|
|
||||||
return count_table
|
return count_table
|
||||||
end
|
end
|
||||||
|
|
||||||
local function write_count_table(count_table)
|
local function write_count_table(count_table)
|
||||||
local count_file_name = awful.util.getdir("cache") .. "/menu_count_file"
|
local count_file_name = awful.util.getdir("cache") .. "/menu_count_file"
|
||||||
|
|
||||||
local count_file = io.open (count_file_name, "w")
|
local count_file = io.open (count_file_name, "w")
|
||||||
|
for name, count in pairs(count_table) do
|
||||||
if count_file then
|
local str = string.format("%s;%d\n", name, count)
|
||||||
io.output (count_file)
|
count_file:write(str)
|
||||||
|
|
||||||
for name, count in pairs(count_table) do
|
|
||||||
local str = string.format("%s;%d\n", name, count)
|
|
||||||
io.write(str)
|
|
||||||
end
|
|
||||||
io.flush()
|
|
||||||
count_file:close()
|
|
||||||
end
|
end
|
||||||
|
count_file:close()
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Perform an action for the given menu item.
|
--- Perform an action for the given menu item.
|
||||||
|
|
Loading…
Reference in New Issue