From 7610e1064feafd1563d468d53b70f4144e3b640d Mon Sep 17 00:00:00 2001 From: rxi Date: Wed, 6 May 2020 00:06:27 +0100 Subject: [PATCH] Added multiline support for LogView's messages --- data/core/init.lua | 2 +- data/core/logview.lua | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/data/core/init.lua b/data/core/init.lua index 18096ac..26e9d0e 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -226,7 +226,7 @@ end local function log(icon, icon_color, fmt, ...) - local text = string.format(fmt, ...):gsub("%s", " ") + local text = string.format(fmt, ...) if icon then core.status_view:show_message(icon, icon_color, text) end diff --git a/data/core/logview.lua b/data/core/logview.lua index 53ea6d2..d7142fb 100644 --- a/data/core/logview.lua +++ b/data/core/logview.lua @@ -33,6 +33,18 @@ function LogView:update() end +local function draw_text_multiline(font, text, x, y, color) + local th = font:get_height() + local resx, resy = x, y + for line in text:gmatch("[^\n]+") do + resy = y + resx = renderer.draw_text(style.font, line, x, y, color) + y = y + th + end + return resx, resy +end + + function LogView:draw() self:draw_background(style.background) @@ -47,14 +59,12 @@ function LogView:draw() x = renderer.draw_text(style.font, time, x, y, style.dim) x = x + style.padding.x local subx = x - x = renderer.draw_text(style.font, item.text, x, y, style.text) - x = renderer.draw_text(style.font, " at " .. item.at, x, y, style.dim) + x, y = draw_text_multiline(style.font, item.text, x, y, style.text) + renderer.draw_text(style.font, " at " .. item.at, x, y, style.dim) y = y + th if item.info then - for line in item.info:gmatch("[^\n]+") do - renderer.draw_text(style.font, line, subx, y, style.dim) - y = y + th - end + subx, y = draw_text_multiline(style.font, item.info, subx, y, style.dim) + y = y + th end y = y + style.padding.y end