]> git.madduck.net Git - etc/awesome.git/blob - widgets/abase.lua

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

#126 calendar: local scrp fix
[etc/awesome.git] / widgets / abase.lua
1
2 --[[
3                                                   
4      Licensed under GNU General Public License v2 
5       * (c) 2014, Luke Bonham                     
6                                                   
7 --]]
8
9 local newtimer     = require("lain.helpers").newtimer
10 local async        = require("lain.asyncshell")
11 local wibox        = require("wibox")
12
13 local setmetatable = setmetatable
14
15 -- Basic template for custom widgets
16 -- Asynchronous version
17 -- lain.widgets.abase
18
19 local function worker(args)
20     local abase    = {}
21     local args     = args or {}
22     local timeout  = args.timeout or 5
23     local cmd      = args.cmd or ""
24     local settings = args.settings or function() end
25
26     abase.widget = wibox.widget.textbox('')
27
28     function abase.update()
29         async.request(cmd, function(f)
30             output = f:read("*all")
31             f:close()
32             widget = abase.widget
33             settings()
34         end)
35     end
36
37     newtimer(cmd, timeout, abase.update)
38
39     return setmetatable(abase, { __index = abase.widget })
40 end
41
42 return setmetatable({}, { __call = function(_, ...) return worker(...) end })