From 8147032a532a73b03bd04dee0ee959f035377526 Mon Sep 17 00:00:00 2001 From: luke bonham Date: Thu, 13 Feb 2014 17:35:55 +0100 Subject: [PATCH] base widget added (this time for real) --- widgets/base.lua | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 widgets/base.lua diff --git a/widgets/base.lua b/widgets/base.lua new file mode 100644 index 0000000..0431d03 --- /dev/null +++ b/widgets/base.lua @@ -0,0 +1,37 @@ + +--[[ + + Licensed under GNU General Public License v2 + * (c) 2014, Luke Bonham + +--]] + +local newtimer = require("lain.helpers").newtimer +local wibox = require("wibox") + +local io = io +local setmetatable = setmetatable + +-- Basic template for simple widgets +-- lain.widgets.base +local base = {} + +local function worker(args) + local args = args or {} + local timeout = args.timeout or 5 + local cmd = args.cmd or "" + local settings = args.settings or function() end + + base.widget = wibox.widget.textbox('') + + function update() + output = io.popen(cmd):read("*all") + widget = base.widget + settings() + end + + newtimer(cmd, timeout, update) + return base.widget +end + +return setmetatable(base, { __call = function(_, ...) return worker(...) end })