Repository navigation
refactor(render): colors in colors.rs, escape codes and sanitize in printer.rs - #1889
Merged
Merged
Conversation
…writing in printer.rs
`Style` names everything that can be colored, as the command line names it:
the six parts of --text-colors, the `{n}` parts of the ascii art
(`Ascii(n)`, for --ascii-colors), and the fixed colors of the language chips
and the palette row.
- colors.rs: `Colors` says what each `Style` looks like (language,
--ascii-language, --ascii-colors, --text-colors, --true-color, --no-bold),
and `chip_color` picks the language chips' colors. It is the only file
that picks colors.
- printer.rs: the only place that writes escape codes, so it sanitizes
everything it prints, the ascii art included.
- ascii.rs (was logo.rs): returns lines styled `Ascii(n)` instead of writing
its own escape codes.
- info.rs (was lines.rs): the info lines.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
o2sh
force-pushed
the
refactor/render-layers
branch
from
October 15, 2026 21:46
f94fb18 to
4ae0c19
Compare
`data` and `render` read their options whichever file defines them, so defining `InfoOptions` in data/mod.rs and `RenderOptions` in render/mod.rs kept no dependency out. options.rs now holds both structs, the defaults the command line uses, and how `Cli` fills them in. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This reverts commit 802fda3. With the structs in options.rs, `data` and `render` imported `options`, which imports `cli`, which imports `data` and `render` types: a loop. Defining each stage's options in the stage keeps the dependencies one way: cli -> options -> {data, render}. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s every color `Style::Color` and `Style::Background` carried finished colors, so the languages field picked chip colors itself (reading `true_color`) and info.rs looped over the palette. `Style::Chip`, `Style::ChipBar` and `Style::Palette` say which language or palette entry a segment is, and `Colors` resolves them. `Style` holds no colors anymore. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The image path pads the info with the same `center_pad()` segment as the ascii path, before painting. - printer.rs module doc: "ascii art or image", not "logo". - `Style::Ascii`: documents the fallback to the default color. - colors.rs decides bold as well as color; the docs say so. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…geBar - `Style::Ascii` -> `Style::AsciiLogo` - `Style::Chip` -> `Style::LanguageChip` - `Style::ChipBar` -> `Style::LanguageBar` - the struct both language styles carry, `Chip` -> `LanguageColor` Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…uageEntry Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…color The color of a `LanguageEntry` is used for the languages bar as well as the chip, so `Colors::chip_color` is now `language_color`, and the field, test helpers and bindings holding a `LanguageEntry` are named `entry`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch was successfully deployed
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.
Follow-up to #1888. On
main, color and escape-code logic was spread acrossrender:style::renderfor the info lines, andlogo.rs, which wrote its own escape codes and skippedsanitize.printer.rscombinedget_ascii_colorsandTextColorsby hand, withno_boldpassed alongside.fields/languages.rs.Design
Stylenames everything that can be colored, as the command line names it: the six parts of--text-colors(Title,Tilde,Underline,Key,Separator,Value), the{n}parts of the ascii art (AsciiArt(n), for--ascii-colors), the language chips and the languages bar (LanguageChip,LanguageBar), and the palette row (Palette(n)). It holds no colors.colors.rsdecides how eachStylelooks: its color, from the language,--ascii-language,--ascii-colors,--text-colorsand--true-color, and whether it is bold (--no-bold). The rest ofrenderonly says whichStylea piece of text has.printer.rswrites escape codes (apart from the image protocols), so it sanitizes everything it prints, the ascii art included.ARCHITECTURE.mddescribes this layout and the two rules.Options
InfoOptionsandRenderOptionsstay where they are onmain, indata/mod.rsandrender/mod.rs. This branch briefly moved them intooptions.rs(802fda3), but that made a loop:dataandrenderimportedoptions, which importscli, which importsdataandrendertypes. da7dfc8 reverts it.Behavior
The visible output is the same as
main. Two differences in the bytes written:\e[…m\e[0m) before each{n}token.--ascii-inputnow goes throughsanitizelike all other text, so control characters in it (tabs, escape codes) show as�. None of the built-in ascii art contains control characters.Testing
cargo fmt,cargo clippy --all-targets: clean.cargo test: 155 unit tests, 12 integration tests and the doc test pass. New tests coverColors::style(including the chip and palette styles), the chip colors,paint,sanitizeandascii_beside_info. The ascii tests now checkLines.mainand this branch on two repos (onefetch, and a repo whose manifest description contains an OSC escape sequence). I used 18 flag sets: default,--no-bold,-c,-t(full and partial),--true-color always/never,--ascii-language(alone and with--no-bold -c),--ascii-input(with and without{n}tokens),--no-art,--nerd-fonts,--no-color-palette,--no-title,--number-of-languages,-o jsonand-o yaml.�.🤖 Generated with Claude Code