💡 Targeted SGR channel resets instead of a blanket reset

Open Beginner friendly
#61 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Quiet
Tech stack
c, typescript
Domain
cli, performance

Research direction

Start with src/clayterm.c:90 in emit_attr, especially the blanket reset at :95 and foreground/background emission at :114/:125. Run test/targeted-sgr-resets.test.ts or inspect the linked repro to establish the current output. Done means changed channels use targeted default resets, unchanged channels remain intact, and the test passes.

Written by the indexing model from the issue text.

Description

enhancement

Is your feature request related to a problem?

On every attribute change, the renderer tears down all SGR state with a blanket \x1b[0m before re-emitting, instead of resetting only the channel that changed (fg vs bg). A red-background cell followed by a default cell generates ...\x1b[48;2;255;0;0mA\x1b[0m... rather than a clean \x1b[49m, resulting in more bytes to process and unnecessary broken foreground sections.

Describe the solution you'd like

Diff the previous and current cell per channel and emit targeted resets when that channel actually changes: \x1b[39m to return the foreground to default, \x1b[49m for the background. Unchanged channels should remain intact across the run. The visible result is identical; the output is smaller and color runs stay continuous.

Describe alternatives you've considered

Keeping the blanket reset and trimming elsewhere doesn't help—the reset is exactly what forces the re-emit. The per-channel diff has to live in emit_attr, alongside the lastfg/lastbg state it already tracks.

Additional context

Failing test case on nm/repro/targeted-sgr-resets (test · diff).

The change likely lives in emit_attr (src/clayterm.c:90)—the blanket reset at :95, foreground/background emit at :114/:125.

Dominant language
TypeScript
Stars
42
Forks
2
Avg merge
2d 5h
Merged PRs (30d)
12

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from bombshell-dev/tty

All issues in bombshell-dev/tty

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.