mirror of https://github.com/lcpz/lain.git
Merge branch 'master' of https://github.com/copycat-killer/lain
This commit is contained in:
commit
137e072153
20
helpers.lua
20
helpers.lua
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
@ -66,13 +73,12 @@ local function worker(args)
|
|||
until line == nil
|
||||
|
||||
p:close()
|
||||
table.sort(boxes)
|
||||
|
||||
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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -21,10 +21,9 @@ local setmetatable = setmetatable
|
|||
|
||||
-- Network infos
|
||||
-- lain.widgets.net
|
||||
local net = {
|
||||
last_t = 0,
|
||||
last_r = 0
|
||||
}
|
||||
|
||||
local function worker(args)
|
||||
local net = { last_t = 0, last_r = 0 }
|
||||
|
||||
function net.get_device()
|
||||
local ws = helpers.read_pipe("ip link show | cut -d' ' -f2,9")
|
||||
|
@ -36,15 +35,13 @@ function net.get_device()
|
|||
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
|
||||
|
||||
iface = args.iface or net.get_device()
|
||||
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
2
wiki
|
@ -1 +1 @@
|
|||
Subproject commit 35cc75dcb382fccdec6941698a1e96cc875fae1f
|
||||
Subproject commit cefdc887c46f0f7c5d837d1449927e7dbf66b19e
|
Loading…
Reference in New Issue