core/diff: per-kind line-number fg + side-targeted line color API#1013
Draft
kitlangton wants to merge 3 commits into
Draft
core/diff: per-kind line-number fg + side-targeted line color API#1013kitlangton wants to merge 3 commits into
kitlangton wants to merge 3 commits into
Conversation
Adds three diff-level options (addedLineNumberFg, removedLineNumberFg,
contextLineNumberFg) so the gutter digits can be tinted per line kind
instead of being stuck at one color, and threads a new fg field through
LineColorConfig so manual setLineColor() callers can do the same.
The diff-level setLineColor / clearLineColor / setLineColors /
clearAllLineColors / highlightLines / clearHighlightLines methods now
take an optional side ("left" | "right" | "both", default "both"),
giving consumers a public way to target one half of a split view
without reaching into the private leftSide/rightSide fields.
Per-review cleanup. Three small helpers replace pasted blocks:
- buildLineConfig(kind) collapses the six near-identical
{ gutter, content, fg } construction sites in the unified and
split builders into one place.
- forSide(side, fn) collapses the six side-filtered pass-through
methods (setLineColor / clearLineColor / setLineColors /
clearAllLineColors / highlightLines / clearHighlightLines).
- isLineColorConfig(value) replaces the inline triple-condition
discriminator in parseLineColor.
Net effect: smaller diff and a single source of truth for the
per-kind config shape — adding another LineColorConfig field in
the future means touching one helper instead of six call sites.
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
Two small additions to the diff renderer, both motivated by real consumer pain:
1. Per-kind line-number foreground colors
Today every line-number digit in the gutter is painted with one
lineNumberFg(default#888), even on+/−rows where the sign glyph is already tinted green/red. This adds three optional overrides:addedLineNumberFgremovedLineNumberFgcontextLineNumberFgEach defaults to undefined (existing
lineNumberFgremains the umbrella default), so behavior is unchanged unless a consumer opts in.Underneath,
LineColorConfig(the per-line override shape used byLineNumberRenderable) gains an optionalfg?: string | RGBAso manualsetLineColor()callers can also set the digit color, not just background.2. Side-targeted line color API
The diff-level methods that paint individual lines now accept an optional
sideparameter:Default is
"both", so existing callers are byte-identical. New capability is"left"/"right"for split-view consumers — e.g. ghui, which currently has to dodiff as unknown as DiffRenderableRuntimeSidesand reach into the privateleftSide/rightSidefields to highlight a single side for a PR comment anchor. With this PR, that hack collapses to a single public call.Test plan
tsc --noEmitis clean for the modified files; pre-existing errors in unrelated tests/dev files remain unchanged)bun run test src/renderables/Diff.test.ts src/renderables/__tests__/LineNumberRenderable.test.ts— could not run locally; my checkout's prebuilt@opentui/core-darwin-arm64is missing thesetClearOnShutdownsymbol added in recentmain, and a from-source rebuild fails with libc symbol errors (Zig 0.15.2 toolchain mismatch). Both predate this PR; CI / a freshbun installshould be fine.packages/examples/src/diff-demo.tswith the new options set, confirming digits in the+/−rows pick up their tinted colors and thatsetLineColor(..., "left")only paints the left side in split view.Marking as draft pending those last two checks.