]> 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:

cal: terminal-colors.d independent highlight matching pattern
[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(task.show_cmd, function(f)
34         task.notification = naughty.notify({
35             preset = task_notification_preset,
36             title  = task.show_cmd,
37             text   = markup.font(task.notification_preset.font,
38                      awful.util.escape(f:gsub("\n*$", "")))
39         })
40     end)
41 end
42
43 function task.prompt()
44     awful.prompt.run {
45         prompt       = task.prompt_text,
46         textbox      = awful.screen.focused().mypromptbox.widget,
47         exe_callback = function(t)
48             helpers.async(t, function(f)
49                 naughty.notify {
50                     preset = task.notification_preset,
51                     title    = t,
52                     text     = markup.font(task.notification_preset.font,
53                                awful.util.escape(f:gsub("\n*$", "")))
54                 }
55             end)
56         end,
57         history_path = awful.util.getdir("cache") .. "/history_task"
58     }
59 end
60
61 function task.attach(widget, args)
62     local args               = args or {}
63     task.show_cmd            = args.show_cmd or "task next"
64     task.prompt_text         = args.prompt_text or "Enter task command: "
65     task.followtag           = args.followtag or false
66     task.notification_preset = args.notification_preset
67
68     if not task.notification_preset then
69         task.notification_preset      = naughty.config.defaults
70         task.notification_preset.font = "Monospace 10"
71         task.notification_preset.icon = helpers.icons_dir .. "/taskwarrior.png"
72     end
73
74     if widget then
75         widget:connect_signal("mouse::enter", function () task.show() end)
76         widget:connect_signal("mouse::leave", function () task.hide() end)
77     end
78 end
79
80 return task