From 4ed6ec1c63c1ed6bf6f16e7c0ef219cae126a1b4 Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Tue, 11 Jul 2023 21:01:24 -0400 Subject: [PATCH] correctly print new messages without overwrites in dmesg even if a prior message is a progress one --- coordinator/startup.lua | 2 +- scada-common/log.lua | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/coordinator/startup.lua b/coordinator/startup.lua index 6f279b0..ce449a2 100644 --- a/coordinator/startup.lua +++ b/coordinator/startup.lua @@ -22,7 +22,7 @@ local sounder = require("coordinator.sounder") local apisessions = require("coordinator.session.apisessions") -local COORDINATOR_VERSION = "v0.20.0" +local COORDINATOR_VERSION = "v0.20.1" local println = util.println local println_ts = util.println_ts diff --git a/scada-common/log.lua b/scada-common/log.lua index 7e2d3fd..51b5373 100644 --- a/scada-common/log.lua +++ b/scada-common/log.lua @@ -20,7 +20,9 @@ local logger = { mode = MODE.APPEND, debug = false, file = nil, - dmesg_out = nil + dmesg_out = nil, + dmesg_restore_coord = { 1, 1 }, + dmesg_scroll_count = 0 } ---@type function @@ -158,6 +160,7 @@ function log.dmesg(msg, tag, tag_color) if cur_y == out_h then out.scroll(1) out.setCursorPos(1, cur_y) + logger.dmesg_scroll_count = logger.dmesg_scroll_count + 1 else out.setCursorPos(1, cur_y + 1) end @@ -193,6 +196,7 @@ function log.dmesg(msg, tag, tag_color) if cur_y == out_h then out.scroll(1) out.setCursorPos(1, cur_y) + logger.dmesg_scroll_count = logger.dmesg_scroll_count + 1 else out.setCursorPos(1, cur_y + 1) end @@ -201,6 +205,8 @@ function log.dmesg(msg, tag, tag_color) out.write(lines[i]) end + logger.dmesg_restore_coord = { out.getCursorPos() } + _log(util.c("[", t_stamp, "] [", tag, "] ", msg)) end @@ -215,6 +221,7 @@ end ---@return function update, function done function log.dmesg_working(msg, tag, tag_color) local ts_coord = log.dmesg(msg, tag, tag_color) + local initial_scroll = logger.dmesg_scroll_count local out = logger.dmesg_out local width = (ts_coord.x2 - ts_coord.x1) + 1 @@ -225,11 +232,14 @@ function log.dmesg_working(msg, tag, tag_color) local counter = 0 local function update(sec_remaining) + local new_y = ts_coord.y - (logger.dmesg_scroll_count - initial_scroll) + if new_y < 1 then return end + local time = util.sprintf("%ds", sec_remaining) local available = width - (string.len(time) + 2) local progress = "" - out.setCursorPos(ts_coord.x1, ts_coord.y) + out.setCursorPos(ts_coord.x1, new_y) out.write(" ") if counter % 4 == 0 then @@ -249,10 +259,15 @@ function log.dmesg_working(msg, tag, tag_color) out.setTextColor(initial_color) counter = counter + 1 + + out.setCursorPos(table.unpack(logger.dmesg_restore_coord)) end local function done(ok) - out.setCursorPos(ts_coord.x1, ts_coord.y) + local new_y = ts_coord.y - (logger.dmesg_scroll_count - initial_scroll) + if new_y < 1 then return end + + out.setCursorPos(ts_coord.x1, new_y) if ok or ok == nil then out.setTextColor(colors.green) @@ -263,6 +278,8 @@ function log.dmesg_working(msg, tag, tag_color) end out.setTextColor(initial_color) + + out.setCursorPos(table.unpack(logger.dmesg_restore_coord)) end return update, done