]> git.madduck.net Git - etc/awesome.git/blob - widget/watch.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:

pulsebar: fix factory return
[etc/awesome.git] / widget / watch.lua
1
2 --[[
3                                                   
4      Licensed under GNU General Public License v2 
5       * (c) 2014, Luke Bonham                     
6                                                   
7 --]]
8
9 local helpers = require("lain.helpers")
10 local textbox = require("wibox.widget.textbox")
11
12 -- Template for asynchronous watcher widgets
13 -- lain.widget.watch
14
15 local function factory(args)
16     local watch     = { widget = args.widget or textbox() }
17     local args      = args or {}
18     local timeout   = args.timeout or 5
19     local nostart   = args.nostart or false
20     local stoppable = args.stoppable or false
21     local cmd       = args.cmd
22     local settings  = args.settings or function() widget:set_text(output) end
23
24     function watch.update()
25         helpers.async(cmd, function(f)
26             output = f
27             if output ~= watch.prev then
28                 widget = watch.widget
29                 settings()
30                 watch.prev = output
31             end
32         end)
33     end
34
35     watch.timer = helpers.newtimer(cmd, timeout, watch.update, nostart, stoppable)
36
37     return watch
38 end
39
40 return factory