fix: avoid monitor log overlap and show upcoming status
This commit is contained in:
+36
-15
@@ -2,7 +2,7 @@
|
||||
-- ============================================================================
|
||||
-- 1. Configuration & Constants
|
||||
-- ============================================================================
|
||||
local APP_VERSION_TEXT = "v1.0.26"
|
||||
local APP_VERSION_TEXT = "v1.0.27"
|
||||
|
||||
local CONFIG = {
|
||||
CLOUD_URL = "ws://stabadmin.fse-media.group",
|
||||
@@ -2025,6 +2025,7 @@ function Display.render()
|
||||
local mon = Peripherals.primaryMonitor
|
||||
if not mon then return end
|
||||
local w, h = mon.getSize()
|
||||
local contentBottom = 4
|
||||
mon.clear()
|
||||
mon.setCursorPos(1,1)
|
||||
mon.setTextColor(COLORS.INFO)
|
||||
@@ -2090,6 +2091,9 @@ function Display.render()
|
||||
mon.setTextColor(COLORS.ERROR)
|
||||
mon.write("Departing...")
|
||||
end
|
||||
contentBottom = 9
|
||||
else
|
||||
contentBottom = 7
|
||||
end
|
||||
else
|
||||
mon.setCursorPos(1,5)
|
||||
@@ -2099,32 +2103,49 @@ function Display.render()
|
||||
else
|
||||
mon.write("SLAVE NODE MODE")
|
||||
end
|
||||
contentBottom = 5
|
||||
end
|
||||
|
||||
-- Upcoming Trains
|
||||
if State.upcomingTrains and #State.upcomingTrains > 0 then
|
||||
local startY = State.currentTrain and 10 or 7
|
||||
mon.setCursorPos(1, startY)
|
||||
local logsStartY = h
|
||||
local upcomingStartY = contentBottom + 1
|
||||
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.setCursorPos(1, upcomingStartY)
|
||||
mon.write("UPCOMING TRAINS:")
|
||||
mon.setTextColor(COLORS.INFO)
|
||||
for i = 1, math.min(3, #State.upcomingTrains) do
|
||||
local t = State.upcomingTrains[i]
|
||||
mon.setCursorPos(1, startY + i)
|
||||
local delayStr = t.delay > 0 and (" [+" .. t.delay .. "m]") or ""
|
||||
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)
|
||||
if hasUpcoming then
|
||||
mon.setTextColor(COLORS.INFO)
|
||||
local visibleCount = math.min(3, #State.upcomingTrains, math.max(0, maxUpcomingRows - 1))
|
||||
for i = 1, visibleCount do
|
||||
local t = State.upcomingTrains[i]
|
||||
mon.setCursorPos(1, upcomingStartY + i)
|
||||
local delayStr = t.delay > 0 and (" [+" .. t.delay .. "m]") or ""
|
||||
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
|
||||
|
||||
-- Logs
|
||||
local y = h - 3
|
||||
for i = 1, 3 do
|
||||
local maxLogLines = math.min(3, math.max(0, h - logsStartY + 1))
|
||||
for i = 1, maxLogLines do
|
||||
local logIdx = i + State.logScrollOffset
|
||||
local entry = State.logs[logIdx]
|
||||
if entry then
|
||||
mon.setCursorPos(1, y + i - 1)
|
||||
mon.setCursorPos(1, logsStartY + i - 1)
|
||||
mon.setTextColor(COLORS[entry.level] or colors.white)
|
||||
mon.write(entry.text:sub(1, w))
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user