ANSI styling: foregrounds (30–37, 90–97), backgrounds (40–47, 100–107), text styles (bold/dim/italic/underline/blink/reverse/strikethrough), truecolor (rgb/bg_rgb), 256-color (color256/bg_256), hex (#RRGGBB), and numeric helpers. Every wrapper takes text first and appends a trailing reset so styles never bleed. Pipeline-friendly — composes with |>.
std.colors wraps text in ANSI escape sequences for terminal output. All channel wrappers take (s: str) -> str and append a reset, so styles never bleed across output. Nesting stacks (bold(reverse(x))); strip recovers visible text. Designed for CLI tools, test reporters, and logs.
println ( "TEST FAIL" |> colors. red () |> colors. bold ())
println (colors. strip (colors. reverse ( "sel" )) == "sel" ) // true
println (colors. rgb ( "hi" , 255 , 87 , 51 )) // truecolor fg
println (colors. hex ( "hi" , "#FF5733" )) // #RRGGBB / RRGGBB / #RGB
println (colors. bg_rgb ( "ok" , 0 , 128 , 0 )) // truecolor bg
func status_color ( ok : bool , msg: str ) - > str {
if ok { return colors. green (msg) }
return colors. red (msg) |> colors. bold ()
println (colors. bold (colors. underline ( "=== Report ===" )))
51 entries. Signatures come from the compiler’s own FuncSig table, so they match the runtime exactly; descriptions come from the module guide.
Function
Signature
Description
std.colors.bg_256
bg_256(s: str, n: int) -> str
256-color bg (48;5;n, clamped)
std.colors.bg_black
bg_black(s: str) -> str
Background SGR 40–47
std.colors.bg_blue
bg_blue(s: str) -> str
—
std.colors.bg_bright_black
bg_bright_black(s: str) -> str
Background SGR 100–107
std.colors.bg_bright_blue
bg_bright_blue(s: str) -> str
—
std.colors.bg_bright_cyan
bg_bright_cyan(s: str) -> str
—
std.colors.bg_bright_green
bg_bright_green(s: str) -> str
—
std.colors.bg_bright_magenta
bg_bright_magenta(s: str) -> str
—
std.colors.bg_bright_red
bg_bright_red(s: str) -> str
—
std.colors.bg_bright_white
bg_bright_white(s: str) -> str
Background SGR 100–107
std.colors.bg_bright_yellow
bg_bright_yellow(s: str) -> str
—
std.colors.bg_cyan
bg_cyan(s: str) -> str
—
std.colors.bg_green
bg_green(s: str) -> str
—
std.colors.bg_magenta
bg_magenta(s: str) -> str
—
std.colors.bg_red
bg_red(s: str) -> str
—
std.colors.bg_rgb
bg_rgb(s: str, r: int, g: int, b: int) -> str
Truecolor bg (channels clamped)
std.colors.bg_white
bg_white(s: str) -> str
Background SGR 40–47
std.colors.bg_yellow
bg_yellow(s: str) -> str
—
std.colors.black
black(s: str) -> str
Foreground SGR 30–37
std.colors.blink
blink(s: str) -> str
Blink (SGR 5)
std.colors.blue
blue(s: str) -> str
—
std.colors.bold
bold(s: str) -> str
Bold (SGR 1)
std.colors.bright_black
bright_black(s: str) -> str
Foreground SGR 90–97
std.colors.bright_blue
bright_blue(s: str) -> str
—
std.colors.bright_cyan
bright_cyan(s: str) -> str
—
std.colors.bright_green
bright_green(s: str) -> str
—
std.colors.bright_magenta
bright_magenta(s: str) -> str
—
std.colors.bright_red
bright_red(s: str) -> str
—
std.colors.bright_white
bright_white(s: str) -> str
Foreground SGR 90–97
std.colors.bright_yellow
bright_yellow(s: str) -> str
—
std.colors.clamp255
clamp255(v: int) -> int
Clamp to 0–255
std.colors.color256
color256(s: str, n: int) -> str
256-color fg (38;5;n, clamped)
std.colors.cyan
cyan(s: str) -> str
—
std.colors.dim
dim(s: str) -> str
Dim (SGR 2)
std.colors.green
green(s: str) -> str
—
std.colors.hex
hex(s: str, code: str) -> str
#FF5733 / FF5733 / #F53; malformed passes through
std.colors.hex3
hex3(s: str, digits: [str]) -> str
Three-digit form
std.colors.hex6
hex6(s: str, digits: [str]) -> str
Six-digit form
std.colors.hex_byte
hex_byte(hi: str, lo: str) -> int
Byte parser (-1 on malformed)
std.colors.hex_val
hex_val(c: str) -> int
Nibble parser (-1 on malformed)
std.colors.italic
italic(s: str) -> str
Italic (SGR 3)
std.colors.magenta
magenta(s: str) -> str
—
std.colors.red
red(s: str) -> str
—
std.colors.reset
reset(s: str) -> str
Append reset
std.colors.reverse
reverse(s: str) -> str
Reverse video (SGR 7)
std.colors.rgb
rgb(s: str, r: int, g: int, b: int) -> str
Truecolor fg (channels clamped)
std.colors.strikethrough
strikethrough(s: str) -> str
Strikethrough (SGR 9)
std.colors.strip
strip(s: str) -> str
Remove all \e[…m
std.colors.underline
underline(s: str) -> str
Underline (SGR 4)
std.colors.white
white(s: str) -> str
Foreground SGR 30–37
std.colors.yellow
yellow(s: str) -> str
—
std.term — Terminal output: size detection, cursor control and raw mode.
Full index: API reference · Standard library