Manuscript Documentation
v2026.12.0

@std/cli/style.ms#

Import each required symbol with import Name from "@std/cli/style.ms".

Color Enum#

A terminal color: the terminal default, a 16-color index, a 256-color palette index, or a 24-bit RGB value. paint downgrades richer colors to what the terminal supports.

Manuscript
enum Color {
    Default
    Ansi(index Int)
    Indexed(index Int)
    Rgb(red Int, green Int, blue Int)
}

Color.Ansi#

One of the 16 ANSI colors; values outside 0 to 15 are clamped.

Manuscript
Ansi(index Int)

Color.Default#

The terminal’s own default color, which emits no color sequence.

Manuscript
Default

Color.Indexed#

An entry of the 256-color palette; values outside 0 to 255 are clamped, and terminals below 256 colors get the nearest of 16.

Manuscript
Indexed(index Int)

Color.Rgb#

A 24-bit color; terminals with fewer than 16777216 colors get the nearest color they support.

Manuscript
Rgb(red Int, green Int, blue Int)

Color.Ansi.index#

0 to 7 normal colors, 8 to 15 bright colors.

Manuscript
index Int

Color.Indexed.index#

0 to 255 in the 256-color palette.

Manuscript
index Int

Color.Rgb.blue#

Blue, 0 to 255.

Manuscript
blue Int

Color.Rgb.green#

Green, 0 to 255.

Manuscript
green Int

Color.Rgb.red#

Red, 0 to 255.

Manuscript
red Int

Style Type#

Colors and attributes of a run of text.

Manuscript
type Style {
    foreground Color = Color.Default
    background Color = Color.Default
    bold Bool = false
    dim Bool = false
    italic Bool = false
    underline Bool = false
    reverse Bool = false
    strikethrough Bool = false
}

Style.background#

Background color; Color.Default leaves the terminal’s own background.

Manuscript
background Color = Color.Default

Style.bold#

Heavier weight when true; defaults to false.

Manuscript
bold Bool = false

Style.dim#

Reduced intensity when true; defaults to false.

Manuscript
dim Bool = false

Style.foreground#

Text color; Color.Default leaves the terminal’s own foreground.

Manuscript
foreground Color = Color.Default

Style.italic#

Slanted text when true; defaults to false.

Manuscript
italic Bool = false

Style.reverse#

Swaps foreground and background when true; defaults to false.

Manuscript
reverse Bool = false

Style.strikethrough#

Struck-through text when true; defaults to false.

Manuscript
strikethrough Bool = false

Style.underline#

Underlined text when true; defaults to false.

Manuscript
underline Bool = false

paint Function#

Wraps text in style and a reset. Returns text unchanged when colors is 0 or the style is plain.

Manuscript
fn paint(text String, style Style, colors Int) String { ... }

strip_ansi Function#

Removes escape sequences from text.

Manuscript
fn strip_ansi(text String) String { ... }

style_start Function#

The escape sequence that starts style for a terminal with colors colors, or "" when it changes nothing.

Manuscript
fn style_start(style Style, colors Int) String { ... }

styled Function#

Like paint, using the color count of the current terminal.

Manuscript
fn styled(text String, style Style) String { ... }

truncate_text Function#

Cuts the single line text to at most width visible columns, keeping escape sequences and ending a styled cut with a reset.

Manuscript
fn truncate_text(text String, width Int) String { ... }

visible_width Function#

The number of terminal columns text occupies, ignoring escape sequences. Any other control character returns EBADMSG.

Manuscript
fn visible_width(text String) Result[Int, Error] { ... }

wrap_text Function#

Splits text on newlines and wraps each line into rows of at most width columns, counting only visible characters. Escape sequences stay with the text they style: a row that breaks inside styled text ends with a reset and the next row repeats the active color and style sequences. Other sequences, such as window titles and hyperlinks, are kept whole and count for no columns. A width below 1 is treated as 1.

Manuscript
fn wrap_text(text String, width Int) List[String] { ... }