Files
slate32/test/statusbar_dirty.lua
T
evan 1adf121dc6 feat(nav)!: own routing in Lua now that the runtime only carries arguments
sys.startApp(path, args) tears the runtime down and starts over from a
file, and keeps nothing else: no history, no title, no app identity. All
of that can ride in the arguments, so it does, and sdcard/.lua/lib/nav.lua
is the single writer of that table.

nav owns the back stack, the bar's title and /.lua/data/<AppId>, which
means the launcher, what "back" reaches and how deep a route nests are
editable on the card rather than in a reflash. Apps call nav.launch,
nav.replace and nav.back; sys.startApp has one caller.

Boot passes no arguments at all, which is how main.lua tells a cold start
from a navigation and opens its own launcher, replacing the home field the
runtime used to read. Arguments cross as JSON, so history is a list of
tables rather than a packed string, and an app passing something JSON
cannot carry sees the error at its own nav call.
2026-08-05 17:04:49 -04:00

78 lines
2.9 KiB
Lua

-- Run: lua test/statusbar_dirty.lua
-- The bar is part of the tree, so a tick has to repaint the field that changed and leave
-- the rest of the screen alone. The clock is pinned unsynced so its text is constant and
-- every other field can be steered on its own.
package.path = "sdcard/.lua/lib/?.lua;test/?.lua;" .. package.path
local device = require("fake_device").install()
local ui = require "ui"
local nav = require "nav"
local statusbar = require "statusbar"
device.clockSynced = false
-- History is the arguments this state was started with, so a route to go back to is
-- stated the way main.lua would have received it.
nav.start { app = "Settings", history = { { app = "Home" } } }
-- What main.lua builds, minus the app: chrome above, whatever is left below.
local function screen()
if not statusbar.isVisible() then
return ui.box { w = "fill", h = "fill" }
end
return ui.box { w = "fill", h = "fill", statusbar.node(), ui.box { w = "fill", h = "fill" } }
end
ui.mount(screen)
local built = tree.getCount()
assert(device.labelled "--:--:--", "the bar built no clock")
assert(device.labelled "117kB", "the bar built no memory slot")
assert(device.labelled(nav.getTitle()), "the bar built no title")
local function tick()
device.invalidated = {}
statusbar.tick()
return #device.invalidated
end
assert(tick() == 0, "an unchanged bar repaints nothing")
device.freeHeap = device.freeHeap - 32000
assert(tick() == 1, "only the memory slot repaints")
assert(device.labelled "148kB", "the memory slot kept its old text")
assert(tree.getCount() == built, "a field update rebuilt the screen")
device.status = { state = "connected", ssid = "x", ip = "", rssi = -50 }
assert(tick() == 1, "the signal strength repaints the icon and nothing else")
assert(tick() == 0, "and settles again afterwards")
-- A longer title needs a wider box, which only a rebuild can give it.
nav.setTitle "settings - wifi"
statusbar.tick()
assert(device.labelled "settings - wifi", "a renamed app did not reach the bar")
assert(tick() == 0, "and settles again afterwards")
-- The back control is offered only when there is somewhere to go back to. It carries no
-- label, so it is counted as what it is: the one thing in the bar a finger can press.
local function pressable()
local count = 0
for _, entry in ipairs(device.nodes) do
if entry.interactive then
count = count + 1
end
end
return count
end
assert(pressable() == 1, "the bar offered no back control with history behind it")
nav.start { app = "Settings" }
ui.rebuild()
assert(pressable() == 0, "the bar offered back with no history behind it")
-- Fullscreen is chrome choosing not to build itself, so the app's node is the whole tree.
statusbar.setFullscreen(true)
assert(not device.labelled "--:--:--", "the bar survived fullscreen")
statusbar.setFullscreen(false)
assert(device.labelled "--:--:--", "the bar did not come back")
print "ok"