refactor(menubar): simplify file handling for count_table

This commit is contained in:
actionless 2017-02-10 13:35:46 +01:00 committed by Yauhen Kirylau
parent 978889e739
commit 0089b5d7c7
1 changed files with 6 additions and 18 deletions

View File

@ -119,14 +119,10 @@ end
local function load_count_table()
local count_file_name = awful.util.getdir("cache") .. "/menu_count_file"
local count_file = io.open (count_file_name, "r")
local count_table = {}
-- read weight file
local count_file = io.open (count_file_name, "r")
if count_file then
io.input (count_file)
for line in io.lines() do
for line in count_file:lines() do
local name, count = string.match(line, "([^;]+);([^;]+)")
if name ~= nil and count ~= nil then
count_table[name] = count
@ -134,26 +130,18 @@ local function load_count_table()
end
count_file:close()
end
return count_table
end
local function write_count_table(count_table)
local count_file_name = awful.util.getdir("cache") .. "/menu_count_file"
local count_file = io.open (count_file_name, "w")
if count_file then
io.output (count_file)
for name, count in pairs(count_table) do
local str = string.format("%s;%d\n", name, count)
io.write(str)
count_file:write(str)
end
io.flush()
count_file:close()
end
end
--- Perform an action for the given menu item.
-- @param o The menu item.