Skip to content

[Feature] Add extended color support (True Color & 256‑color) with rgb / hex / color256 #6

@razbuild

Description

@razbuild

Feature request

Currently RazTint only supports the 16 standard ANSI colors. Add optional, zero‑dependency support for extended colors: 24‑bit True Color and 256‑color mode via raw ANSI escape sequences.

Proposed API

from raztint import rgb, hex_color, color256
from raztint import bg_rgb, bg_hex_color, bg_color256

# True Color foreground
print(rgb("This is orange text", 255, 100, 50))
print(hex_color("Same orange via hex", "#FF6432"))

# True Color background
print(bg_rgb("Orange background", 255, 100, 50))

# 256-color
print(color256("Orange via 256 palette", 208))
print(bg_color256("Background 256", 208))

# Seamless composition with existing styles
print(bold(rgb("Bold green text", 0, 200, 0)))
print(rgb(bg_color256("White text on orange bg", 208), 255, 255, 255))

Acceptance criteria

  • Zero dependencies – only stdlib escape codes

  • All new functions follow the pattern func(text, *color_params) → str

  • ANSI sequences: \033[38;2;R;G;Bm (foreground), \033[48;2;R;G;Bm (background)

  • 256‑color: \033[38;5;INDEXm / \033[48;5;INDEXm

  • Respect NO_COLOR, RAZTINT_FORCE_COLOR, and terminal detection

  • Works with existing styling functions (bold, underline, etc.)

  • Backward compatible – doesn’t break red(), bg_blue(), etc.

  • Background color resets use \033[49m to preserve foreground styles

  • Unit tests for each new function

  • README updated with an “Extended Colors” section

  • New code passes project tooling: black src tests, ruff check src tests, and ty check src

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions