2014-02-13 17:35:55 +01:00
|
|
|
|
|
|
|
--[[
|
|
|
|
|
|
|
|
Licensed under GNU General Public License v2
|
|
|
|
* (c) 2014, Luke Bonham
|
|
|
|
|
|
|
|
--]]
|
|
|
|
|
2017-01-24 16:15:40 +01:00
|
|
|
local helpers = require("lain.helpers")
|
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)
|
2017-01-24 16:15:40 +01:00
|
|
|
local base = helpers.make_widget_textbox()
|
|
|
|
local args = args or {}
|
|
|
|
local timeout = args.timeout or 5
|
|
|
|
local nostart = args.nostart or false
|
|
|
|
local stoppable = args.stoppable or false
|
|
|
|
local cmd = args.cmd or ""
|
|
|
|
local settings = args.settings or function() end
|
2014-02-13 17:35:55 +01:00
|
|
|
|
2014-02-13 18:17:48 +01:00
|
|
|
function base.update()
|
2017-01-24 16:15:40 +01:00
|
|
|
output = helpers.read_pipe(cmd)
|
2016-03-20 22:20:55 +01:00
|
|
|
if output ~= base.prev then
|
2016-03-03 12:40:49 +01:00
|
|
|
widget = base.widget
|
|
|
|
settings()
|
2016-03-20 22:20:55 +01:00
|
|
|
base.prev = output
|
2016-03-03 12:40:49 +01:00
|
|
|
end
|
2014-02-13 17:35:55 +01:00
|
|
|
end
|
|
|
|
|
2017-01-24 16:15:40 +01:00
|
|
|
base.timer = helpers.newtimer(cmd, timeout, base.update, nostart, stoppable)
|
2014-02-13 18:17:48 +01:00
|
|
|
|
2017-01-25 17:13:14 +01:00
|
|
|
return base
|
2014-02-13 17:35:55 +01:00
|
|
|
end
|
|
|
|
|
2014-06-13 09:44:36 +02:00
|
|
|
return setmetatable({}, { __call = function(_, ...) return worker(...) end })
|