Expand description
Shared termination/intent model for mecha10 dev’s interactive TUI screens.
Before this module existed, “what does this key mean” was answered independently by every
screen that owned terminal input: the outer dev-mode loop (ops/interactive.rs) had its own
is_dev_quit_key, the teleop sub-screen (ui/teleop.rs) had its own is_quit_all_key plus a
separate zero-velocity x/Space branch, and three more call sites each registered their own
ctrlc::set_handler. Because those handlers didn’t compose, the same physical key (x) meant
two unrelated things depending on which screen happened to own input at the time: “stop the
simulation” at the outer dev-mode menu, or “zero velocity, stay put” inside teleop. A user who
pressed s (enter simulation, which auto-opens teleop) then x got the second meaning and
nothing stopped - the reported bug this module fixes.
classify_key gives every screen the same answer for “what does this key mean”, and
ScreenOutcome lets a nested screen (teleop) report what happened without needing to know
about the outer loop’s own shutdown flag - the translation from “screen backed out” to “what
that means for this caller” belongs to the caller (see ops/teleop.rs::enter_teleop_mode),
not to the screen itself.
install_quit_signal replaces the four independent, copy-pasted ctrlc::set_handler
registrations (ops/interactive.rs, ops/lifecycle.rs::run_watch_mode,
handlers/logs.rs::follow_logs, plus what used to be ui/teleop.rs’s own Ctrl+C handling
before it was folded into classify_key) with one shared helper.
Enums§
- Screen
Outcome - What a nested screen’s event loop did, for its caller to interpret. A screen that owns its own
sub-context (e.g.
TeleopUi) should never mutate the outer loop’s shutdown flag directly - it reports what happened here, and lets the caller (which knows how it was entered) decide what that means. Seeops/teleop.rs::enter_teleop_mode, which interpretsReturnToParentdifferently depending on whether it was entered via's'(simulation hand-off, so backing out means “stop the simulation and return to the dev-mode menu”) or't'(standalone teleop, so backing out just closes the screen). - Termination
Intent - What a termination-shaped key (“stop the current thing” or “quit everything”) means.
Functions§
- classify_
key - Classify a key event into a
TerminationIntent, if it is one. Pure, dependency-free function so it’s unit testable without a live terminal/event loop. - install_
quit_ signal - Install a single process-wide Ctrl+C handler and return the shared “keep running” flag it
clears on signal. Replaces the four independent, copy-pasted
ctrlc::set_handlerregistrations that used to exist acrossops/interactive.rs,ops/lifecycle.rs, andhandlers/logs.rs.