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
--]]
local newtimer = require("lain.helpers").newtimer
local async = require("lain.asyncshell")
local wibox = require("wibox")
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 {}
local timeout = args.timeout or 5
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
2014-08-08 14:10:25 +02:00
widget = abase.widget
settings()
end)
end
newtimer(cmd, timeout, abase.update)
return setmetatable(abase, { __index = abase.widget })
end
return setmetatable({}, { __call = function(_, ...) return worker(...) end })