lain/widgets/abase.lua

42 lines
1.1 KiB
Lua
Raw Normal View History

2014-08-08 14:10:25 +02: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 async = require("lain.asyncshell")
local wibox = require("wibox")
2014-08-08 14:10:25 +02:00
local setmetatable = setmetatable
2015-07-03 12:17:31 +02:00
-- Basic template for custom widgets
2014-08-08 14:10:25 +02:00
-- Asynchronous version
-- lain.widgets.abase
local function worker(args)
local abase = {}
local args = args or {}
2015-10-20 15:17:44 +02:00
local timeout = args.timeout or 5
2014-08-08 14:10:25 +02:00
local cmd = args.cmd or ""
local settings = args.settings or function() end
abase.widget = wibox.widget.textbox('')
function abase.update()
async.request(cmd, function(f)
2015-08-05 12:28:54 +02:00
output = f
2015-10-20 15:17:44 +02:00
widget = abase.widget
settings()
2014-08-08 14:10:25 +02:00
end)
end
2015-10-20 15:17:44 +02:00
newtimer(cmd, timeout, abase.update)
2014-08-08 14:10:25 +02:00
return setmetatable(abase, { __index = abase.widget })
end
return setmetatable({}, { __call = function(_, ...) return worker(...) end })