CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-hues

Colored terminal text made easy for Python and happiness.

Pending
Overview
Eval results
Files

color-constants.mddocs/

Color and Style Constants

ANSI color code constants and keyword mappings for direct access to escape sequence values. These constants provide the low-level codes used by HueString and console classes to generate colored terminal output.

Capabilities

Foreground Color Constants

Standard ANSI foreground colors (codes 30-37).

FG: namedtuple
"""
Foreground color constants.

Fields:
    black (int): 30
    red (int): 31
    green (int): 32
    yellow (int): 33
    blue (int): 34
    magenta (int): 35
    cyan (int): 36
    white (int): 37
"""

Usage:

from hues.colortable import FG

print(FG.red)      # 31
print(FG.green)    # 32
print(FG.blue)     # 34

Background Color Constants

Standard ANSI background colors (codes 40-47).

BG: namedtuple
"""
Background color constants.

Fields:
    black (int): 40
    red (int): 41
    green (int): 42
    yellow (int): 43
    blue (int): 44
    magenta (int): 45
    cyan (int): 46
    white (int): 47
"""

Usage:

from hues.colortable import BG

print(BG.black)    # 40
print(BG.white)    # 47

High Intensity Foreground Colors

Bright/high intensity foreground colors (codes 90-97).

HI_FG: namedtuple
"""
High intensity foreground color constants.

Fields:
    black (int): 90
    red (int): 91
    green (int): 92
    yellow (int): 93
    blue (int): 94
    magenta (int): 95
    cyan (int): 96
    white (int): 97
"""

Usage:

from hues.colortable import HI_FG

print(HI_FG.red)    # 91
print(HI_FG.green)  # 92

High Intensity Background Colors

Bright/high intensity background colors (codes 100-107).

HI_BG: namedtuple
"""
High intensity background color constants.

Fields:
    black (int): 100
    red (int): 101
    green (int): 102
    yellow (int): 103
    blue (int): 104
    magenta (int): 105
    cyan (int): 106
    white (int): 107
"""

Usage:

from hues.colortable import HI_BG

print(HI_BG.red)     # 101
print(HI_BG.yellow)  # 103

Style Constants

Text style and formatting codes.

STYLE: namedtuple
"""
Text style constants.

Fields:
    reset (int): 0 - Reset all formatting
    bold (int): 1 - Bold text
    italic (int): 3 - Italic text
    underline (int): 4 - Underlined text
    defaultfg (int): 39 - Default foreground color
    defaultbg (int): 49 - Default background color
"""

Usage:

from hues.colortable import STYLE

print(STYLE.bold)      # 1
print(STYLE.italic)    # 3
print(STYLE.reset)     # 0

Unified Keyword Mapping

Combined mapping of all color and style keywords to their numeric codes.

KEYWORDS: namedtuple
"""
Unified keyword mapping for all colors and styles.

Contains all fields from STYLE, FG, plus prefixed versions:
- bg_* for background colors (from BG)
- bright_* for high intensity foreground (from HI_FG) 
- bg_bright_* for high intensity background (from HI_BG)
"""

Usage:

from hues.colortable import KEYWORDS

# Direct color access
print(KEYWORDS.red)         # 31 (same as FG.red)
print(KEYWORDS.bg_red)      # 41 (same as BG.red)
print(KEYWORDS.bright_red)  # 91 (same as HI_FG.red)
print(KEYWORDS.bg_bright_red) # 101 (same as HI_BG.red)

# Style access
print(KEYWORDS.bold)        # 1 (same as STYLE.bold)
print(KEYWORDS.reset)       # 0 (same as STYLE.reset)

ANSI Sequence Format

Template string for generating ANSI escape sequences.

SEQ: str
"""
ANSI escape sequence format string: '\\033[%sm'
Used to format numeric codes into escape sequences.
"""

Usage:

from hues.colortable import SEQ, FG

# Create ANSI escape sequence
red_sequence = SEQ % FG.red
print(repr(red_sequence))  # '\\033[31m'

# Multiple codes
codes = [FG.red, STYLE.bold]
multi_sequence = SEQ % ';'.join(map(str, codes))
print(repr(multi_sequence))  # '\\033[31;1m'

Usage Examples

Direct Color Code Access

from hues.colortable import FG, BG, STYLE, SEQ

# Build escape sequence manually
def make_colored(text, fg_color, bg_color=None):
    codes = [fg_color]
    if bg_color:
        codes.append(bg_color)
    
    start = SEQ % ';'.join(map(str, codes))
    end = SEQ % STYLE.reset
    return start + text + end

# Use it
colored = make_colored('Hello', FG.red, BG.white)
print(colored)  # Red text on white background

Keyword-Based Access

from hues.colortable import KEYWORDS

# Access any color/style by name
def get_code(name):
    return getattr(KEYWORDS, name)

red_code = get_code('red')         # 31
bg_blue_code = get_code('bg_blue') # 44
bold_code = get_code('bold')       # 1

Integration with HueString

These constants are used internally by HueString when you access color attributes:

from hues import huestr
from hues.colortable import KEYWORDS

text = huestr('Hello')

# When you do text.red, it internally uses:
# KEYWORDS.red (which equals 31)

# When you do text.bg_green, it uses:
# KEYWORDS.bg_green (which equals 42)

Constants Reference

All Available Colors

Standard Colors (FG 30-37, BG 40-47):

  • black, red, green, yellow, blue, magenta, cyan, white

High Intensity Colors (HI_FG 90-97, HI_BG 100-107):

  • Same names as standard, accessed via KEYWORDS as bright_*

Keyword Prefixes:

  • No prefix: foreground colors (FG)
  • bg_: background colors (BG)
  • bright_: high intensity foreground (HI_FG)
  • bg_bright_: high intensity background (HI_BG)

Styles:

  • reset (0), bold (1), italic (3), underline (4)
  • defaultfg (39), defaultbg (49)

Install with Tessl CLI

npx tessl i tessl/pypi-hues

docs

color-constants.md

console-logging.md

index.md

optimization.md

string-coloring.md

tile.json