refactor(cli): unify terminal presentation with semantic spans#56
Open
francoischalifour wants to merge 5 commits into
Open
refactor(cli): unify terminal presentation with semantic spans#56francoischalifour wants to merge 5 commits into
francoischalifour wants to merge 5 commits into
Conversation
3e7ae2c to
e1e7298
Compare
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.
Context
CLI presentation had grown around terminal-specific formatting helpers. Views and feature code could produce already-styled strings, raw ANSI sequences, links, and table-specific styling instructions before output reached the terminal renderer.
That created several related problems:
The result was harder to reason about than necessary: feature code knew too much about terminal mechanics, while the renderer did not consistently own sanitization, styling, hyperlink behavior, measurement, and truncation.
Solution
Introduce one small semantic presentation model and make the terminal renderer the single boundary that converts it into terminal output.
A display value is now either plain text or a sequence of spans containing:
textStyles describe intent—such as
strong,muted,accent,success,warning,error, data types, headings, and HTTP methods—without embedding ANSI sequences in views.Documents, rows, tables, text blocks, and trees carry these semantic values until rendering. The terminal renderer then owns the concrete ANSI colors, OSC hyperlinks, sanitization, visible-width calculation, padding, and truncation.
This deliberately does not widen the general output sink or introduce a second rendering framework. Semantic values exist only where presentation needs them, and the existing document and terminal rendering path remains the output boundary.
What changed
Semantic presentation
DisplaySpan/DisplayTextrepresentation for styled text and links.Terminal safety
All display text now passes through the terminal renderer before emission.
The renderer:
label (URL)rather than only the label.This establishes one presentation boundary for values originating from API responses, profiles, catalogs, queries, errors, and link targets.
Correct terminal layout
Visible-width handling is now shared by table and query rendering instead of mixing terminal width with JavaScript
.length,.slice(), or.padEnd().Measurement and truncation now account for:
Truncation operates on grapheme clusters, so it does not split joined emoji or other user-perceived characters. Query tables and expanded labels use visible width for truncation and padding, keeping their frames aligned for non-ASCII content.
Result
Feature code now declares presentation intent, while the terminal renderer exclusively handles terminal mechanics.
There are no remaining legacy styling helpers, raw ANSI generators, or old table-style fields in
cli/src. The resulting path is:This reduces the number of presentation concepts, makes terminal behavior consistent, and provides a single place to enforce safety and display-width correctness.