Skip to content
VaelJS Blog

vael:ansi

Terminal ANSI escape sequences, SGR text styling, cursor and screen control, OSC 8 hyperlinks, synchronized output, and ANSI-aware text layout utilities.

Available in both vjs (vaeljs) and vjs-lite (vaeljs-lite) runtimes. Style wrappers properly restore outer SGR attributes across nested calls, control-sequence sanitizers strip embedded control characters from titles and hyperlink URLs, and width/truncation/wrapping helpers measure Unicode display columns accurately without counting ANSI escape sequences.

import ... from "vael:ansi"
Since v0.0.0-alpha.2 vjs (V8) vjs-lite (QuickJS)
Cargo feature: vael-ansi (enabled by default in vaeljs-core and vaeljs-lite-core)
import { bold, green, hex, style, visibleWidth, wrap } from "vael:ansi";
console.log(bold(green("OK")) + " deployment complete");
console.log(hex("#ff8800", "Warning"));
console.log(style("Banner", { bold: true, fg: "brightWhite", bg: "blue" }));
console.log(visibleWidth(green("hello"))); // 5
console.log(wrap(green("hello world"), 6));
API Symbols
Functions (92)
boldv0.0.0-alpha.2
Wrap text in bold SGR codes (\x1b[1m...\x1b[22m), restoring outer bold/dim state if nested.
dimv0.0.0-alpha.2
Wrap text in dim/faint SGR codes (\x1b[2m...\x1b[22m).
italicv0.0.0-alpha.2
Wrap text in italic SGR codes (\x1b[3m...\x1b[23m).
underlinev0.0.0-alpha.2
Wrap text in underline SGR codes (\x1b[4m...\x1b[24m).
blinkv0.0.0-alpha.2
Wrap text in blink SGR codes (\x1b[5m...\x1b[25m).
inversev0.0.0-alpha.2
Wrap text in inverse/reverse-video SGR codes (\x1b[7m...\x1b[27m).
hiddenv0.0.0-alpha.2
Wrap text in hidden/conceal SGR codes (\x1b[8m...\x1b[28m).
strikethroughv0.0.0-alpha.2
Wrap text in strikethrough SGR codes (\x1b[9m...\x1b[29m).
overlinev0.0.0-alpha.2
Wrap text in overline SGR codes (\x1b[53m...\x1b[55m).
resetv0.0.0-alpha.2
Wrap text with full SGR reset (\x1b[0m...\x1b[0m).
blackv0.0.0-alpha.2
Style text with black foreground color (SGR 30).
redv0.0.0-alpha.2
Style text with red foreground color (SGR 31).
greenv0.0.0-alpha.2
Style text with green foreground color (SGR 32).
yellowv0.0.0-alpha.2
Style text with yellow foreground color (SGR 33).
bluev0.0.0-alpha.2
Style text with blue foreground color (SGR 34).
magentav0.0.0-alpha.2
Style text with magenta foreground color (SGR 35).
cyanv0.0.0-alpha.2
Style text with cyan foreground color (SGR 36).
whitev0.0.0-alpha.2
Style text with white foreground color (SGR 37).
grayv0.0.0-alpha.2
Style text with gray (bright black) foreground color (SGR 90).
brightBlackv0.0.0-alpha.2
Style text with bright black foreground color (SGR 90).
brightRedv0.0.0-alpha.2
Style text with bright red foreground color (SGR 91).
brightGreenv0.0.0-alpha.2
Style text with bright green foreground color (SGR 92).
brightYellowv0.0.0-alpha.2
Style text with bright yellow foreground color (SGR 93).
brightBluev0.0.0-alpha.2
Style text with bright blue foreground color (SGR 94).
brightMagentav0.0.0-alpha.2
Style text with bright magenta foreground color (SGR 95).
brightCyanv0.0.0-alpha.2
Style text with bright cyan foreground color (SGR 96).
brightWhitev0.0.0-alpha.2
Style text with bright white foreground color (SGR 97).
bgBlackv0.0.0-alpha.2
Style text with black background color (SGR 40).
bgRedv0.0.0-alpha.2
Style text with red background color (SGR 41).
bgGreenv0.0.0-alpha.2
Style text with green background color (SGR 42).
bgYellowv0.0.0-alpha.2
Style text with yellow background color (SGR 43).
bgBluev0.0.0-alpha.2
Style text with blue background color (SGR 44).
bgMagentav0.0.0-alpha.2
Style text with magenta background color (SGR 45).
bgCyanv0.0.0-alpha.2
Style text with cyan background color (SGR 46).
bgWhitev0.0.0-alpha.2
Style text with white background color (SGR 47).
bgBrightBlackv0.0.0-alpha.2
Style text with bright black background color (SGR 100).
bgBrightRedv0.0.0-alpha.2
Style text with bright red background color (SGR 101).
bgBrightGreenv0.0.0-alpha.2
Style text with bright green background color (SGR 102).
bgBrightYellowv0.0.0-alpha.2
Style text with bright yellow background color (SGR 103).
bgBrightBluev0.0.0-alpha.2
Style text with bright blue background color (SGR 104).
bgBrightMagentav0.0.0-alpha.2
Style text with bright magenta background color (SGR 105).
bgBrightCyanv0.0.0-alpha.2
Style text with bright cyan background color (SGR 106).
bgBrightWhitev0.0.0-alpha.2
Style text with bright white background color (SGR 107).
rgb256v0.0.0-alpha.2
Style text with an ANSI 256-color palette foreground index (0..=255).
bgRgb256v0.0.0-alpha.2
Style text with an ANSI 256-color palette background index (0..=255).
rgb24v0.0.0-alpha.2
Style text with a 24-bit RGB truecolor foreground (\x1b[38;2;r;g;bm).
bgRgb24v0.0.0-alpha.2
Style text with a 24-bit RGB truecolor background (\x1b[48;2;r;g;bm).
hexv0.0.0-alpha.2
Style text with a 24-bit foreground color parsed from #rgb or #rrggbb.
bgHexv0.0.0-alpha.2
Style text with a 24-bit background color parsed from #rgb or #rrggbb.
stylev0.0.0-alpha.2
Apply multiple SGR attributes and foreground/background colors to text in a single builder call.
cursorUpv0.0.0-alpha.2
Move the cursor up by n rows (\x1b[<n>A).
cursorDownv0.0.0-alpha.2
Move the cursor down by n rows (\x1b[<n>B).
cursorForwardv0.0.0-alpha.2
Move the cursor forward (right) by n columns (\x1b[<n>C).
cursorBackv0.0.0-alpha.2
Move the cursor back (left) by n columns (\x1b[<n>D).
cursorNextLinev0.0.0-alpha.2
Move the cursor down n lines to column 1 (\x1b[<n>E).
cursorPrevLinev0.0.0-alpha.2
Move the cursor up n lines to column 1 (\x1b[<n>F).
cursorHorizontalAbsolutev0.0.0-alpha.2
Move the cursor to 1-based column col on the current line (\x1b[<col>G).
cursorTov0.0.0-alpha.2
Position the cursor at 1-based column col and optional 1-based row (\x1b[<col>G or \x1b[<row>;<col>H).
cursorMovev0.0.0-alpha.2
Move the cursor relative to its current position by dx columns and dy rows (dy defaults to 0).
cursorHomev0.0.0-alpha.2
Move the cursor to the top-left home position (\x1b[H).
cursorSavev0.0.0-alpha.2
Save the current cursor position (\x1b7 / DECSC or \x1b[s).
cursorRestorev0.0.0-alpha.2
Restore the previously saved cursor position (\x1b8 / DECRC or \x1b[u).
cursorHidev0.0.0-alpha.2
Hide the terminal cursor (\x1b[?25l).
cursorShowv0.0.0-alpha.2
Show the terminal cursor (\x1b[?25h).
cursorShapev0.0.0-alpha.2
Set the terminal cursor shape via DECSCUSR (\x1b[<shape> q).
eraseScreenv0.0.0-alpha.2
Erase the entire screen (\x1b[2J).
eraseScreenToEndv0.0.0-alpha.2
Erase from the cursor to the end of the screen (\x1b[0J or \x1b[J).
eraseScreenToStartv0.0.0-alpha.2
Erase from the start of the screen to the cursor (\x1b[1J).
eraseScrollbackv0.0.0-alpha.2
Erase the terminal scrollback buffer (\x1b[3J).
clearScreenv0.0.0-alpha.2
Clear the screen and move the cursor home (\x1b[2J\x1b[3J\x1b[H or \x1b[2J\x1b[H).
eraseLinev0.0.0-alpha.2
Erase the entire current line (\x1b[2K).
eraseLineToEndv0.0.0-alpha.2
Erase from the cursor to the end of the current line (\x1b[0K or \x1b[K).
eraseLineToStartv0.0.0-alpha.2
Erase from the start of the current line to the cursor (\x1b[1K).
eraseLinesv0.0.0-alpha.2
Erase n lines starting from the current line upward and return the cursor to column 1.
scrollUpv0.0.0-alpha.2
Scroll the viewport up by n lines (\x1b[<n>S).
scrollDownv0.0.0-alpha.2
Scroll the viewport down by n lines (\x1b[<n>T).
enterAltScreenv0.0.0-alpha.2
Switch to the terminal alternate screen buffer (\x1b[?1049h).
exitAltScreenv0.0.0-alpha.2
Return from the terminal alternate screen buffer (\x1b[?1049l).
enableLineWrapv0.0.0-alpha.2
Enable automatic terminal line wrapping (\x1b[?7h).
disableLineWrapv0.0.0-alpha.2
Disable automatic terminal line wrapping (\x1b[?7l).
setTitlev0.0.0-alpha.2
Build an OSC 0/2 terminal title sequence (\x1b]0;<title>\x07 or ST), stripping control characters from title to prevent terminal inje...
hyperlinkv0.0.0-alpha.2
Build an OSC 8 clickable terminal hyperlink sequence, stripping control characters from url and optional id to prevent terminal injec...
syncOutputv0.0.0-alpha.2
Wrap content in DEC 2026 synchronized output markers (\x1b[?2026h<content>\x1b[?2026l).
syncOutputStartv0.0.0-alpha.2
Begin a DEC 2026 synchronized output frame (\x1b[?2026h).
syncOutputEndv0.0.0-alpha.2
End a DEC 2026 synchronized output frame (\x1b[?2026l).
beepv0.0.0-alpha.2
Return the terminal audible/visual bell character ("\x07").
stripAnsiv0.0.0-alpha.2
Remove all ANSI CSI, OSC, and escape sequences from text.
visibleWidthv0.0.0-alpha.2
Compute the visible terminal column width of text, ignoring ANSI escape sequences, counting combining marks as width 0, and counting...
truncatev0.0.0-alpha.2
Truncate input to fit within maxWidth visible columns while preserving ANSI escape sequences and closing any active SGR styles before...
wrapv0.0.0-alpha.2
Word-wrap input to maxWidth visible columns while preserving active ANSI SGR styles across line breaks.
detectColorLevelv0.0.0-alpha.2
Detect the terminal's supported ANSI color level (0..3) from runtime environment and TTY capabilities.
isColorEnabledv0.0.0-alpha.2
Return true when ANSI color output is enabled in the current environment (detectColorLevel() > 0).
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function bold(text: string): string;

Wrap text in bold SGR codes (\x1b[1m...\x1b[22m), restoring outer bold/dim state if nested.

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
import { bold } from "vael:ansi";
console.log(bold("Important"));
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function dim(text: string): string;

Wrap text in dim/faint SGR codes (\x1b[2m...\x1b[22m).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function italic(text: string): string;

Wrap text in italic SGR codes (\x1b[3m...\x1b[23m).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function underline(text: string): string;

Wrap text in underline SGR codes (\x1b[4m...\x1b[24m).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function blink(text: string): string;

Wrap text in blink SGR codes (\x1b[5m...\x1b[25m).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function inverse(text: string): string;

Wrap text in inverse/reverse-video SGR codes (\x1b[7m...\x1b[27m).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function hidden(text: string): string;

Wrap text in hidden/conceal SGR codes (\x1b[8m...\x1b[28m).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function strikethrough(text: string): string;

Wrap text in strikethrough SGR codes (\x1b[9m...\x1b[29m).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function overline(text: string): string;

Wrap text in overline SGR codes (\x1b[53m...\x1b[55m).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function reset(text: string): string;

Wrap text with full SGR reset (\x1b[0m...\x1b[0m).

Parameters
NameTypeDescription
textstringInput string to wrap with reset sequences.
Returns
string — Reset-wrapped string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function black(text: string): string;

Style text with black foreground color (SGR 30).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function red(text: string): string;

Style text with red foreground color (SGR 31).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function green(text: string): string;

Style text with green foreground color (SGR 32).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function yellow(text: string): string;

Style text with yellow foreground color (SGR 33).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function blue(text: string): string;

Style text with blue foreground color (SGR 34).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function magenta(text: string): string;

Style text with magenta foreground color (SGR 35).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function cyan(text: string): string;

Style text with cyan foreground color (SGR 36).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function white(text: string): string;

Style text with white foreground color (SGR 37).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function gray(text: string): string;

Style text with gray (bright black) foreground color (SGR 90).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function brightBlack(text: string): string;

Style text with bright black foreground color (SGR 90).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function brightRed(text: string): string;

Style text with bright red foreground color (SGR 91).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function brightGreen(text: string): string;

Style text with bright green foreground color (SGR 92).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function brightYellow(text: string): string;

Style text with bright yellow foreground color (SGR 93).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function brightBlue(text: string): string;

Style text with bright blue foreground color (SGR 94).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function brightMagenta(text: string): string;

Style text with bright magenta foreground color (SGR 95).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function brightCyan(text: string): string;

Style text with bright cyan foreground color (SGR 96).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function brightWhite(text: string): string;

Style text with bright white foreground color (SGR 97).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function bgBlack(text: string): string;

Style text with black background color (SGR 40).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function bgRed(text: string): string;

Style text with red background color (SGR 41).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function bgGreen(text: string): string;

Style text with green background color (SGR 42).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function bgYellow(text: string): string;

Style text with yellow background color (SGR 43).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function bgBlue(text: string): string;

Style text with blue background color (SGR 44).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function bgMagenta(text: string): string;

Style text with magenta background color (SGR 45).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function bgCyan(text: string): string;

Style text with cyan background color (SGR 46).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function bgWhite(text: string): string;

Style text with white background color (SGR 47).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function bgBrightBlack(text: string): string;

Style text with bright black background color (SGR 100).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function bgBrightRed(text: string): string;

Style text with bright red background color (SGR 101).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function bgBrightGreen(text: string): string;

Style text with bright green background color (SGR 102).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function bgBrightYellow(text: string): string;

Style text with bright yellow background color (SGR 103).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function bgBrightBlue(text: string): string;

Style text with bright blue background color (SGR 104).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function bgBrightMagenta(text: string): string;

Style text with bright magenta background color (SGR 105).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function bgBrightCyan(text: string): string;

Style text with bright cyan background color (SGR 106).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function bgBrightWhite(text: string): string;

Style text with bright white background color (SGR 107).

Parameters
NameTypeDescription
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when text is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function rgb256(code: number, text: string): string;

Style text with an ANSI 256-color palette foreground index (0..=255).

Parameters
NameTypeDescription
codenumberPalette index integer in 0..=255.
textstringInput string to style.
Returns
string — Styled string (\x1b[38;5;<code>m...\x1b[39m).
Exceptions
  • TypeError — when code is not a number or text is not a string.
  • RangeError — when code is not an integer in 0..=255.
import { rgb256 } from "vael:ansi";
console.log(rgb256(208, "Orange"));
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function bgRgb256(code: number, text: string): string;

Style text with an ANSI 256-color palette background index (0..=255).

Parameters
NameTypeDescription
codenumberPalette index integer in 0..=255.
textstringInput string to style.
Returns
string — Styled string (\x1b[48;5;<code>m...\x1b[49m).
Exceptions
  • TypeError — when code is not a number or text is not a string.
  • RangeError — when code is not an integer in 0..=255.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function rgb24(r: number, g: number, b: number, text: string): string;

Style text with a 24-bit RGB truecolor foreground (\x1b[38;2;r;g;bm).

Parameters
NameTypeDescription
rnumberRed channel integer in 0..=255.
gnumberGreen channel integer in 0..=255.
bnumberBlue channel integer in 0..=255.
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when any channel is not a number or text is not a string.
  • RangeError — when any channel is not an integer in 0..=255.
import { rgb24 } from "vael:ansi";
console.log(rgb24(255, 136, 0, "Truecolor"));
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function bgRgb24(r: number, g: number, b: number, text: string): string;

Style text with a 24-bit RGB truecolor background (\x1b[48;2;r;g;bm).

Parameters
NameTypeDescription
rnumberRed channel integer in 0..=255.
gnumberGreen channel integer in 0..=255.
bnumberBlue channel integer in 0..=255.
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when any channel is not a number or text is not a string.
  • RangeError — when any channel is not an integer in 0..=255.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function hex(color: string, text: string): string;

Style text with a 24-bit foreground color parsed from #rgb or #rrggbb.

Parameters
NameTypeDescription
colorstringHex color string ("#f0a" or "#112233", leading # optional if supported or required #rgb/#rrggbb).
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when color or text is not a string.
  • RangeError — when color is not a valid hex color.
import { hex } from "vael:ansi";
console.log(hex("#ff8800", "Warm"));
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function bgHex(color: string, text: string): string;

Style text with a 24-bit background color parsed from #rgb or #rrggbb.

Parameters
NameTypeDescription
colorstringHex color string ("#f0a" or "#112233").
textstringInput string to style.
Returns
string — Styled string.
Exceptions
  • TypeError — when color or text is not a string.
  • RangeError — when color is not a valid hex color.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function style(text: string, options?: StyleOptions): string;

Apply multiple SGR attributes and foreground/background colors to text in a single builder call.

Parameters
NameTypeDescription
textstringInput string to style.
options optionalStyleOptionsOptional SGR attribute flags and fg/bg colors.
Returns
string — Styled string (or text unchanged when options is undefined).
Exceptions
  • TypeError — when text is not a string or options is provided and not an object.
  • RangeError — when a color specification in options is invalid.
import { style } from "vael:ansi";
console.log(style("Alert", { bold: true, underline: true, fg: "brightWhite", bg: "#aa0000" }));
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function cursorUp(n?: number): string;

Move the cursor up by n rows (\x1b[<n>A).

Parameters
NameTypeDescription
n optionalnumberNumber of rows to move (defaults to 1).
Returns
string — CSI cursor-up escape sequence.
Exceptions
  • TypeError — when n is defined and not a number.
  • RangeError — when n is negative, NaN, infinite, or non-integer.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function cursorDown(n?: number): string;

Move the cursor down by n rows (\x1b[<n>B).

Parameters
NameTypeDescription
n optionalnumberNumber of rows to move (defaults to 1).
Returns
string — CSI cursor-down escape sequence.
Exceptions
  • TypeError — when n is defined and not a number.
  • RangeError — when n is negative, NaN, infinite, or non-integer.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function cursorForward(n?: number): string;

Move the cursor forward (right) by n columns (\x1b[<n>C).

Parameters
NameTypeDescription
n optionalnumberNumber of columns to move (defaults to 1).
Returns
string — CSI cursor-forward escape sequence.
Exceptions
  • TypeError — when n is defined and not a number.
  • RangeError — when n is negative, NaN, infinite, or non-integer.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function cursorBack(n?: number): string;

Move the cursor back (left) by n columns (\x1b[<n>D).

Parameters
NameTypeDescription
n optionalnumberNumber of columns to move (defaults to 1).
Returns
string — CSI cursor-back escape sequence.
Exceptions
  • TypeError — when n is defined and not a number.
  • RangeError — when n is negative, NaN, infinite, or non-integer.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function cursorNextLine(n?: number): string;

Move the cursor down n lines to column 1 (\x1b[<n>E).

Parameters
NameTypeDescription
n optionalnumberNumber of lines to move (defaults to 1).
Returns
string — CSI cursor-next-line escape sequence.
Exceptions
  • TypeError — when n is defined and not a number.
  • RangeError — when n is negative, NaN, infinite, or non-integer.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function cursorPrevLine(n?: number): string;

Move the cursor up n lines to column 1 (\x1b[<n>F).

Parameters
NameTypeDescription
n optionalnumberNumber of lines to move (defaults to 1).
Returns
string — CSI cursor-previous-line escape sequence.
Exceptions
  • TypeError — when n is defined and not a number.
  • RangeError — when n is negative, NaN, infinite, or non-integer.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function cursorHorizontalAbsolute(col?: number): string;

Move the cursor to 1-based column col on the current line (\x1b[<col>G).

Parameters
NameTypeDescription
col optionalnumber1-based column index (defaults to 1).
Returns
string — CSI cursor-horizontal-absolute escape sequence.
Exceptions
  • TypeError — when col is defined and not a number.
  • RangeError — when col is < 1, NaN, infinite, or non-integer.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function cursorTo(col: number, row?: number): string;

Position the cursor at 1-based column col and optional 1-based row (\x1b[<col>G or \x1b[<row>;<col>H).

Parameters
NameTypeDescription
colnumber1-based column index.
row optionalnumberOptional 1-based row index.
Returns
string — CSI cursor positioning escape sequence.
Exceptions
  • TypeError — when col or defined row is not a number.
  • RangeError — when coordinates are < 1, NaN, infinite, or non-integer.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function cursorMove(dx: number, dy?: number): string;

Move the cursor relative to its current position by dx columns and dy rows (dy defaults to 0).

Parameters
NameTypeDescription
dxnumberRelative horizontal offset (positive right, negative left).
dy optionalnumberOptional relative vertical offset (positive down, negative up; defaults to 0).
Returns
string — Concatenated CSI cursor movement sequences (empty string if both are 0).
Exceptions
  • TypeError — when dx or defined dy is not a number.
  • RangeError — when dx or dy is NaN, infinite, or non-integer.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function cursorHome(): string;

Move the cursor to the top-left home position (\x1b[H).

Returns
string — CSI cursor-home escape sequence.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function cursorSave(): string;

Save the current cursor position (\x1b7 / DECSC or \x1b[s).

Returns
string — Cursor-save escape sequence.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function cursorRestore(): string;

Restore the previously saved cursor position (\x1b8 / DECRC or \x1b[u).

Returns
string — Cursor-restore escape sequence.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function cursorHide(): string;

Hide the terminal cursor (\x1b[?25l).

Returns
string — DEC private mode hide-cursor escape sequence.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function cursorShow(): string;

Show the terminal cursor (\x1b[?25h).

Returns
string — DEC private mode show-cursor escape sequence.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function cursorShape(shape?: CursorShapeValue): string;

Set the terminal cursor shape via DECSCUSR (\x1b[<shape> q).

Parameters
NameTypeDescription
shape optionalCursorShapeValueCursor shape value (0..=6, defaults to 0 / CursorShape.DEFAULT).
Returns
string — DECSCUSR escape sequence.
Exceptions
  • TypeError — when shape is defined and not a number.
  • RangeError — when shape is not an integer in 0..=6.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function eraseScreen(): string;

Erase the entire screen (\x1b[2J).

Returns
string — CSI erase-screen escape sequence.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function eraseScreenToEnd(): string;

Erase from the cursor to the end of the screen (\x1b[0J or \x1b[J).

Returns
string — CSI erase-to-end-of-screen escape sequence.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function eraseScreenToStart(): string;

Erase from the start of the screen to the cursor (\x1b[1J).

Returns
string — CSI erase-to-start-of-screen escape sequence.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function eraseScrollback(): string;

Erase the terminal scrollback buffer (\x1b[3J).

Returns
string — CSI erase-scrollback escape sequence.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function clearScreen(): string;

Clear the screen and move the cursor home (\x1b[2J\x1b[3J\x1b[H or \x1b[2J\x1b[H).

Returns
string — Screen-clear escape sequence.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function eraseLine(): string;

Erase the entire current line (\x1b[2K).

Returns
string — CSI erase-line escape sequence.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function eraseLineToEnd(): string;

Erase from the cursor to the end of the current line (\x1b[0K or \x1b[K).

Returns
string — CSI erase-to-end-of-line escape sequence.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function eraseLineToStart(): string;

Erase from the start of the current line to the cursor (\x1b[1K).

Returns
string — CSI erase-to-start-of-line escape sequence.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function eraseLines(n: number): string;

Erase n lines starting from the current line upward and return the cursor to column 1.

Parameters
NameTypeDescription
nnumberNumber of lines to erase (non-negative integer).
Returns
string — Escape sequence erasing n lines.
Exceptions
  • TypeError — when n is not a number.
  • RangeError — when n is negative, NaN, infinite, or non-integer.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function scrollUp(n?: number): string;

Scroll the viewport up by n lines (\x1b[<n>S).

Parameters
NameTypeDescription
n optionalnumberNumber of lines to scroll (defaults to 1).
Returns
string — CSI scroll-up escape sequence.
Exceptions
  • TypeError — when n is defined and not a number.
  • RangeError — when n is negative, NaN, infinite, or non-integer.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function scrollDown(n?: number): string;

Scroll the viewport down by n lines (\x1b[<n>T).

Parameters
NameTypeDescription
n optionalnumberNumber of lines to scroll (defaults to 1).
Returns
string — CSI scroll-down escape sequence.
Exceptions
  • TypeError — when n is defined and not a number.
  • RangeError — when n is negative, NaN, infinite, or non-integer.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function enterAltScreen(): string;

Switch to the terminal alternate screen buffer (\x1b[?1049h).

Returns
string — Alternate screen enter escape sequence.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function exitAltScreen(): string;

Return from the terminal alternate screen buffer (\x1b[?1049l).

Returns
string — Alternate screen exit escape sequence.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function enableLineWrap(): string;

Enable automatic terminal line wrapping (\x1b[?7h).

Returns
string — DEC private mode enable-line-wrap escape sequence.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function disableLineWrap(): string;

Disable automatic terminal line wrapping (\x1b[?7l).

Returns
string — DEC private mode disable-line-wrap escape sequence.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function setTitle(title: string): string;

Build an OSC 0/2 terminal title sequence (\x1b]0;<title>\x07 or ST), stripping control characters from title to prevent terminal injection.

Parameters
NameTypeDescription
titlestringDesired terminal title string.
Returns
string — Sanitized OSC title escape sequence.
Exceptions
  • TypeError — when title is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function hyperlink(text: string, url: string, id?: string): string;

Build an OSC 8 clickable terminal hyperlink sequence, stripping control characters from url and optional id to prevent terminal injection.

Parameters
NameTypeDescription
textstringVisible link label text.
urlstringTarget hyperlink URL.
id optionalstringOptional OSC 8 id parameter grouping multi-span links.
Returns
string — Sanitized OSC 8 hyperlink sequence wrapping text.
Exceptions
  • TypeError — when text, url, or defined id is not a string.
import { hyperlink } from "vael:ansi";
console.log(hyperlink("VaelJS", "https://vaeljs.com"));
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function syncOutput(content: string): string;

Wrap content in DEC 2026 synchronized output markers (\x1b[?2026h<content>\x1b[?2026l).

Parameters
NameTypeDescription
contentstringFrame payload to bracket in synchronized output markers.
Returns
string — Bracketed output string.
Exceptions
  • TypeError — when content is not a string.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function syncOutputStart(): string;

Begin a DEC 2026 synchronized output frame (\x1b[?2026h).

Returns
string — Synchronized output start escape sequence.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function syncOutputEnd(): string;

End a DEC 2026 synchronized output frame (\x1b[?2026l).

Returns
string — Synchronized output end escape sequence.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function beep(): string;

Return the terminal audible/visual bell character ("\x07").

Returns
string — ASCII BEL sequence.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function stripAnsi(text: string): string;

Remove all ANSI CSI, OSC, and escape sequences from text.

Parameters
NameTypeDescription
textstringInput string potentially containing ANSI escape sequences.
Returns
string — Plain string without ANSI escape sequences.
Exceptions
  • TypeError — when text is not a string.
import { red, stripAnsi } from "vael:ansi";
console.log(stripAnsi(red("Hello"))); // "Hello"
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function visibleWidth(text: string): number;

Compute the visible terminal column width of text, ignoring ANSI escape sequences, counting combining marks as width 0, and counting wide CJK / emoji graphemes as width 2.

Parameters
NameTypeDescription
textstringInput string (may contain ANSI escape sequences).
Returns
number — Non-negative display column width.
Exceptions
  • TypeError — when text is not a string.
import { bold, visibleWidth } from "vael:ansi";
console.log(visibleWidth(bold("hi"))); // 2
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function truncate(input: string, maxWidth: number, options?: TruncateOptions): string;

Truncate input to fit within maxWidth visible columns while preserving ANSI escape sequences and closing any active SGR styles before ellipsis.

Parameters
NameTypeDescription
inputstringInput string (may contain ANSI escape sequences).
maxWidthnumberMaximum visible column width (>= 0).
options optionalTruncateOptionsOptional truncation settings (ellipsis).
Returns
string — Truncated string whose visible width is <= maxWidth.
Exceptions
  • TypeError — when input is not a string, maxWidth is not a number, or options is invalid.
  • RangeError — when maxWidth is negative, NaN, infinite, or non-integer.
import { green, truncate } from "vael:ansi";
console.log(truncate(green("hello world"), 8));
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function wrap(input: string, maxWidth: number, options?: WrapOptions): string;

Word-wrap input to maxWidth visible columns while preserving active ANSI SGR styles across line breaks.

Parameters
NameTypeDescription
inputstringInput string (may contain ANSI escape sequences).
maxWidthnumberMaximum visible column width per line (>= 1).
options optionalWrapOptionsOptional wrapping settings (hard).
Returns
string — Wrapped multi-line string.
Exceptions
  • TypeError — when input is not a string, maxWidth is not a number, or options is invalid.
  • RangeError — when maxWidth is < 1, NaN, infinite, or non-integer.
import { cyan, wrap } from "vael:ansi";
console.log(wrap(cyan("alpha beta gamma"), 10));
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function detectColorLevel(): ColorLevelValue;

Detect the terminal’s supported ANSI color level (0..3) from runtime environment and TTY capabilities.

Returns
ColorLevelValue — Detected ColorLevelValue (0, 1, 2, or 3).
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function isColorEnabled(): boolean;

Return true when ANSI color output is enabled in the current environment (detectColorLevel() > 0).

Returns
boolean — Whether ANSI color output is enabled.
interfaceSince v0.0.0-alpha.2vjs & vjs-lite
export interface StyleOptions {
  bold?: boolean;
  dim?: boolean;
  italic?: boolean;
  underline?: boolean;
  blink?: boolean;
  inverse?: boolean;
  hidden?: boolean;
  strikethrough?: boolean;
  overline?: boolean;
  fg?: AnsiColorValue;
  bg?: AnsiColorValue;
}

Combined SGR styling options accepted by style.

Properties
PropertyTypeDescriptionSince
bold optionalbooleanApply bold / increased intensity (SGR 1).v0.0.0-alpha.2
dim optionalbooleanApply dim / faint intensity (SGR 2).v0.0.0-alpha.2
italic optionalbooleanApply italic emphasis (SGR 3).v0.0.0-alpha.2
underline optionalbooleanApply underline (SGR 4).v0.0.0-alpha.2
blink optionalbooleanApply slow blink (SGR 5).v0.0.0-alpha.2
inverse optionalbooleanSwap foreground and background colors (SGR 7).v0.0.0-alpha.2
hidden optionalbooleanConceal text (SGR 8).v0.0.0-alpha.2
strikethrough optionalbooleanApply strikethrough (SGR 9).v0.0.0-alpha.2
overline optionalbooleanApply overline (SGR 53).v0.0.0-alpha.2
fg optionalAnsiColorValueForeground color specification.v0.0.0-alpha.2
bg optionalAnsiColorValueBackground color specification.v0.0.0-alpha.2
interfaceSince v0.0.0-alpha.2vjs & vjs-lite
export interface TruncateOptions {
  ellipsis?: string;
}

Options accepted by truncate.

Properties
PropertyTypeDescriptionSince
ellipsis optionalstringTrailing indicator appended when text exceeds maxWidth. Defaults to "…".v0.0.0-alpha.2
interfaceSince v0.0.0-alpha.2vjs & vjs-lite
export interface WrapOptions {
  hard?: boolean;
}

Options accepted by wrap.

Properties
PropertyTypeDescriptionSince
hard optionalbooleanBreak words longer than maxWidth mid-word instead of overflowing. Defaults to false.v0.0.0-alpha.2
typeSince v0.0.0-alpha.2vjs & vjs-lite
export type ColorLevelValue = 0 | 1 | 2 | 3;

Supported terminal color capability levels returned by detectColorLevel and exposed on ColorLevel.

  • 0 (NONE): no color support
  • 1 (BASIC): 16-color ANSI SGR
  • 2 (ANSI256): 256-color palette
  • 3 (TRUECOLOR): 24-bit RGB truecolor
typeSince v0.0.0-alpha.2vjs & vjs-lite
export type CursorShapeValue = 0 | 1 | 2 | 3 | 4 | 5 | 6;

DECSCUSR cursor shape values accepted by cursorShape and exposed on CursorShape.

typeSince v0.0.0-alpha.2vjs & vjs-lite
export type AnsiColorName =
  | "black"
  | "red"
  | "green"
  | "yellow"
  | "blue"
  | "magenta"
  | "cyan"
  | "white"
  | "gray"
  | "brightBlack"
  | "brightRed"
  | "brightGreen"
  | "brightYellow"
  | "brightBlue"
  | "brightMagenta"
  | "brightCyan"
  | "brightWhite";

Named 16-color ANSI palette identifiers accepted by StyleOptions.fg and StyleOptions.bg.

typeSince v0.0.0-alpha.2vjs & vjs-lite
export type AnsiColorValue = AnsiColorName | number | readonly [number, number, number] | string;

Color specification accepted by StyleOptions.fg and StyleOptions.bg: a named 16-color identifier, an ANSI 256-color index (0..=255), an RGB triple [r, g, b] (0..=255), or a #rgb / #rrggbb hex string.

constSince v0.0.0-alpha.2vjs & vjs-lite
export const ESC: "\x1b";

ASCII Escape character ("\x1b").

constSince v0.0.0-alpha.2vjs & vjs-lite
export const CSI: "\x1b[";

Control Sequence Introducer ("\x1b[").

constSince v0.0.0-alpha.2vjs & vjs-lite
export const OSC: "\x1b]";

Operating System Command introducer ("\x1b]").

constSince v0.0.0-alpha.2vjs & vjs-lite
export const ST: "\x1b\\";

String Terminator ("\x1b\\").

constSince v0.0.0-alpha.2vjs & vjs-lite
export const BEL: "\x07";

ASCII Bell character ("\x07").

constSince v0.0.0-alpha.2vjs & vjs-lite
export const RESET: "\x1b[0m";

SGR full attribute reset sequence ("\x1b[0m").

constSince v0.0.0-alpha.2vjs & vjs-lite
export const ColorLevel: {
  /** No color support (`0`). @since 0.0.0-alpha.2 */
  readonly NONE: 0;
  /** Basic 16-color ANSI support (`1`). @since 0.0.0-alpha.2 */
  readonly BASIC: 1;
  /** 256-color palette support (`2`). @since 0.0.0-alpha.2 */
  readonly ANSI256: 2;
  /** 24-bit RGB truecolor support (`3`). @since 0.0.0-alpha.2 */
  readonly TRUECOLOR: 3;
};

Terminal color support levels returned by detectColorLevel.

constSince v0.0.0-alpha.2vjs & vjs-lite
export const CursorShape: {
  /** Terminal default cursor (`0`). @since 0.0.0-alpha.2 */
  readonly DEFAULT: 0;
  /** Blinking block cursor (`1`). @since 0.0.0-alpha.2 */
  readonly BLOCK_BLINK: 1;
  /** Steady block cursor (`2`). @since 0.0.0-alpha.2 */
  readonly BLOCK: 2;
  /** Blinking underline cursor (`3`). @since 0.0.0-alpha.2 */
  readonly UNDERLINE_BLINK: 3;
  /** Steady underline cursor (`4`). @since 0.0.0-alpha.2 */
  readonly UNDERLINE: 4;
  /** Blinking bar / I-beam cursor (`5`). @since 0.0.0-alpha.2 */
  readonly BAR_BLINK: 5;
  /** Steady bar / I-beam cursor (`6`). @since 0.0.0-alpha.2 */
  readonly BAR: 6;
};

DECSCUSR terminal cursor shape constants accepted by cursorShape.