Clean up train rendering traits - #108
Merged
Merged
Conversation
Split terminal dimensions from drawing in libsl, add a fallible render target API, and adapt the CLI and WASM wrappers to the cleaner Rust boundary while preserving behavior. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR refactors libsl’s rendering interface to separate screen geometry, render options, and drawing/error handling so both the CLI terminal adapter and the WASM adapter can use a more natural core API.
Changes:
- Replaces the old
Display/Optionstraits withScreenSize,TrainOptions,RenderTarget, andRenderError, and updates train entrypoints accordingly. - Updates core rendering helpers (
mvaddstr,add_train, smoke/man helpers) to take explicit screen dimensions and propagate target draw failures. - Adapts the CLI and WASM bindings to the new API and adds focused
libsltests for clipping/offscreen/error propagation.
Show a summary per file
| File | Description |
|---|---|
| libraries/websl/src/lib.rs | Updates WASM bindings to the new RenderTarget + ScreenSize/TrainOptions API and maps core errors into JS-visible outcomes. |
| libraries/libsl/src/mvaddstr.rs | Refactors clipping/drawing helper to take ScreenSize + RenderTarget and return target errors; adds unit tests. |
| libraries/libsl/src/logo.rs | Updates logo train entrypoint signature to the new rendering API types. |
| libraries/libsl/src/lib.rs | Introduces ScreenSize, TrainOptions, RenderTarget, and RenderError as the new public core rendering surface. |
| libraries/libsl/src/d51.rs | Updates D51 entrypoint to new API and adds an offscreen regression test. |
| libraries/libsl/src/c51.rs | Updates C51 entrypoint to new API. |
| libraries/libsl/src/add_train.rs | Refactors the main renderer loop to accept screen/options separately and propagate RenderTarget failures. |
| libraries/libsl/src/add_smoke.rs | Updates smoke helper to use RenderTarget and return errors instead of swallowing failures. |
| libraries/libsl/src/add_man.rs | Updates “man” helper to use RenderTarget and return errors instead of swallowing failures. |
| apps/sl/src/main.rs | Adapts the CLI renderer to RenderTarget and properly distinguishes offscreen completion vs target I/O errors. |
Copilot's findings
- Files reviewed: 10/10 changed files
- Comments generated: 3
Document that false means offscreen completion while render-target failures are thrown as JavaScript exceptions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
The train renderer supported both real terminals and the web terminal through a combined display trait, but that made the boundary feel awkward: geometry, drawing, and failure handling were all tied together. This PR separates those concerns so the core renderer has a more natural API for both adapters.
Summary
Display/Optionstraits with explicitScreenSize,TrainOptions,RenderTarget, andRenderErrortypes.libslrendering helpers and train entrypoints to pass dimensions separately and propagate render-target failures instead of requiring adapter-level unwraps.libsltests for clipping, offscreen completion, and target error propagation.Validation
cargo fmt --allcargo test --workspacebun run test:webslbun run build:webslbun run typecheck:pagebun run test:pagecargo run -p sl -- --help