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

quake: allow to pass extra arguments
[etc/awesome.git] / util / markup.lua
1
2 --[[
3                                  
4      Licensed under MIT License  
5       * (c) 2013, Luke Bonham    
6       * (c) 2009, Uli Schlachter 
7       * (c) 2009, Majic          
8                                  
9 --]]
10
11 local beautiful    = require("beautiful")
12 local tostring     = tostring
13 local setmetatable = setmetatable
14
15 -- Lain markup util submodule
16 -- lain.util.markup
17 local markup = {}
18
19 local fg = {}
20 local bg = {}
21
22 -- Convenience tags.
23 function markup.bold(text)      return '<b>'     .. tostring(text) .. '</b>'     end
24 function markup.italic(text)    return '<i>'     .. tostring(text) .. '</i>'     end
25 function markup.strike(text)    return '<s>'     .. tostring(text) .. '</s>'     end
26 function markup.underline(text) return '<u>'     .. tostring(text) .. '</u>'     end
27 function markup.monospace(text) return '<tt>'    .. tostring(text) .. '</tt>'    end
28 function markup.big(text)       return '<big>'   .. tostring(text) .. '</big>'   end
29 function markup.small(text)     return '<small>' .. tostring(text) .. '</small>' end
30
31 -- Set the font.
32 function markup.font(font, text)
33   return '<span font="'  .. tostring(font)  .. '">' .. tostring(text) ..'</span>'
34 end
35
36 -- Set the foreground.
37 function fg.color(color, text)
38   return '<span foreground="' .. tostring(color) .. '">' .. tostring(text) .. '</span>'
39 end
40
41 -- Set the background.
42 function bg.color(color, text)
43   return '<span background="' .. tostring(color) .. '">' .. tostring(text) .. '</span>'
44 end
45
46 -- Context: focus
47 function fg.focus(text) return fg.color(beautiful.fg_focus, text) end
48 function bg.focus(text) return bg.color(beautiful.bg_focus, text) end
49 function markup.focus(text) return bg.focus(fg.focus(text)) end
50
51 -- Context: normal
52 function fg.normal(text) return fg.color(beautiful.fg_normal, text) end
53 function bg.normal(text) return bg.color(beautiful.bg_normal, text) end
54 function markup.normal(text) return bg.normal(fg.normal(text)) end
55
56 -- Context: urgent
57 function fg.urgent(text) return fg.color(beautiful.fg_urgent, text) end
58 function bg.urgent(text) return bg.color(beautiful.bg_urgent, text) end
59 function markup.urgent(text) return bg.urgent(fg.urgent(text)) end
60
61 markup.fg = fg
62 markup.bg = bg
63
64 -- link markup.{fg,bg}(...) calls to markup.{fg,bg}.color(...)
65 setmetatable(markup.fg, { __call = function(_, ...) return markup.fg.color(...) end })
66 setmetatable(markup.bg, { __call = function(_, ...) return markup.bg.color(...) end })
67
68 -- link markup(...) calls to markup.fg.color(...)
69 return setmetatable(markup, { __call = function(_, ...) return markup.fg.color(...) end })