2014-02-13 17:35:55 +01:00
|
|
|
|
|
|
|
--[[
|
|
|
|
|
|
|
|
Licensed under GNU General Public License v2
|
|
|
|
* (c) 2014, Luke Bonham
|
|
|
|
|
|
|
|
--]]
|
|
|
|
|
|
|
|
local newtimer = require("lain.helpers").newtimer
|
|
|
|
local wibox = require("wibox")
|
|
|
|
|
2014-08-08 14:25:21 +02:00
|
|
|
local io = { popen = io.popen }
|
2014-02-13 17:35:55 +01:00
|
|
|
local setmetatable = setmetatable
|
|
|
|
|
2014-08-08 14:25:21 +02:00
|
|
|
-- Basic template for custom widgets
|
2014-02-13 17:35:55 +01:00
|
|
|
-- lain.widgets.base
|
|
|
|
|
|
|
|
local function worker(args)
|
2014-06-13 09:44:36 +02:00
|
|
|
local base = {}
|
2014-02-13 17:35:55 +01:00
|
|
|
local args = args or {}
|
|
|
|
local timeout = args.timeout or 5
|
|
|
|
local cmd = args.cmd or ""
|
|
|
|
local settings = args.settings or function() end
|
|
|
|
|
|
|
|
base.widget = wibox.widget.textbox('')
|
|
|
|
|
2014-02-13 18:17:48 +01:00
|
|
|
function base.update()
|
|
|
|
local f = assert(io.popen(cmd))
|
2015-07-26 00:59:23 +02:00
|
|
|
output = f:read("*all")
|
2014-02-13 18:17:48 +01:00
|
|
|
f:close()
|
2014-02-13 17:35:55 +01:00
|
|
|
widget = base.widget
|
|
|
|
settings()
|
|
|
|
end
|
|
|
|
|
2014-02-14 18:02:02 +01:00
|
|
|
newtimer(cmd, timeout, base.update)
|
2014-02-13 18:17:48 +01:00
|
|
|
|
|
|
|
return setmetatable(base, { __index = base.widget })
|
2014-02-13 17:35:55 +01:00
|
|
|
end
|
|
|
|
|
2014-06-13 09:44:36 +02:00
|
|
|
return setmetatable({}, { __call = function(_, ...) return worker(...) end })
|