diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-12-29 17:35:37 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-12-29 17:35:37 +0000 |
commit | e6e614c520135a4c14ff25b0cd90fb53528216d6 (patch) | |
tree | da3b885b332b003cf064193fad99dbaa75e74fb4 /src | |
parent | ec73f1ac18bc6c095b1c60b037266f5e4e4519cd (diff) | |
download | rspamd-e6e614c520135a4c14ff25b0cd90fb53528216d6.tar.gz rspamd-e6e614c520135a4c14ff25b0cd90fb53528216d6.zip |
Allow colored output
Diffstat (limited to 'src')
-rw-r--r-- | src/rspamadm/ansicolors.lua.in | 56 | ||||
-rw-r--r-- | src/rspamadm/confighelp.lua | 16 |
2 files changed, 69 insertions, 3 deletions
diff --git a/src/rspamadm/ansicolors.lua.in b/src/rspamadm/ansicolors.lua.in new file mode 100644 index 000000000..1e9ca2065 --- /dev/null +++ b/src/rspamadm/ansicolors.lua.in @@ -0,0 +1,56 @@ +local colormt = {} +local ansicolors = {} + +function colormt:__tostring() + return self.value +end + +function colormt:__concat(other) + return tostring(self) .. tostring(other) +end + +function colormt:__call(s) + return self .. s .. _M.reset +end + +colormt.__metatable = {} + +local function makecolor(value) + return setmetatable({ value = string.char(27) .. '[' .. tostring(value) .. 'm' }, colormt) +end + +local colors = { + -- attributes + reset = 0, + clear = 0, + bright = 1, + dim = 2, + underscore = 4, + blink = 5, + reverse = 7, + hidden = 8, + + -- foreground + black = 30, + red = 31, + green = 32, + yellow = 33, + blue = 34, + magenta = 35, + cyan = 36, + white = 37, + + -- background + onblack = 40, + onred = 41, + ongreen = 42, + onyellow = 43, + onblue = 44, + onmagenta = 45, + oncyan = 46, + onwhite = 47, +} + +for c, v in pairs(colors) do + ansicolors[c] = makecolor(v) +end diff --git a/src/rspamadm/confighelp.lua b/src/rspamadm/confighelp.lua index 34f323f28..28c0e2897 100644 --- a/src/rspamadm/confighelp.lua +++ b/src/rspamadm/confighelp.lua @@ -7,9 +7,19 @@ local known_attrs = { } --.USE "getopt" +--.USE "ansicolors" + + +local function maybe_print_color(key) + if opts['color'] then + return ansicolors.white .. key .. ansicolors.reset + else + return key + end +end local function print_help(key, value, tabs) - print(string.format('%sOption: %s', tabs, key)) + print(string.format('%sConfiguration element: %s', tabs, maybe_print_color(key))) if not opts['short'] then if value['data'] then @@ -23,7 +33,6 @@ local function print_help(key, value, tabs) print(string.format('%s\tExample: %s', tabs, value['example'])) end end - print('') for k, v in pairs(value) do if not known_attrs[k] then @@ -37,6 +46,7 @@ return function(args, res) opts = getopt(args, '') for k,v in pairs(res) do - print_help(k, v, ''); + print_help(k, v, '') + print('') end end |