Software /
code /
prosody
Comparison
util/termcolours.lua @ 7205:a6c4530c1bc0
util.termcolours: Validate color codes, fixes traceback
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 28 Feb 2016 15:03:01 +0100 |
parent | 7204:ab2b7496a617 |
child | 7206:1c005878db55 |
comparison
equal
deleted
inserted
replaced
7204:ab2b7496a617 | 7205:a6c4530c1bc0 |
---|---|
13 local char, format = string.char, string.format; | 13 local char, format = string.char, string.format; |
14 local tonumber = tonumber; | 14 local tonumber = tonumber; |
15 local ipairs = ipairs; | 15 local ipairs = ipairs; |
16 local io_write = io.write; | 16 local io_write = io.write; |
17 local m_floor = math.floor; | 17 local m_floor = math.floor; |
18 local type = type; | |
19 local setmetatable = setmetatable; | |
20 local pairs = pairs; | |
18 | 21 |
19 local windows; | 22 local windows; |
20 if os.getenv("WINDIR") then | 23 if os.getenv("WINDIR") then |
21 windows = require "util.windows"; | 24 windows = require "util.windows"; |
22 end | 25 end |
74 local b = tonumber(hex:sub(5,6),16); | 77 local b = tonumber(hex:sub(5,6),16); |
75 return r,g,b; | 78 return r,g,b; |
76 end | 79 end |
77 | 80 |
78 setmetatable(stylemap, { __index = function(_, style) | 81 setmetatable(stylemap, { __index = function(_, style) |
79 local g = style:sub(7) == " background" and "48;5;" or "38;5;"; | 82 if type(style) == "string" and style:find("%x%x%x%x%x%x") == 1 then |
80 return g .. color(hex2rgb(style)); | 83 local g = style:sub(7) == " background" and "48;5;" or "38;5;"; |
84 return g .. color(hex2rgb(style)); | |
85 end | |
81 end } ); | 86 end } ); |
82 | 87 |
83 local csscolors = { | 88 local csscolors = { |
84 red = "ff0000"; fuchsia = "ff00ff"; green = "008000"; white = "ffffff"; | 89 red = "ff0000"; fuchsia = "ff00ff"; green = "008000"; white = "ffffff"; |
85 lime = "00ff00"; yellow = "ffff00"; purple = "800080"; blue = "0000ff"; | 90 lime = "00ff00"; yellow = "ffff00"; purple = "800080"; blue = "0000ff"; |