lines = io.lines,
popen = io.popen }
local rawget = rawget
+local table = { sort = table.sort }
-- Lain helper functions for internal use
-- lain.helpers
-- }}}
+--{{{ 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
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 }
local pairs = pairs
local string = { len = string.len,
match = string.match }
-local table = { sort = table.sort }
local setmetatable = setmetatable
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
"-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
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)
mpd_now = {
state = "N/A",
file = "N/A",
+ name = "N/A",
artist = "N/A",
title = "N/A",
album = "N/A",
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)
-- 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('')
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 })
-Subproject commit 35cc75dcb382fccdec6941698a1e96cc875fae1f
+Subproject commit cefdc887c46f0f7c5d837d1449927e7dbf66b19e