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

first commit
[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 --[[ clean this as soon as you document it
23
24   +-- markup
25   |
26   |`-- bold()        Set bold.
27   |`-- italic()      Set italicized text.
28   |`-- strike()      Set strikethrough text.
29   |`-- underline()   Set underlined text.
30   |`-- monospace()   Set monospaced text.
31   |`-- big()         Set bigger text.
32   |`-- small()       Set smaller text.
33   |`-- font()        Set the font of the text.
34   |
35   |`--+ bg
36   |   |
37   |   |`-- color()   Set background color.
38   |   |`-- focus()   Set focus  background color.
39   |   |`-- normal()  Set normal background color.
40   |    `-- urgent()  Set urgent background color.
41   |
42   |`--+ fg
43   |   |
44   |   |`-- color()   Set foreground color.
45   |   |`-- focus()   Set focus  foreground color.
46   |   |`-- normal()  Set normal foreground color.
47   |    `-- urgent()  Set urgent foreground color.
48   |
49   |`-- focus()       Set both foreground and background focus  colors.
50   |`-- normal()      Set both foreground and background normal colors.
51    `-- urgent()      Set both foreground and background urgent colors.
52
53 ]]
54
55 -- Convenience tags.
56 function markup.bold(text)      return '<b>'     .. tostring(text) .. '</b>'     end
57 function markup.italic(text)    return '<i>'     .. tostring(text) .. '</i>'     end
58 function markup.strike(text)    return '<s>'     .. tostring(text) .. '</s>'     end
59 function markup.underline(text) return '<u>'     .. tostring(text) .. '</u>'     end
60 function markup.monospace(text) return '<tt>'    .. tostring(text) .. '</tt>'    end
61 function markup.big(text)       return '<big>'   .. tostring(text) .. '</big>'   end
62 function markup.small(text)     return '<small>' .. tostring(text) .. '</small>' end
63
64 -- Set the font.
65 function markup.font(font, text)
66   return '<span font="'  .. tostring(font)  .. '">' .. tostring(text) ..'</span>'
67 end
68
69 -- Set the foreground.
70 function fg.color(color, text)
71   return '<span foreground="' .. tostring(color) .. '">' .. tostring(text) .. '</span>'
72 end
73
74 -- Set the background.
75 function bg.color(color, text)
76   return '<span background="' .. tostring(color) .. '">' .. tostring(text) .. '</span>'
77 end
78
79 -- Context: focus
80 function fg.focus(text) return fg.color(beautiful.fg_focus, text) end
81 function bg.focus(text) return bg.color(beautiful.bg_focus, text) end
82 function markup.focus(text) return bg.focus(fg.focus(text)) end
83
84 -- Context: normal
85 function fg.normal(text) return fg.color(beautiful.fg_normal, text) end
86 function bg.normal(text) return bg.color(beautiful.bg_normal, text) end
87 function markup.normal(text) return bg.normal(fg.normal(text)) end
88
89 -- Context: urgent
90 function fg.urgent(text) return fg.color(beautiful.fg_urgent, text) end
91 function bg.urgent(text) return bg.color(beautiful.bg_urgent, text) end
92 function markup.urgent(text) return bg.urgent(fg.urgent(text)) end
93
94 markup.fg = fg
95 markup.bg = bg
96
97 -- link markup.{fg,bg}(...) calls to markup.{fg,bg}.color(...)
98 setmetatable(markup.fg, { __call = function(_, ...) return markup.fg.color(...) end })
99 setmetatable(markup.bg, { __call = function(_, ...) return markup.bg.color(...) end })
100
101 -- link markup(...) calls to markup.fg.color(...)
102 return setmetatable(markup, { __call = function(_, ...) return markup.fg.color(...) end })