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"
vael-ansi (enabled by default in vaeljs-core and vaeljs-lite-core)Example
Section titled “Example”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"))); // 5console.log(wrap(green("hello world"), 6));boldv0.0.0-alpha.2text in bold SGR codes (\x1b[1m...\x1b[22m), restoring outer bold/dim state if nested.dimv0.0.0-alpha.2text in dim/faint SGR codes (\x1b[2m...\x1b[22m).italicv0.0.0-alpha.2text in italic SGR codes (\x1b[3m...\x1b[23m).underlinev0.0.0-alpha.2text in underline SGR codes (\x1b[4m...\x1b[24m).blinkv0.0.0-alpha.2text in blink SGR codes (\x1b[5m...\x1b[25m).inversev0.0.0-alpha.2text in inverse/reverse-video SGR codes (\x1b[7m...\x1b[27m).hiddenv0.0.0-alpha.2text in hidden/conceal SGR codes (\x1b[8m...\x1b[28m).strikethroughv0.0.0-alpha.2text in strikethrough SGR codes (\x1b[9m...\x1b[29m).overlinev0.0.0-alpha.2text in overline SGR codes (\x1b[53m...\x1b[55m).resetv0.0.0-alpha.2text with full SGR reset (\x1b[0m...\x1b[0m).blackv0.0.0-alpha.2text with black foreground color (SGR 30).redv0.0.0-alpha.2text with red foreground color (SGR 31).greenv0.0.0-alpha.2text with green foreground color (SGR 32).yellowv0.0.0-alpha.2text with yellow foreground color (SGR 33).bluev0.0.0-alpha.2text with blue foreground color (SGR 34).magentav0.0.0-alpha.2text with magenta foreground color (SGR 35).cyanv0.0.0-alpha.2text with cyan foreground color (SGR 36).whitev0.0.0-alpha.2text with white foreground color (SGR 37).grayv0.0.0-alpha.2text with gray (bright black) foreground color (SGR 90).brightBlackv0.0.0-alpha.2text with bright black foreground color (SGR 90).brightRedv0.0.0-alpha.2text with bright red foreground color (SGR 91).brightGreenv0.0.0-alpha.2text with bright green foreground color (SGR 92).brightYellowv0.0.0-alpha.2text with bright yellow foreground color (SGR 93).brightBluev0.0.0-alpha.2text with bright blue foreground color (SGR 94).brightMagentav0.0.0-alpha.2text with bright magenta foreground color (SGR 95).brightCyanv0.0.0-alpha.2text with bright cyan foreground color (SGR 96).brightWhitev0.0.0-alpha.2text with bright white foreground color (SGR 97).bgBlackv0.0.0-alpha.2text with black background color (SGR 40).bgRedv0.0.0-alpha.2text with red background color (SGR 41).bgGreenv0.0.0-alpha.2text with green background color (SGR 42).bgYellowv0.0.0-alpha.2text with yellow background color (SGR 43).bgBluev0.0.0-alpha.2text with blue background color (SGR 44).bgMagentav0.0.0-alpha.2text with magenta background color (SGR 45).bgCyanv0.0.0-alpha.2text with cyan background color (SGR 46).bgWhitev0.0.0-alpha.2text with white background color (SGR 47).bgBrightBlackv0.0.0-alpha.2text with bright black background color (SGR 100).bgBrightRedv0.0.0-alpha.2text with bright red background color (SGR 101).bgBrightGreenv0.0.0-alpha.2text with bright green background color (SGR 102).bgBrightYellowv0.0.0-alpha.2text with bright yellow background color (SGR 103).bgBrightBluev0.0.0-alpha.2text with bright blue background color (SGR 104).bgBrightMagentav0.0.0-alpha.2text with bright magenta background color (SGR 105).bgBrightCyanv0.0.0-alpha.2text with bright cyan background color (SGR 106).bgBrightWhitev0.0.0-alpha.2text with bright white background color (SGR 107).rgb256v0.0.0-alpha.2text with an ANSI 256-color palette foreground index (0..=255).bgRgb256v0.0.0-alpha.2text with an ANSI 256-color palette background index (0..=255).rgb24v0.0.0-alpha.2text with a 24-bit RGB truecolor foreground (\x1b[38;2;r;g;bm).bgRgb24v0.0.0-alpha.2text with a 24-bit RGB truecolor background (\x1b[48;2;r;g;bm).hexv0.0.0-alpha.2text with a 24-bit foreground color parsed from #rgb or #rrggbb.bgHexv0.0.0-alpha.2text with a 24-bit background color parsed from #rgb or #rrggbb.stylev0.0.0-alpha.2text in a single builder call.cursorUpv0.0.0-alpha.2n rows (\x1b[<n>A).cursorDownv0.0.0-alpha.2n rows (\x1b[<n>B).cursorForwardv0.0.0-alpha.2n columns (\x1b[<n>C).cursorBackv0.0.0-alpha.2n columns (\x1b[<n>D).cursorNextLinev0.0.0-alpha.2n lines to column 1 (\x1b[<n>E).cursorPrevLinev0.0.0-alpha.2n lines to column 1 (\x1b[<n>F).cursorHorizontalAbsolutev0.0.0-alpha.2col on the current line (\x1b[<col>G).cursorTov0.0.0-alpha.2col and optional 1-based row (\x1b[<col>G or \x1b[<row>;<col>H).cursorMovev0.0.0-alpha.2dx columns and dy rows (dy defaults to 0).cursorHomev0.0.0-alpha.2\x1b[H).cursorSavev0.0.0-alpha.2\x1b7 / DECSC or \x1b[s).cursorRestorev0.0.0-alpha.2\x1b8 / DECRC or \x1b[u).cursorHidev0.0.0-alpha.2\x1b[?25l).cursorShowv0.0.0-alpha.2\x1b[?25h).cursorShapev0.0.0-alpha.2\x1b[<shape> q).eraseScreenv0.0.0-alpha.2\x1b[2J).eraseScreenToEndv0.0.0-alpha.2\x1b[0J or \x1b[J).eraseScreenToStartv0.0.0-alpha.2\x1b[1J).eraseScrollbackv0.0.0-alpha.2\x1b[3J).clearScreenv0.0.0-alpha.2\x1b[2J\x1b[3J\x1b[H or \x1b[2J\x1b[H).eraseLinev0.0.0-alpha.2\x1b[2K).eraseLineToEndv0.0.0-alpha.2\x1b[0K or \x1b[K).eraseLineToStartv0.0.0-alpha.2\x1b[1K).eraseLinesv0.0.0-alpha.2n lines starting from the current line upward and return the cursor to column 1.scrollUpv0.0.0-alpha.2n lines (\x1b[<n>S).scrollDownv0.0.0-alpha.2n lines (\x1b[<n>T).enterAltScreenv0.0.0-alpha.2\x1b[?1049h).exitAltScreenv0.0.0-alpha.2\x1b[?1049l).enableLineWrapv0.0.0-alpha.2\x1b[?7h).disableLineWrapv0.0.0-alpha.2\x1b[?7l).setTitlev0.0.0-alpha.2\x1b]0;<title>\x07 or ST), stripping control characters from title to prevent terminal inje...hyperlinkv0.0.0-alpha.2url and optional id to prevent terminal injec...syncOutputv0.0.0-alpha.2content in DEC 2026 synchronized output markers (\x1b[?2026h<content>\x1b[?2026l).syncOutputStartv0.0.0-alpha.2\x1b[?2026h).syncOutputEndv0.0.0-alpha.2\x1b[?2026l).beepv0.0.0-alpha.2"\x07").stripAnsiv0.0.0-alpha.2text.visibleWidthv0.0.0-alpha.2text, ignoring ANSI escape sequences, counting combining marks as width 0, and counting...truncatev0.0.0-alpha.2input to fit within maxWidth visible columns while preserving ANSI escape sequences and closing any active SGR styles before...wrapv0.0.0-alpha.2input to maxWidth visible columns while preserving active ANSI SGR styles across line breaks.detectColorLevelv0.0.0-alpha.20..3) from runtime environment and TTY capabilities.isColorEnabledv0.0.0-alpha.2true when ANSI color output is enabled in the current environment (detectColorLevel() > 0).ColorLevelValuev0.0.0-alpha.2detectColorLevel and exposed on ColorLevel.CursorShapeValuev0.0.0-alpha.2cursorShape and exposed on CursorShape.AnsiColorNamev0.0.0-alpha.2StyleOptions.fg and StyleOptions.bg.AnsiColorValuev0.0.0-alpha.2StyleOptions.fg and StyleOptions.bg: a named 16-color identifier, an ANSI 256-color index (0..=255)...ESCv0.0.0-alpha.2"\x1b").CSIv0.0.0-alpha.2"\x1b[").OSCv0.0.0-alpha.2"\x1b]").STv0.0.0-alpha.2"\x1b\\").BELv0.0.0-alpha.2"\x07").RESETv0.0.0-alpha.2"\x1b[0m").ColorLevelv0.0.0-alpha.2detectColorLevel.CursorShapev0.0.0-alpha.2cursorShape.Functions
Section titled “Functions”export function bold(text: string): string;
Wrap text in bold SGR codes (\x1b[1m...\x1b[22m), restoring outer
bold/dim state if nested.
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
import { bold } from "vael:ansi";
console.log(bold("Important"));export function dim(text: string): string;
Wrap text in dim/faint SGR codes (\x1b[2m...\x1b[22m).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
italic
Section titled “italic”export function italic(text: string): string;
Wrap text in italic SGR codes (\x1b[3m...\x1b[23m).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
underline
Section titled “underline”export function underline(text: string): string;
Wrap text in underline SGR codes (\x1b[4m...\x1b[24m).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
export function blink(text: string): string;
Wrap text in blink SGR codes (\x1b[5m...\x1b[25m).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
inverse
Section titled “inverse”export function inverse(text: string): string;
Wrap text in inverse/reverse-video SGR codes (\x1b[7m...\x1b[27m).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
hidden
Section titled “hidden”export function hidden(text: string): string;
Wrap text in hidden/conceal SGR codes (\x1b[8m...\x1b[28m).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
strikethrough
Section titled “strikethrough”export function strikethrough(text: string): string;
Wrap text in strikethrough SGR codes (\x1b[9m...\x1b[29m).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
overline
Section titled “overline”export function overline(text: string): string;
Wrap text in overline SGR codes (\x1b[53m...\x1b[55m).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
export function reset(text: string): string;
Wrap text with full SGR reset (\x1b[0m...\x1b[0m).
| Name | Type | Description |
|---|---|---|
text | string | Input string to wrap with reset sequences. |
string — Reset-wrapped string.TypeError— whentextis not a string.
export function black(text: string): string;
Style text with black foreground color (SGR 30).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
export function red(text: string): string;
Style text with red foreground color (SGR 31).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
export function green(text: string): string;
Style text with green foreground color (SGR 32).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
yellow
Section titled “yellow”export function yellow(text: string): string;
Style text with yellow foreground color (SGR 33).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
export function blue(text: string): string;
Style text with blue foreground color (SGR 34).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
magenta
Section titled “magenta”export function magenta(text: string): string;
Style text with magenta foreground color (SGR 35).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
export function cyan(text: string): string;
Style text with cyan foreground color (SGR 36).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
export function white(text: string): string;
Style text with white foreground color (SGR 37).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
export function gray(text: string): string;
Style text with gray (bright black) foreground color (SGR 90).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
brightBlack
Section titled “brightBlack”export function brightBlack(text: string): string;
Style text with bright black foreground color (SGR 90).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
brightRed
Section titled “brightRed”export function brightRed(text: string): string;
Style text with bright red foreground color (SGR 91).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
brightGreen
Section titled “brightGreen”export function brightGreen(text: string): string;
Style text with bright green foreground color (SGR 92).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
brightYellow
Section titled “brightYellow”export function brightYellow(text: string): string;
Style text with bright yellow foreground color (SGR 93).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
brightBlue
Section titled “brightBlue”export function brightBlue(text: string): string;
Style text with bright blue foreground color (SGR 94).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
brightMagenta
Section titled “brightMagenta”export function brightMagenta(text: string): string;
Style text with bright magenta foreground color (SGR 95).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
brightCyan
Section titled “brightCyan”export function brightCyan(text: string): string;
Style text with bright cyan foreground color (SGR 96).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
brightWhite
Section titled “brightWhite”export function brightWhite(text: string): string;
Style text with bright white foreground color (SGR 97).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
bgBlack
Section titled “bgBlack”export function bgBlack(text: string): string;
Style text with black background color (SGR 40).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
export function bgRed(text: string): string;
Style text with red background color (SGR 41).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
bgGreen
Section titled “bgGreen”export function bgGreen(text: string): string;
Style text with green background color (SGR 42).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
bgYellow
Section titled “bgYellow”export function bgYellow(text: string): string;
Style text with yellow background color (SGR 43).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
bgBlue
Section titled “bgBlue”export function bgBlue(text: string): string;
Style text with blue background color (SGR 44).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
bgMagenta
Section titled “bgMagenta”export function bgMagenta(text: string): string;
Style text with magenta background color (SGR 45).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
bgCyan
Section titled “bgCyan”export function bgCyan(text: string): string;
Style text with cyan background color (SGR 46).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
bgWhite
Section titled “bgWhite”export function bgWhite(text: string): string;
Style text with white background color (SGR 47).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
bgBrightBlack
Section titled “bgBrightBlack”export function bgBrightBlack(text: string): string;
Style text with bright black background color (SGR 100).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
bgBrightRed
Section titled “bgBrightRed”export function bgBrightRed(text: string): string;
Style text with bright red background color (SGR 101).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
bgBrightGreen
Section titled “bgBrightGreen”export function bgBrightGreen(text: string): string;
Style text with bright green background color (SGR 102).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
bgBrightYellow
Section titled “bgBrightYellow”export function bgBrightYellow(text: string): string;
Style text with bright yellow background color (SGR 103).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
bgBrightBlue
Section titled “bgBrightBlue”export function bgBrightBlue(text: string): string;
Style text with bright blue background color (SGR 104).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
bgBrightMagenta
Section titled “bgBrightMagenta”export function bgBrightMagenta(text: string): string;
Style text with bright magenta background color (SGR 105).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
bgBrightCyan
Section titled “bgBrightCyan”export function bgBrightCyan(text: string): string;
Style text with bright cyan background color (SGR 106).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
bgBrightWhite
Section titled “bgBrightWhite”export function bgBrightWhite(text: string): string;
Style text with bright white background color (SGR 107).
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
string — Styled string.TypeError— whentextis not a string.
rgb256
Section titled “rgb256”export function rgb256(code: number, text: string): string;
Style text with an ANSI 256-color palette foreground index (0..=255).
| Name | Type | Description |
|---|---|---|
code | number | Palette index integer in 0..=255. |
text | string | Input string to style. |
string — Styled string (\x1b[38;5;<code>m...\x1b[39m).TypeError— whencodeis not a number ortextis not a string.RangeError— whencodeis not an integer in0..=255.
import { rgb256 } from "vael:ansi";
console.log(rgb256(208, "Orange"));bgRgb256
Section titled “bgRgb256”export function bgRgb256(code: number, text: string): string;
Style text with an ANSI 256-color palette background index (0..=255).
| Name | Type | Description |
|---|---|---|
code | number | Palette index integer in 0..=255. |
text | string | Input string to style. |
string — Styled string (\x1b[48;5;<code>m...\x1b[49m).TypeError— whencodeis not a number ortextis not a string.RangeError— whencodeis not an integer in0..=255.
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).
| Name | Type | Description |
|---|---|---|
r | number | Red channel integer in 0..=255. |
g | number | Green channel integer in 0..=255. |
b | number | Blue channel integer in 0..=255. |
text | string | Input string to style. |
string — Styled string.TypeError— when any channel is not a number ortextis not a string.RangeError— when any channel is not an integer in0..=255.
import { rgb24 } from "vael:ansi";
console.log(rgb24(255, 136, 0, "Truecolor"));bgRgb24
Section titled “bgRgb24”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).
| Name | Type | Description |
|---|---|---|
r | number | Red channel integer in 0..=255. |
g | number | Green channel integer in 0..=255. |
b | number | Blue channel integer in 0..=255. |
text | string | Input string to style. |
string — Styled string.TypeError— when any channel is not a number ortextis not a string.RangeError— when any channel is not an integer in0..=255.
export function hex(color: string, text: string): string;
Style text with a 24-bit foreground color parsed from #rgb or #rrggbb.
| Name | Type | Description |
|---|---|---|
color | string | Hex color string ("#f0a" or "#112233", leading # optional if supported or required #rgb/#rrggbb). |
text | string | Input string to style. |
string — Styled string.TypeError— whencolorortextis not a string.RangeError— whencoloris not a valid hex color.
import { hex } from "vael:ansi";
console.log(hex("#ff8800", "Warm"));export function bgHex(color: string, text: string): string;
Style text with a 24-bit background color parsed from #rgb or #rrggbb.
| Name | Type | Description |
|---|---|---|
color | string | Hex color string ("#f0a" or "#112233"). |
text | string | Input string to style. |
string — Styled string.TypeError— whencolorortextis not a string.RangeError— whencoloris not a valid hex color.
export function style(text: string, options?: StyleOptions): string;
Apply multiple SGR attributes and foreground/background colors to text
in a single builder call.
| Name | Type | Description |
|---|---|---|
text | string | Input string to style. |
options optional | StyleOptions | Optional SGR attribute flags and fg/bg colors. |
string — Styled string (or text unchanged when options is undefined).TypeError— whentextis not a string oroptionsis provided and not an object.RangeError— when a color specification inoptionsis invalid.
import { style } from "vael:ansi";
console.log(style("Alert", { bold: true, underline: true, fg: "brightWhite", bg: "#aa0000" }));cursorUp
Section titled “cursorUp”export function cursorUp(n?: number): string;
Move the cursor up by n rows (\x1b[<n>A).
| Name | Type | Description |
|---|---|---|
n optional | number | Number of rows to move (defaults to 1). |
string — CSI cursor-up escape sequence.TypeError— whennis defined and not a number.RangeError— whennis negative,NaN, infinite, or non-integer.
cursorDown
Section titled “cursorDown”export function cursorDown(n?: number): string;
Move the cursor down by n rows (\x1b[<n>B).
| Name | Type | Description |
|---|---|---|
n optional | number | Number of rows to move (defaults to 1). |
string — CSI cursor-down escape sequence.TypeError— whennis defined and not a number.RangeError— whennis negative,NaN, infinite, or non-integer.
cursorForward
Section titled “cursorForward”export function cursorForward(n?: number): string;
Move the cursor forward (right) by n columns (\x1b[<n>C).
| Name | Type | Description |
|---|---|---|
n optional | number | Number of columns to move (defaults to 1). |
string — CSI cursor-forward escape sequence.TypeError— whennis defined and not a number.RangeError— whennis negative,NaN, infinite, or non-integer.
cursorBack
Section titled “cursorBack”export function cursorBack(n?: number): string;
Move the cursor back (left) by n columns (\x1b[<n>D).
| Name | Type | Description |
|---|---|---|
n optional | number | Number of columns to move (defaults to 1). |
string — CSI cursor-back escape sequence.TypeError— whennis defined and not a number.RangeError— whennis negative,NaN, infinite, or non-integer.
cursorNextLine
Section titled “cursorNextLine”export function cursorNextLine(n?: number): string;
Move the cursor down n lines to column 1 (\x1b[<n>E).
| Name | Type | Description |
|---|---|---|
n optional | number | Number of lines to move (defaults to 1). |
string — CSI cursor-next-line escape sequence.TypeError— whennis defined and not a number.RangeError— whennis negative,NaN, infinite, or non-integer.
cursorPrevLine
Section titled “cursorPrevLine”export function cursorPrevLine(n?: number): string;
Move the cursor up n lines to column 1 (\x1b[<n>F).
| Name | Type | Description |
|---|---|---|
n optional | number | Number of lines to move (defaults to 1). |
string — CSI cursor-previous-line escape sequence.TypeError— whennis defined and not a number.RangeError— whennis negative,NaN, infinite, or non-integer.
cursorHorizontalAbsolute
Section titled “cursorHorizontalAbsolute”export function cursorHorizontalAbsolute(col?: number): string;
Move the cursor to 1-based column col on the current line (\x1b[<col>G).
| Name | Type | Description |
|---|---|---|
col optional | number | 1-based column index (defaults to 1). |
string — CSI cursor-horizontal-absolute escape sequence.TypeError— whencolis defined and not a number.RangeError— whencolis< 1,NaN, infinite, or non-integer.
cursorTo
Section titled “cursorTo”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).
| Name | Type | Description |
|---|---|---|
col | number | 1-based column index. |
row optional | number | Optional 1-based row index. |
string — CSI cursor positioning escape sequence.TypeError— whencolor definedrowis not a number.RangeError— when coordinates are< 1,NaN, infinite, or non-integer.
cursorMove
Section titled “cursorMove”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).
| Name | Type | Description |
|---|---|---|
dx | number | Relative horizontal offset (positive right, negative left). |
dy optional | number | Optional relative vertical offset (positive down, negative up; defaults to 0). |
string — Concatenated CSI cursor movement sequences (empty string if both are 0).TypeError— whendxor defineddyis not a number.RangeError— whendxordyisNaN, infinite, or non-integer.
cursorHome
Section titled “cursorHome”export function cursorHome(): string;
Move the cursor to the top-left home position (\x1b[H).
string — CSI cursor-home escape sequence.cursorSave
Section titled “cursorSave”export function cursorSave(): string;
Save the current cursor position (\x1b7 / DECSC or \x1b[s).
string — Cursor-save escape sequence.cursorRestore
Section titled “cursorRestore”export function cursorRestore(): string;
Restore the previously saved cursor position (\x1b8 / DECRC or \x1b[u).
string — Cursor-restore escape sequence.cursorHide
Section titled “cursorHide”export function cursorHide(): string;
Hide the terminal cursor (\x1b[?25l).
string — DEC private mode hide-cursor escape sequence.cursorShow
Section titled “cursorShow”export function cursorShow(): string;
Show the terminal cursor (\x1b[?25h).
string — DEC private mode show-cursor escape sequence.cursorShape
Section titled “cursorShape”export function cursorShape(shape?: CursorShapeValue): string;
Set the terminal cursor shape via DECSCUSR (\x1b[<shape> q).
| Name | Type | Description |
|---|---|---|
shape optional | CursorShapeValue | Cursor shape value (0..=6, defaults to 0 / CursorShape.DEFAULT). |
string — DECSCUSR escape sequence.TypeError— whenshapeis defined and not a number.RangeError— whenshapeis not an integer in0..=6.
eraseScreen
Section titled “eraseScreen”export function eraseScreen(): string;
Erase the entire screen (\x1b[2J).
string — CSI erase-screen escape sequence.eraseScreenToEnd
Section titled “eraseScreenToEnd”export function eraseScreenToEnd(): string;
Erase from the cursor to the end of the screen (\x1b[0J or \x1b[J).
string — CSI erase-to-end-of-screen escape sequence.eraseScreenToStart
Section titled “eraseScreenToStart”export function eraseScreenToStart(): string;
Erase from the start of the screen to the cursor (\x1b[1J).
string — CSI erase-to-start-of-screen escape sequence.eraseScrollback
Section titled “eraseScrollback”export function eraseScrollback(): string;
Erase the terminal scrollback buffer (\x1b[3J).
string — CSI erase-scrollback escape sequence.clearScreen
Section titled “clearScreen”export function clearScreen(): string;
Clear the screen and move the cursor home (\x1b[2J\x1b[3J\x1b[H or \x1b[2J\x1b[H).
string — Screen-clear escape sequence.eraseLine
Section titled “eraseLine”export function eraseLine(): string;
Erase the entire current line (\x1b[2K).
string — CSI erase-line escape sequence.eraseLineToEnd
Section titled “eraseLineToEnd”export function eraseLineToEnd(): string;
Erase from the cursor to the end of the current line (\x1b[0K or \x1b[K).
string — CSI erase-to-end-of-line escape sequence.eraseLineToStart
Section titled “eraseLineToStart”export function eraseLineToStart(): string;
Erase from the start of the current line to the cursor (\x1b[1K).
string — CSI erase-to-start-of-line escape sequence.eraseLines
Section titled “eraseLines”export function eraseLines(n: number): string;
Erase n lines starting from the current line upward and return the cursor
to column 1.
| Name | Type | Description |
|---|---|---|
n | number | Number of lines to erase (non-negative integer). |
string — Escape sequence erasing n lines.TypeError— whennis not a number.RangeError— whennis negative,NaN, infinite, or non-integer.
scrollUp
Section titled “scrollUp”export function scrollUp(n?: number): string;
Scroll the viewport up by n lines (\x1b[<n>S).
| Name | Type | Description |
|---|---|---|
n optional | number | Number of lines to scroll (defaults to 1). |
string — CSI scroll-up escape sequence.TypeError— whennis defined and not a number.RangeError— whennis negative,NaN, infinite, or non-integer.
scrollDown
Section titled “scrollDown”export function scrollDown(n?: number): string;
Scroll the viewport down by n lines (\x1b[<n>T).
| Name | Type | Description |
|---|---|---|
n optional | number | Number of lines to scroll (defaults to 1). |
string — CSI scroll-down escape sequence.TypeError— whennis defined and not a number.RangeError— whennis negative,NaN, infinite, or non-integer.
enterAltScreen
Section titled “enterAltScreen”export function enterAltScreen(): string;
Switch to the terminal alternate screen buffer (\x1b[?1049h).
string — Alternate screen enter escape sequence.exitAltScreen
Section titled “exitAltScreen”export function exitAltScreen(): string;
Return from the terminal alternate screen buffer (\x1b[?1049l).
string — Alternate screen exit escape sequence.enableLineWrap
Section titled “enableLineWrap”export function enableLineWrap(): string;
Enable automatic terminal line wrapping (\x1b[?7h).
string — DEC private mode enable-line-wrap escape sequence.disableLineWrap
Section titled “disableLineWrap”export function disableLineWrap(): string;
Disable automatic terminal line wrapping (\x1b[?7l).
string — DEC private mode disable-line-wrap escape sequence.setTitle
Section titled “setTitle”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.
| Name | Type | Description |
|---|---|---|
title | string | Desired terminal title string. |
string — Sanitized OSC title escape sequence.TypeError— whentitleis not a string.
hyperlink
Section titled “hyperlink”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.
| Name | Type | Description |
|---|---|---|
text | string | Visible link label text. |
url | string | Target hyperlink URL. |
id optional | string | Optional OSC 8 id parameter grouping multi-span links. |
string — Sanitized OSC 8 hyperlink sequence wrapping text.TypeError— whentext,url, or definedidis not a string.
import { hyperlink } from "vael:ansi";
console.log(hyperlink("VaelJS", "https://vaeljs.com"));syncOutput
Section titled “syncOutput”export function syncOutput(content: string): string;
Wrap content in DEC 2026 synchronized output markers
(\x1b[?2026h<content>\x1b[?2026l).
| Name | Type | Description |
|---|---|---|
content | string | Frame payload to bracket in synchronized output markers. |
string — Bracketed output string.TypeError— whencontentis not a string.
syncOutputStart
Section titled “syncOutputStart”export function syncOutputStart(): string;
Begin a DEC 2026 synchronized output frame (\x1b[?2026h).
string — Synchronized output start escape sequence.syncOutputEnd
Section titled “syncOutputEnd”export function syncOutputEnd(): string;
End a DEC 2026 synchronized output frame (\x1b[?2026l).
string — Synchronized output end escape sequence.export function beep(): string;
Return the terminal audible/visual bell character ("\x07").
string — ASCII BEL sequence.stripAnsi
Section titled “stripAnsi”export function stripAnsi(text: string): string;
Remove all ANSI CSI, OSC, and escape sequences from text.
| Name | Type | Description |
|---|---|---|
text | string | Input string potentially containing ANSI escape sequences. |
string — Plain string without ANSI escape sequences.TypeError— whentextis not a string.
import { red, stripAnsi } from "vael:ansi";
console.log(stripAnsi(red("Hello"))); // "Hello"visibleWidth
Section titled “visibleWidth”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.
| Name | Type | Description |
|---|---|---|
text | string | Input string (may contain ANSI escape sequences). |
number — Non-negative display column width.TypeError— whentextis not a string.
import { bold, visibleWidth } from "vael:ansi";
console.log(visibleWidth(bold("hi"))); // 2truncate
Section titled “truncate”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.
| Name | Type | Description |
|---|---|---|
input | string | Input string (may contain ANSI escape sequences). |
maxWidth | number | Maximum visible column width (>= 0). |
options optional | TruncateOptions | Optional truncation settings (ellipsis). |
string — Truncated string whose visible width is <= maxWidth.TypeError— wheninputis not a string,maxWidthis not a number, oroptionsis invalid.RangeError— whenmaxWidthis negative,NaN, infinite, or non-integer.
import { green, truncate } from "vael:ansi";
console.log(truncate(green("hello world"), 8));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.
| Name | Type | Description |
|---|---|---|
input | string | Input string (may contain ANSI escape sequences). |
maxWidth | number | Maximum visible column width per line (>= 1). |
options optional | WrapOptions | Optional wrapping settings (hard). |
string — Wrapped multi-line string.TypeError— wheninputis not a string,maxWidthis not a number, oroptionsis invalid.RangeError— whenmaxWidthis< 1,NaN, infinite, or non-integer.
import { cyan, wrap } from "vael:ansi";
console.log(wrap(cyan("alpha beta gamma"), 10));detectColorLevel
Section titled “detectColorLevel”export function detectColorLevel(): ColorLevelValue;
Detect the terminal’s supported ANSI color level (0..3) from runtime
environment and TTY capabilities.
isColorEnabled
Section titled “isColorEnabled”export function isColorEnabled(): boolean;
Return true when ANSI color output is enabled in the current environment
(detectColorLevel() > 0).
boolean — Whether ANSI color output is enabled.Interfaces
Section titled “Interfaces”StyleOptions
Section titled “StyleOptions”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.
| Property | Type | Description | Since |
|---|---|---|---|
bold optional | boolean | Apply bold / increased intensity (SGR 1). | v0.0.0-alpha.2 |
dim optional | boolean | Apply dim / faint intensity (SGR 2). | v0.0.0-alpha.2 |
italic optional | boolean | Apply italic emphasis (SGR 3). | v0.0.0-alpha.2 |
underline optional | boolean | Apply underline (SGR 4). | v0.0.0-alpha.2 |
blink optional | boolean | Apply slow blink (SGR 5). | v0.0.0-alpha.2 |
inverse optional | boolean | Swap foreground and background colors (SGR 7). | v0.0.0-alpha.2 |
hidden optional | boolean | Conceal text (SGR 8). | v0.0.0-alpha.2 |
strikethrough optional | boolean | Apply strikethrough (SGR 9). | v0.0.0-alpha.2 |
overline optional | boolean | Apply overline (SGR 53). | v0.0.0-alpha.2 |
fg optional | AnsiColorValue | Foreground color specification. | v0.0.0-alpha.2 |
bg optional | AnsiColorValue | Background color specification. | v0.0.0-alpha.2 |
TruncateOptions
Section titled “TruncateOptions”export interface TruncateOptions {
ellipsis?: string;
}
Options accepted by truncate.
| Property | Type | Description | Since |
|---|---|---|---|
ellipsis optional | string | Trailing indicator appended when text exceeds maxWidth. Defaults to "…". | v0.0.0-alpha.2 |
WrapOptions
Section titled “WrapOptions”export interface WrapOptions {
hard?: boolean;
}
Options accepted by wrap.
| Property | Type | Description | Since |
|---|---|---|---|
hard optional | boolean | Break words longer than maxWidth mid-word instead of overflowing. Defaults to false. | v0.0.0-alpha.2 |
Type Aliases
Section titled “Type Aliases”ColorLevelValue
Section titled “ColorLevelValue”export type ColorLevelValue = 0 | 1 | 2 | 3;
Supported terminal color capability levels returned by detectColorLevel
and exposed on ColorLevel.
0(NONE): no color support1(BASIC): 16-color ANSI SGR2(ANSI256): 256-color palette3(TRUECOLOR): 24-bit RGB truecolor
CursorShapeValue
Section titled “CursorShapeValue”export type CursorShapeValue = 0 | 1 | 2 | 3 | 4 | 5 | 6;
DECSCUSR cursor shape values accepted by cursorShape and exposed on
CursorShape.
AnsiColorName
Section titled “AnsiColorName”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.
AnsiColorValue
Section titled “AnsiColorValue”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.
Constants
Section titled “Constants”export const ESC: "\x1b";
ASCII Escape character ("\x1b").
export const CSI: "\x1b[";
Control Sequence Introducer ("\x1b[").
export const OSC: "\x1b]";
Operating System Command introducer ("\x1b]").
export const ST: "\x1b\\";
String Terminator ("\x1b\\").
export const BEL: "\x07";
ASCII Bell character ("\x07").
export const RESET: "\x1b[0m";
SGR full attribute reset sequence ("\x1b[0m").
ColorLevel
Section titled “ColorLevel”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.
CursorShape
Section titled “CursorShape”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.
