lain/widgets/abase.lua

45 lines
1.2 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
2016-03-03 12:40:49 +01:00
if output ~= abase.prev then
widget = abase.widget
settings()
abase.prev = output
end
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 })