From db5175995b4661a14255f3275f7ee3d4efbf6ce0 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 28 Feb 2016 15:03:01 +0100 Subject: util.termcolours: Validate color codes, fixes traceback --- util/termcolours.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'util/termcolours.lua') diff --git a/util/termcolours.lua b/util/termcolours.lua index a0fee7ce..dcdc994d 100644 --- a/util/termcolours.lua +++ b/util/termcolours.lua @@ -15,6 +15,9 @@ local tonumber = tonumber; local ipairs = ipairs; local io_write = io.write; local m_floor = math.floor; +local type = type; +local setmetatable = setmetatable; +local pairs = pairs; local windows; if os.getenv("WINDIR") then @@ -76,8 +79,10 @@ local function hex2rgb(hex) end setmetatable(stylemap, { __index = function(_, style) - local g = style:sub(7) == " background" and "48;5;" or "38;5;"; - return g .. color(hex2rgb(style)); + if type(style) == "string" and style:find("%x%x%x%x%x%x") == 1 then + local g = style:sub(7) == " background" and "48;5;" or "38;5;"; + return g .. color(hex2rgb(style)); + end end } ); local csscolors = { -- cgit v1.2.3