]> git.madduck.net Git - etc/awesome.git/blob - widgets/contrib/task.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:

taskwarrior: asynchronous; #213 enhanced
[etc/awesome.git] / widgets / contrib / task.lua
1
2 --[[
3                                                   
4      Licensed under GNU General Public License v2 
5       * (c) 2013, Jan Xie                         
6                                                   
7 --]]
8
9 local helpers = require("lain.helpers")
10 local awful   = require("awful")
11 local naughty = require("naughty")
12 local string  = { format = string.format, gsub = string.gsub }
13
14 -- Taskwarrior notification
15 -- lain.widgets.contrib.task
16 local task = {}
17
18 function task.hide()
19     if not task.notification then return end
20     naughty.destroy(task.notification)
21     task.notification = nil
22 end
23
24 function task.show(scr)
25     task.hide()
26
27     if task.followtag then
28         task.notification_preset.screen = awful.screen.focused()
29     elseif scr then
30         task.notification_preset.screen = scr
31     end
32
33     helpers.async(string.format("%s -c '%s'", awful.util.shell, task.cmd),
34     function(f)
35         task.notification = naughty.notify({
36             preset = task_notification_preset,
37             title  = task.cmd,
38             text   = markup.font(task.notification_preset.font,
39                      awful.util.escape(f:gsub("\n*$", "")))
40         })
41     end)
42 end
43
44 function task.prompt()
45     awful.prompt.run {
46         prompt       = task.prompt_text,
47         textbox      = awful.screen.focused().mypromptbox.widget,
48         exe_callback = function(t)
49             helpers.async(string.format("%s -c '%s'", awful.util.shell, t),
50             function(f)
51                 naughty.notify {
52                     preset = task_notification_preset,
53                     title    = t,
54                     text     = markup.font(task.notification_preset.font,
55                                awful.util.escape(f:gsub("\n*$", "")))
56                 }
57             end)
58         end,
59         history_path = awful.util.getdir("cache") .. "/history_task"
60     }
61 end
62
63 function task.attach(widget, args)
64     local args               = args or {}
65     task.show_cmd            = args.cmd or "task"
66     task.prompt_text         = args.prompt_text or "Enter task command: "
67     task.followtag           = args.followtag or false
68     task.notification_preset = args.notification_preset
69
70     if not task.notification_preset then
71         task.notification_preset      = naughty.config.defaults
72         task.notification_preset.font = "Monospace 10"
73         task.notification_preset.icon = helpers.icons_dir .. "/taskwarrior.png"
74     end
75
76     if widget then
77         widget:connect_signal("mouse::enter", function () task.show() end)
78         widget:connect_signal("mouse::leave", function () task.hide() end)
79     end
80 end
81
82 return task