Skip to content

feat: support shorthand hex colors#7

Merged
seapagan merged 1 commit intomainfrom
feat/shorthand-hex-support
Apr 4, 2026
Merged

feat: support shorthand hex colors#7
seapagan merged 1 commit intomainfrom
feat/shorthand-hex-support

Conversation

@seapagan
Copy link
Copy Markdown
Owner

@seapagan seapagan commented Apr 4, 2026

Summary

This PR adds support for 3-character shorthand hex colors in colored_text.

hex_to_rgb now accepts both the existing 6-digit forms and shorthand #rgb / rgb, expanding shorthand to the equivalent 6-digit color before parsing. Invalid lengths and malformed input continue to fall back to plain text.

The PR also updates crate docs, README examples, and examples/basic.rs to show equivalent hex forms, and removes the completed shorthand-hex item from TODO.md.

Summary by CodeRabbit

Release Notes

  • New Features

    • Hex colour input now supports 3-digit shorthand formats (e.g., #f80) in addition to 6-digit formats.
    • Hex codes may now be provided with or without the leading # prefix.
  • Documentation

    • Updated documentation and examples to reflect expanded hex colour format support.

Signed-off-by: Grant Ramsay <seapagan@gmail.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 4, 2026

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: 25acf9da-7cbd-4ee6-974d-c0027caf5bd4

📥 Commits

Reviewing files that changed from the base of the PR and between 37e8917 and 1ecfc80.

📒 Files selected for processing (6)
  • README.md
  • TODO.md
  • examples/basic.rs
  • src/color.rs
  • src/lib.rs
  • src/tests.rs
💤 Files with no reviewable changes (1)
  • TODO.md

📝 Walkthrough

Walkthrough

The pull request extends hex colour input support to accept 3-character shorthand formats (e.g., #f80) alongside the existing 6-character form. Updates include the hex_to_rgb function, documentation, tests, and examples.

Changes

Cohort / File(s) Summary
Documentation Updates
README.md, src/lib.rs
Expanded documentation to specify that .hex(code) accepts both #-prefixed and non-prefixed forms in 3-character shorthand or 6-character full formats. Updated examples to include valid shorthand ("#f80") and changed invalid examples from too-short to wrong-length inputs.
Core Implementation
src/color.rs
Modified hex_to_rgb to accept both 3-digit and 6-digit hex strings by expanding 3-character inputs (duplicating each hex character) before parsing RGB values. Previous strict length check replaced with conditional branching.
Examples & Tests
examples/basic.rs, src/tests.rs
Added four new println! examples demonstrating hex parsing without # prefix and 3-digit shorthand forms. Expanded test coverage in test_rgb_colors, test_hex_colors, and test_invalid_hex_returns_plain_text with shorthand and invalid-length cases.
Cleanup
TODO.md
Removed completed TODO item for 3-character shorthand hex colour support.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 ✨ Hooray for hex so short and sweet!
Three digits now make colours complete,
#f80 shines bright with duplicated cheer,
Shorthand formats hopping far and near! 🎨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: support shorthand hex colors' accurately and concisely summarizes the main change—adding support for 3-character shorthand hex color formats across the crate.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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/shorthand-hex-support

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 and usage tips.

@seapagan seapagan self-assigned this Apr 4, 2026
@seapagan seapagan added the enhancement New feature or request label Apr 4, 2026
@seapagan seapagan merged commit a92f925 into main Apr 4, 2026
2 checks passed
@seapagan seapagan deleted the feat/shorthand-hex-support branch April 4, 2026 14:25
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