mirror of https://github.com/lcpz/lain.git
commit
5ea12705d4
20
helpers.lua
20
helpers.lua
|
@ -13,6 +13,7 @@ local io = { open = io.open,
|
||||||
lines = io.lines,
|
lines = io.lines,
|
||||||
popen = io.popen }
|
popen = io.popen }
|
||||||
local rawget = rawget
|
local rawget = rawget
|
||||||
|
local table = { sort = table.sort }
|
||||||
|
|
||||||
-- Lain helper functions for internal use
|
-- Lain helper functions for internal use
|
||||||
-- lain.helpers
|
-- lain.helpers
|
||||||
|
@ -113,4 +114,23 @@ end
|
||||||
|
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
|
--{{{ Iterate over table of records sorted by keys
|
||||||
|
function helpers.spairs(t)
|
||||||
|
-- collect the keys
|
||||||
|
local keys = {}
|
||||||
|
for k in pairs(t) do keys[#keys+1] = k end
|
||||||
|
|
||||||
|
table.sort(keys)
|
||||||
|
|
||||||
|
-- return the iterator function
|
||||||
|
local i = 0
|
||||||
|
return function()
|
||||||
|
i = i + 1
|
||||||
|
if keys[i] then
|
||||||
|
return keys[i], t[keys[i]]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
--}}}
|
||||||
|
|
||||||
return helpers
|
return helpers
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
local newtimer = require("lain.helpers").newtimer
|
local newtimer = require("lain.helpers").newtimer
|
||||||
local read_pipe = require("lain.helpers").read_pipe
|
local read_pipe = require("lain.helpers").read_pipe
|
||||||
|
local spairs = require("lain.helpers").spairs
|
||||||
|
|
||||||
local wibox = require("wibox")
|
local wibox = require("wibox")
|
||||||
|
|
||||||
|
@ -19,7 +20,6 @@ local os = { getenv = os.getenv }
|
||||||
local pairs = pairs
|
local pairs = pairs
|
||||||
local string = { len = string.len,
|
local string = { len = string.len,
|
||||||
match = string.match }
|
match = string.match }
|
||||||
local table = { sort = table.sort }
|
|
||||||
|
|
||||||
local setmetatable = setmetatable
|
local setmetatable = setmetatable
|
||||||
|
|
||||||
|
@ -66,13 +66,12 @@ local function worker(args)
|
||||||
until line == nil
|
until line == nil
|
||||||
|
|
||||||
p:close()
|
p:close()
|
||||||
table.sort(boxes)
|
|
||||||
|
|
||||||
newmail = "no mail"
|
newmail = "no mail"
|
||||||
-- Count the total number of mails irrespective of where it was found
|
-- Count the total number of mails irrespective of where it was found
|
||||||
total = 0
|
total = 0
|
||||||
|
|
||||||
for box, number in pairs(boxes)
|
for box, number in spairs(boxes)
|
||||||
do
|
do
|
||||||
-- Add this box only if it's not to be ignored.
|
-- Add this box only if it's not to be ignored.
|
||||||
if not util.element_in_table(box, ignore_boxes)
|
if not util.element_in_table(box, ignore_boxes)
|
||||||
|
|
Loading…
Reference in New Issue