Multi-backend console formatter: ANSI + CSS, semantic palette#129
Draft
DmitrySharabin wants to merge 27 commits intomainfrom
Draft
Multi-backend console formatter: ANSI + CSS, semantic palette#129DmitrySharabin wants to merge 27 commits intomainfrom
DmitrySharabin wants to merge 27 commits intomainfrom
Conversation
- Flatten c/bg symmetry via isColor/isBg + single stack selector. - Rename foregroundStack/backgroundStack → colorStack/bgStack. - Use findLast(Boolean) idiom over findLast(hex => hex). - Merge defaultMode into detectMode; env default keys off IS_NODEJS so browser short-circuits to "truecolor" without a wrapper. - Cache detectedMode at module load. - Drop asymmetric empty-string early return; let tokenize handle str ?? "". - Drop WHAT comments; add WHY notes on cubeLevels, null push, replay, detectMode caching.
Replace `format(str, { css, mode })` with `format(str, mode)`. Modes:
"truecolor" | "256" | "strip" | "css". Browser detection falls back to
"css" instead of "truecolor".
Updates env/console.js and tests to match. render.js and env/node.js
use defaults — unchanged.
- Chunk bg: red/green → diff-removed-emph/diff-added-emph.
- Line bg: single neutral lightblack → side-specific diff-removed/diff-added.
- Import path: ../format-console.js → ./format-console.js (sibling in src/util/).
- sides config: color → { chunk, line }; colorize reads both.
Two-tier semantic palette:
- pass/fail/skip/message — solid variant.
- pass-tint/fail-tint/skip-tint/message-tint — muted variant for
secondary text (test names, etc.).
Rename diff-added-emph/diff-removed-emph → diff-added-tint/diff-removed-tint
for consistency with the new suffix.
TestResult.js:
- Badge bg uses <bg pass|skip|fail>; label uses <c text> (passes WCAG
on all three bg colors).
- Test name uses <c \${color}-tint>.
- Summary: <c green>/<c red> → <c pass>/<c fail>.
- Messages header: <c yellow> → <c message>.
SKIP badge color changes from yellow to gray (skip = #a0a8b4).
✅ Deploy Preview for h-test ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
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
src/format-console.jswith tokenizer + two emitters: ANSI (Node terminal; truecolor / 256 / strip) and CSS (browser%cstyling, cross-engine).src/util/palette.jsas single source of truth — base 16 ANSI-named colors + semantic tokens.TestResult,env/node,env/console,render, andformat-diffto semantic tokens.chalkdevDependency.Closes #30.
What changed
src/util/format-console.js(moved fromsrc/, rewritten)New API:
"css"; Node auto-detects via env (NO_COLOR/FORCE_COLOR/COLORTERM/TERM).string; CSS backend returns[text, ...styles]to spread intoconsole.log.<c NAME>/<bg NAME>whereNAMEis a palette token (semantic or base) or hex literal (#rgbor#rrggbb).src/util/palette.js(new)Two-tier semantic system:
pass/fail/skip/message/highlight/textpass-tint/fail-tint/skip-tint/message-tint(muted variants for secondary text)diff-added/diff-added-tint/diff-removed/diff-removed-tint/gutterAll values hex-authored. No runtime conversion. Readable in both light and dark terminals.
Caller migration
TestResult.js<bg pass|skip|fail><c text>. Names:<c ${color}-tint>. Summary:<c pass>/<c fail>. Messages header:<c message>.env/node.js<c highlight>.env/console.jsformat(str, "css")spread intoconsole.log/group*.render.jsformat-diff.js(from #127)diff-{added|removed}-tint. Line bg: side-specificdiff-{added|removed}.Browser support
Previous code emitted ANSI escape codes into browser
console.log. Chrome rendered them; Firefox and Safari printed literal\x1b[…. CSS backend works in all three engines via%c.Non-goals
Test plan
npm testpasses (self-hosted suite).npm run eslintclean.npm run devand a failing-test details click — styled output, no raw escapes, no visible%c.🤖 Generated with Claude Code