Skip to content

feat: add ansi256 color support - #10

Merged
seapagan merged 4 commits into
mainfrom
feat/ansi256-colors
Jul 4, 2026
Merged

feat: add ansi256 color support#10
seapagan merged 4 commits into
mainfrom
feat/ansi256-colors

Conversation

@seapagan

@seapagan seapagan commented Jul 4, 2026

Copy link
Copy Markdown
Owner

Summary

Adds explicit ANSI 256-color support to the styling API.

This includes foreground and background builders for ANSI 256 palette indexes,
plus color256 aliases for callers who prefer that naming. The new color spec
renders through the existing SGR composition path, so named colors, RGB output,
runtime color modes, and NO_COLOR behavior remain unchanged.

The README, crate docs, and basic example now show the ANSI 256 API alongside
the existing color methods.

Summary by CodeRabbit

  • New Features

    • Added ANSI 256 colour support for text styling, including foreground and background colours.
    • Introduced short aliases for the new colour methods.
  • Bug Fixes

    • Improved colour handling so ANSI 256 formatting follows the same runtime behaviour as other colour options.
    • Clarified valid colour index limits and compatibility details.
  • Documentation

    • Updated the README and crate docs with new examples, usage notes, and terminal compatibility information.
  • Tests

    • Expanded test coverage for ANSI 256 output, aliases, chaining, and colour precedence.

seapagan added 2 commits July 4, 2026 14:07
Signed-off-by: Grant Ramsay <seapagan@gmail.com>
Signed-off-by: Grant Ramsay <seapagan@gmail.com>
@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ef3d237f-d26e-4d7d-9470-3e8ca149e212

📥 Commits

Reviewing files that changed from the base of the PR and between 5f9d366 and 0583e1e.

📒 Files selected for processing (6)
  • README.md
  • examples/basic.rs
  • src/color.rs
  • src/lib.rs
  • src/style.rs
  • src/tests.rs

📝 Walkthrough

Walkthrough

This PR adds ANSI 256-colour support to the colored_text crate. ColorSpec gains an Ansi256(u8) variant with corresponding SGR code formatting, StyledText/Colorize gain ansi256/on_ansi256/color256/on_color256 methods, and tests, examples, and documentation are updated accordingly.

Changes

ANSI 256-colour support

Layer / File(s) Summary
ColorSpec Ansi256 variant and code formatting
src/color.rs
Adds Ansi256(u8) variant to ColorSpec and extends foreground_code/background_code to emit 38;5;{index}/48;5;{index} sequences.
StyledText and Colorize ANSI 256 methods
src/style.rs
Adds ansi256, on_ansi256, color256, on_color256 builder methods to StyledText, extends the Colorize trait with matching methods, and implements them via forwarding in the blanket impl<T: Display>.
Test coverage for ANSI 256 styling
src/tests.rs
Adds/extends tests for escape sequences, alias equivalence, clearing, chaining/conflict resolution, colour-mode/no_color behaviour, and ColorSpec formatting.
Examples and documentation updates
examples/basic.rs, README.md, src/lib.rs
Updates the example program and documentation to demonstrate ANSI 256 usage, aliases, index constraints, runtime policy, and terminal compatibility.

Estimated code review effort: 2 (Simple) | ~15 minutes

Possibly related PRs

  • seapagan/colored_text#5: Extends the ColorSpec/foreground_code/background_code machinery and StyledText/Colorize builder APIs introduced by this PR.

Suggested labels: documentation

Poem

A bunny hops through palettes wide,
Two-fifty-six shades, side by side 🎨
Foreground, background, aliases too,
38;5 and 48;5 — a rainbow view!
Tests all pass, docs all shine,
This colourful warren is truly divine. 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately summarises the main change: adding ANSI 256 colour support.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/ansi256-colors

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@seapagan seapagan self-assigned this Jul 4, 2026
@seapagan seapagan added the enhancement New feature or request label Jul 4, 2026
seapagan added 2 commits July 4, 2026 14:30
Signed-off-by: Grant Ramsay <seapagan@gmail.com>
Signed-off-by: Grant Ramsay <seapagan@gmail.com>
@seapagan
seapagan marked this pull request as ready for review July 4, 2026 14:03
@seapagan
seapagan merged commit 9a613a1 into main Jul 4, 2026
2 checks passed
@seapagan
seapagan deleted the feat/ansi256-colors branch July 4, 2026 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant