fix: avoid monitor log overlap and show upcoming status

This commit is contained in:
2026-08-02 16:24:32 +08:00
parent 5134a4ebf0
commit c13a0c9dcc
+36 -15
View File
@@ -2,7 +2,7 @@
-- ============================================================================ -- ============================================================================
-- 1. Configuration & Constants -- 1. Configuration & Constants
-- ============================================================================ -- ============================================================================
local APP_VERSION_TEXT = "v1.0.26" local APP_VERSION_TEXT = "v1.0.27"
local CONFIG = { local CONFIG = {
CLOUD_URL = "ws://stabadmin.fse-media.group", CLOUD_URL = "ws://stabadmin.fse-media.group",
@@ -2025,6 +2025,7 @@ function Display.render()
local mon = Peripherals.primaryMonitor local mon = Peripherals.primaryMonitor
if not mon then return end if not mon then return end
local w, h = mon.getSize() local w, h = mon.getSize()
local contentBottom = 4
mon.clear() mon.clear()
mon.setCursorPos(1,1) mon.setCursorPos(1,1)
mon.setTextColor(COLORS.INFO) mon.setTextColor(COLORS.INFO)
@@ -2090,6 +2091,9 @@ function Display.render()
mon.setTextColor(COLORS.ERROR) mon.setTextColor(COLORS.ERROR)
mon.write("Departing...") mon.write("Departing...")
end end
contentBottom = 9
else
contentBottom = 7
end end
else else
mon.setCursorPos(1,5) mon.setCursorPos(1,5)
@@ -2099,32 +2103,49 @@ function Display.render()
else else
mon.write("SLAVE NODE MODE") mon.write("SLAVE NODE MODE")
end end
contentBottom = 5
end end
-- Upcoming Trains -- Upcoming Trains
if State.upcomingTrains and #State.upcomingTrains > 0 then local logsStartY = h
local startY = State.currentTrain and 10 or 7 local upcomingStartY = contentBottom + 1
mon.setCursorPos(1, startY) if Peripherals.blockReader or Peripherals.createTarget then
local hasUpcoming = State.upcomingTrains and #State.upcomingTrains > 0
local maxUpcomingRows = math.max(0, h - upcomingStartY)
mon.setTextColor(COLORS.DEBUG) mon.setTextColor(COLORS.DEBUG)
mon.setCursorPos(1, upcomingStartY)
mon.write("UPCOMING TRAINS:") mon.write("UPCOMING TRAINS:")
mon.setTextColor(COLORS.INFO) if hasUpcoming then
for i = 1, math.min(3, #State.upcomingTrains) do mon.setTextColor(COLORS.INFO)
local t = State.upcomingTrains[i] local visibleCount = math.min(3, #State.upcomingTrains, math.max(0, maxUpcomingRows - 1))
mon.setCursorPos(1, startY + i) for i = 1, visibleCount do
local delayStr = t.delay > 0 and (" [+" .. t.delay .. "m]") or "" local t = State.upcomingTrains[i]
local lineText = string.format("%s->%s ETA:%ds%s", t.trainName, t.dest, t.eta, delayStr) mon.setCursorPos(1, upcomingStartY + i)
if #lineText > w then lineText = lineText:sub(1, w) end local delayStr = t.delay > 0 and (" [+" .. t.delay .. "m]") or ""
mon.write(lineText) local lineText = string.format("%s->%s ETA:%ds%s", t.trainName, t.dest, t.eta, delayStr)
if #lineText > w then lineText = lineText:sub(1, w) end
mon.write(lineText)
end
logsStartY = upcomingStartY + visibleCount + 1
else
mon.setTextColor(COLORS.WARNING)
if upcomingStartY + 1 <= h then
mon.setCursorPos(1, upcomingStartY + 1)
mon.write("NONE / WAITING DATA")
logsStartY = upcomingStartY + 2
else
logsStartY = upcomingStartY + 1
end
end end
end end
-- Logs -- Logs
local y = h - 3 local maxLogLines = math.min(3, math.max(0, h - logsStartY + 1))
for i = 1, 3 do for i = 1, maxLogLines do
local logIdx = i + State.logScrollOffset local logIdx = i + State.logScrollOffset
local entry = State.logs[logIdx] local entry = State.logs[logIdx]
if entry then if entry then
mon.setCursorPos(1, y + i - 1) mon.setCursorPos(1, logsStartY + i - 1)
mon.setTextColor(COLORS[entry.level] or colors.white) mon.setTextColor(COLORS[entry.level] or colors.white)
mon.write(entry.text:sub(1, w)) mon.write(entry.text:sub(1, w))
end end