ui: shared layout primitives, no dependencies - #388
Merged
Conversation
Adds table, panel, gauge and the measuring helpers (strip/visible/pad/ clip) to src/ui.mjs, and moves sparkline there out of crypto.mjs. The shapes are lifted from the TermUI registry, which is React + Ink and so not installable here: moshcode has zero runtime dependencies and install.sh untars a release and runs node with no npm install in the path, the same constraint that kept node-pty out of pty.mjs. The ideas are a few lines of string arithmetic each, so they are reimplemented rather than depended on. Three modules had each grown a private copy of visible/pad — games.mjs, rss-ui.mjs and the herd-ui test — and advisor.mjs and crypto.mjs had identical copies of clip. All now share one implementation. clip is newly colour-aware: cutting a painted string with slice can drop the reset that ends a colour run, and a terminal never told to stop stays that colour for everything printed afterwards. renderRoster is converted as the first caller. It was padding a coloured state cell to a fixed width by hand-correcting for the length of its own escape codes, and pinning cwd at 24 columns whether the paths were 8 or 60. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
ThreatCrush Security Scan97 finding(s) HIGH/CRITICAL: 5 | MEDIUM: 41 | LOW: 51
…and 47 more. Full results in the Security tab. Snippets are redacted; ThreatCrush never prints matched credential material. |
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.
Answers "can we use TermUI to pretty up the CLI?" — not as a dependency, but the ideas port cleanly.
TermUI is a shadcn-style registry of React + Ink components. moshcode has zero runtime dependencies, and
install.shuntars a release and runsnodewith nonpm installanywhere in the path — the same constraint documented insrc/pty.mjsfor whynode-ptywas rejected in favour ofscript(1). Adding React + Ink (plus a TypeScript build for the.tsx, in an all-.mjscodebase) would break the primary install path. The components are a few lines of string arithmetic each, so they are reimplemented instead.What this adds to
src/ui.mjsstrip/visible/pad/clip— measuring and padding in printable columnstable— columns sized to their contents, alignment,maxwith a "… n more" footerpanel— a box sized to its body, title set into the top edgesparkline— moved here fromcrypto.mjs, unchangedgauge— a horizontal meter, clamped at both endsWhat it removes
Three modules had each grown a private copy of
visible/pad(games.mjs,rss-ui.mjs, and the herd-ui test), andadvisor.mjsandcrypto.mjsheld identical copies ofclip. They now share one implementation. Existing export names (games.strip,games.visible,rss-ui.visibleWidth,crypto.sparkline) are preserved as re-exports, so no caller or test changed.Two real fixes fell out
clipis now colour-aware. Cutting a painted string withslicecan land inside an escape sequence or drop the reset that closes a colour run — and a terminal never told to stop keeps that colour for everything printed afterwards, including the next command's output.renderRosterno longer hand-corrects for ANSI width. It was padding the state cell to a fixed 9 by adding the length of its own escape codes, and pinningcwdat 24 columns whether the paths were 8 or 60. It is now atablecall.Verification
node --test: 1924 tests, 0 failing (1893 before; 31 new intest/ui.test.mjs).package.jsonis untouched — still zero runtime dependencies.🤖 Generated with Claude Code