ScreenStack router for push/pop navigation#87
Merged
Conversation
Type-erased stack of screens (each with its own state, key handler, and view) wired together via a small vtable interface. Distinct from SubProgram (static-typed wrapper for one child model): a ScreenStack holds heterogeneous screens at runtime and supports browser-style push/pop/replace navigation. Screens marked modal are layered on top of the previous screen (centered) — useful for confirm dialogs and command palettes — while non-modal screens hide whatever's beneath. Lifecycle hooks on_enter/on_suspend/on_resume let screens manage per-presentation state.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a screen router so apps can push/pop self-contained screens the way a browser navigates pages. Currently every nontrivial Bubble Tea–style app hand-rolls this — now it's a first-class primitive.
How it differs from SubProgram
`SubProgram` is a static-typed wrapper for one specific child model. `ScreenStack` is a runtime-typed stack of heterogeneous screens — login screen, home screen, modal dialog, command palette can all live in the same stack despite being unrelated types.
API
A `Screen` is a thin vtable: `update(key) -> Action`, `view` returning a string, plus optional `deinit`, `on_enter`, `on_suspend`, `on_resume` lifecycle hooks. Actions returned from `update` are: `none`, `pop`, `push(screen)`, `replace(screen)`, `quit`.
`ScreenStack` exposes `push`, `pop`, `replace`, `top`, `depth`, `handleKey`, `view`. Modal screens are rendered centered on top of the screen below; non-modal screens hide whatever's beneath.
Usage
```zig
var stack = zz.ScreenStack.init(allocator);
defer stack.deinit();
try stack.push(login_screen);
// In top-level update:
switch (try stack.handleKey(&ctx, key)) {
.quit => return .quit,
else => {},
}
// In top-level view:
return try stack.view(&ctx, allocator);
```
Test plan