diff --git a/src/text.moon b/src/text.moon index 8fef554..29c67b9 100644 --- a/src/text.moon +++ b/src/text.moon @@ -45,17 +45,19 @@ word_wrap = (text, max_width) -> line = "" for i=2, #colored, 2 -- Skip over the colors themselves words = split(colored[i], " ") - line = line..words[1] - last_color = colored[i-1] - for j=2, #words - tmp = line.." "..words[j] - if font\getWidth(tmp) > max_width - table.insert(list[l], last_color) - table.insert(list[l], line) - l += 1 - table.insert(list, {}) - line = words[j] - else line = tmp + if #words > 0 + line = line..words[1] + last_color = colored[i-1] + for j=2, #words + tmp = line.." "..words[j] + if font\getWidth(tmp) > max_width + table.insert(list[l], last_color) + table.insert(list[l], line) + l += 1 + table.insert(list, {}) + line = words[j] + else line = tmp + if #words > 1 then line = line.." " table.insert(list[l], last_color) table.insert(list[l], line) line = "" diff --git a/src/text_color.moon b/src/text_color.moon index 877b51a..b1c8f42 100644 --- a/src/text_color.moon +++ b/src/text_color.moon @@ -14,12 +14,15 @@ color_map = { "x1b[37;1m": rgb(236, 239, 244) } colorify = (str, i=1, last_color=reset, result={}) -> - s, e = str\find("x1b%[%d*;*%dm", i) + s, e = str\find("\\*x1b%[%d*;*%dm", i) if s == nil table.insert(result, last_color) table.insert(result, str\sub(i, -1)) return result - color = color_map[str\sub(s, e)] + offset = 0 + if str\sub(s, s) == "\\" --remove the backslash + offset = 1 + color = color_map[str\sub(s + offset, e)] if i != s table.insert(result, last_color) table.insert(result, str\sub(i, s - 1))