Repository navigation
Conversation
Co-authored-by: nev21 <82737406+nev21@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add parser that resolves ANSI SGR codes into styled text runs
Add Oct 27, 2026
parseAnsiStyles to resolve ANSI SGR codes into styled text runs
nev21
requested changes
Oct 28, 2026
Co-authored-by: nev21 <82737406+nev21@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #279 +/- ##
===========================================
- Coverage 89.86% 49.92% -39.94%
===========================================
Files 23 27 +4
Lines 513 709 +196
Branches 138 213 +75
===========================================
- Hits 461 354 -107
- Misses 52 355 +303
🚀 New features to boost your workflow:
|
nev21
reviewed
Oct 28, 2026
|
|
||
| function _copy<T extends object>(src: T): T { | ||
| const result: any = {}; | ||
| Object.keys(src).forEach((k) => { |
Contributor
There was a problem hiding this comment.
@copilot, you should be using the ts-utils helpers for ALL of these
Contributor
|
Taking over and implementing a fuller solution |
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.
chromacon can locate escape sequences but not say what they do, so consumers rendering coloured output outside a terminal (HTML log panels, SVG, reports) each write their own SGR interpreter. This adds a parser that resolves SGR codes into styled runs, plus supporting helpers.
parseAnsiStyles(value, state?)(ansi/parseAnsiStyles.ts)38;5;nwithn < 16is reported asbasic. Malformed or out-of-range colours are ignored.\x9b, drops non-SGR sequences, and exposes OSC 8 asstyle.link.stateis cloned, not mutated.createAnsiStyleParser()is a statefulpush(chunk)/state()wrapper for line-at-a-time input.ansi/ansiColors.ts):ansi256ToRgb(xterm 6×6×6 cube and greyscale ramp, with an overridable 0–15 palette),ansiColorToCss, andDEFAULT_ANSI_PALETTE.getSgrName(code)(ansi/sgrCodes.ts) gives a runtime lookup of SGR code names.CSIColorsstays aconst enum. The names are newly chosen (e.g.fgRed,bgBrightBlue), so reviewers may want to weigh in on them.ansiToHtml(value, options?)(ansi/ansiToHtml.ts) is a separate module for tree-shaking.ansi-prefix by default) or inline-style spans.<a rel="noopener noreferrer">. Links can be disabled, andjavascript:,data:andvbscript:URLs are never emitted as links.index.ts. The implementation avoids object spread and adds no new dependencies, to stay ES5-friendly.test/src/ansi/parseAnsiStyles.test.tscover the issue's test table plus the helpers,getSgrName, the stateful parser andansiToHtml.Not done:
CHANGELIST.mdentry.corehas no installed dependencies in this environment.