This commit is contained in:
aajjbb 2016-01-02 18:16:02 -02:00
commit 137e072153
5 changed files with 56 additions and 30 deletions

View File

@ -13,6 +13,7 @@ local io = { open = io.open,
lines = io.lines,
popen = io.popen }
local rawget = rawget
local table = { sort = table.sort }
-- Lain helper functions for internal use
-- 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

View File

@ -9,9 +9,11 @@
local newtimer = require("lain.helpers").newtimer
local read_pipe = require("lain.helpers").read_pipe
local spairs = require("lain.helpers").spairs
local wibox = require("wibox")
local awful = require("awful")
local util = require("lain.util")
local io = { popen = io.popen }
@ -19,7 +21,6 @@ local os = { getenv = os.getenv }
local pairs = pairs
local string = { len = string.len,
match = string.match }
local table = { sort = table.sort }
local setmetatable = setmetatable
@ -33,13 +34,19 @@ local function worker(args)
local mailpath = args.mailpath or os.getenv("HOME") .. "/Mail"
local ignore_boxes = args.ignore_boxes or {}
local settings = args.settings or function() end
local ext_mail_cmd = args.external_mail_cmd
maildir.widget = wibox.widget.textbox('')
function update()
if ext_mail_cmd ~= nil
then
awful.util.spawn(ext_mail_cmd)
end
-- Find pathes to mailboxes.
local p = io.popen("find " .. mailpath ..
" -mindepth 1 -maxdepth 1 -type d" ..
" -mindepth 1 -maxdepth 2 -type d" ..
" -not -name .git")
local boxes = {}
repeat
@ -56,7 +63,7 @@ local function worker(args)
"-not -name '.*' -printf a")
-- Strip off leading mailpath.
local box = string.match(line, mailpath .. "/*([^/]+)")
local box = string.match(line, mailpath .. "/(.*)")
local nummails = string.len(mailstring)
if nummails > 0
then
@ -65,14 +72,13 @@ local function worker(args)
end
until line == nil
p:close()
table.sort(boxes)
p:close()
newmail = "no mail"
-- Count the total number of mails irrespective of where it was found
total = 0
for box, number in pairs(boxes)
for box, number in spairs(boxes)
do
-- Add this box only if it's not to be ignored.
if not util.element_in_table(box, ignore_boxes)

View File

@ -59,6 +59,7 @@ local function worker(args)
mpd_now = {
state = "N/A",
file = "N/A",
name = "N/A",
artist = "N/A",
title = "N/A",
album = "N/A",
@ -71,6 +72,7 @@ local function worker(args)
for k, v in string.gmatch(line, "([%w]+):[%s](.*)$") do
if k == "state" then mpd_now.state = v
elseif k == "file" then mpd_now.file = v
elseif k == "Name" then mpd_now.name = escape_f(v)
elseif k == "Artist" then mpd_now.artist = escape_f(v)
elseif k == "Title" then mpd_now.title = escape_f(v)
elseif k == "Album" then mpd_now.album = escape_f(v)

View File

@ -21,30 +21,27 @@ local setmetatable = setmetatable
-- Network infos
-- lain.widgets.net
local net = {
last_t = 0,
last_r = 0
}
function net.get_device()
local ws = helpers.read_pipe("ip link show | cut -d' ' -f2,9")
ws = ws:match("%w+: UP") or ws:match("ppp%w+: UNKNOWN")
if ws ~= nil then
return ws:match("(%w+):")
else
return "network off"
end
end
local function worker(args)
local args = args or {}
local timeout = args.timeout or 2
local units = args.units or 1024 --kb
local notify = args.notify or "on"
local screen = args.screen or 1
local settings = args.settings or function() end
local net = { last_t = 0, last_r = 0 }
iface = args.iface or net.get_device()
function net.get_device()
local ws = helpers.read_pipe("ip link show | cut -d' ' -f2,9")
ws = ws:match("%w+: UP") or ws:match("ppp%w+: UNKNOWN")
if ws ~= nil then
return ws:match("(%w+):")
else
return "network off"
end
end
local args = args or {}
local timeout = args.timeout or 2
local units = args.units or 1024 --kb
local notify = args.notify or "on"
local screen = args.screen or 1
local settings = args.settings or function() end
local iface = args.iface or net.get_device()
net.widget = wibox.widget.textbox('')
@ -100,7 +97,8 @@ local function worker(args)
end
helpers.newtimer(iface, timeout, update)
return net.widget
return setmetatable(net, { __index = net.widget })
end
return setmetatable(net, { __call = function(_, ...) return worker(...) end })
return setmetatable({}, { __call = function(_, ...) return worker(...) end })

2
wiki

@ -1 +1 @@
Subproject commit 35cc75dcb382fccdec6941698a1e96cc875fae1f
Subproject commit cefdc887c46f0f7c5d837d1449927e7dbf66b19e