lain/widgets/base.lua

40 lines
1013 B
Lua
Raw Normal View History

2014-02-13 17:35:55 +01:00
--[[
Licensed under GNU General Public License v2
* (c) 2014, Luke Bonham
--]]
2015-10-20 15:17:44 +02:00
local newtimer = require("lain.helpers").newtimer
local read_pipe = require("lain.helpers").read_pipe
2014-02-13 17:35:55 +01:00
local wibox = require("wibox")
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)
local base = {}
2014-02-13 17:35:55 +01:00
local args = args or {}
2015-10-20 15:17:44 +02:00
local timeout = args.timeout or 5
2014-02-13 17:35:55 +01:00
local cmd = args.cmd or ""
local settings = args.settings or function() end
base.widget = wibox.widget.textbox('')
function base.update()
2015-10-20 15:17:44 +02:00
output = read_pipe(cmd)
widget = base.widget
settings()
2014-02-13 17:35:55 +01:00
end
2015-10-20 15:17:44 +02:00
newtimer(cmd, timeout, base.update)
return setmetatable(base, { __index = base.widget })
2014-02-13 17:35:55 +01:00
end
return setmetatable({}, { __call = function(_, ...) return worker(...) end })