Skip to content

ANSI Reference

Coverage License NPM Version Open Issues Size

📟 Functional CLI ANSI formatting functions.

Usage

📦 Node

Install @lou.codes/ansi as a dependency:

Terminal window
1
pnpm add @lou.codes/ansi
2
# or
3
npm install @lou.codes/ansi
4
# or
5
yarn add @lou.codes/ansi

Import it and use it:

1
import { foregroundRed } from "@lou.codes/ansi";
2
3
foregroundRed`Hello world!`; // "Hello world!" in red text.

🦕 Deno

Import @lou.codes/ansi using the npm: prefix, and use it directly:

1
import { foregroundRed } from "npm:@lou.codes/ansi";
2
3
foregroundRed`Hello world!`; // "Hello world!" in red text.

🌎 Browser

Import @lou.codes/ansi using esm.sh, and use it directly:

1
<script type="module">
2
import { foregroundRed } from "https://esm.sh/@lou.codes/ansi";
3
4
foregroundRed`Hello world!`; // "Hello world!" in red text.
5
</script>

Background

backgroundBlack()

1
function backgroundBlack<Input>(
2
input: Input,
3
...expressions: ReadOnlyArray
4
): `${Input extends string ? Input<Input> : string}`;

Black background code wrapper.

Type parameters

Type parameter
Input extends string | TemplateStringsArray

Parameters

ParameterType
inputInput
expressionsReadOnlyArray

Returns

`${Input extends string ? Input<Input> : string}`

input string with black background.

Remarks

Given an input string, it will return a new string with the ANSI codes for black background around it.

Example

1
backgroundBlack("Lou"); // "\u001B[40mLou\u001B[49m"
2
// It can also be used as a tag function for tagged templates:
3
backgroundBlack`Lou`; // "\u001B[40mLou\u001B[49m"

See

View source


backgroundBlue()

1
function backgroundBlue<Input>(
2
input: Input,
3
...expressions: ReadOnlyArray
4
): `${Input extends string ? Input<Input> : string}`;

Blue background code wrapper.

Type parameters

Type parameter
Input extends string | TemplateStringsArray

Parameters

ParameterType
inputInput
expressionsReadOnlyArray

Returns

`${Input extends string ? Input<Input> : string}`

input string with blue background.

Remarks

Given an input string, it will return a new string with the ANSI codes for blue background around it.

Example

1
backgroundBlue("Lou"); // "\u001B[44mLou\u001B[49m"
2
// It can also be used as a tag function for tagged templates:
3
backgroundBlue`Lou`; // "\u001B[44mLou\u001B[49m"

See

View source


backgroundBrightBlue()

1
function backgroundBrightBlue<Input>(
2
input: Input,
3
...expressions: ReadOnlyArray
4
): `${Input extends string ? Input<Input> : string}`;

Bright blue background code wrapper.

Type parameters

Type parameter
Input extends string | TemplateStringsArray

Parameters

ParameterType
inputInput
expressionsReadOnlyArray

Returns

`${Input extends string ? Input<Input> : string}`

input string with bright blue background.

Remarks

Given an input string, it will return a new string with the ANSI codes for bright blue background around it.

Example

1
backgroundBrightBlue("Lou"); // "\u001B[104mLou\u001B[49m"
2
// It can also be used as a tag function for tagged templates:
3
backgroundBrightBlue`Lou`; // "\u001B[104mLou\u001B[49m"

See

View source


backgroundBrightCyan()

1
function backgroundBrightCyan<Input>(
2
input: Input,
3
...expressions: ReadOnlyArray
4
): `${Input extends string ? Input<Input> : string}`;

Bright cyan background code wrapper.

Type parameters

Type parameter
Input extends string | TemplateStringsArray

Parameters

ParameterType
inputInput
expressionsReadOnlyArray

Returns

`${Input extends string ? Input<Input> : string}`

input string with bright cyan background.

Remarks

Given an input string, it will return a new string with the ANSI codes for bright cyan background around it.

Example

1
backgroundBrightCyan("Lou"); // "\u001B[106mLou\u001B[49m"
2
// It can also be used as a tag function for tagged templates:
3
backgroundBrightCyan`Lou`; // "\u001B[106mLou\u001B[49m"

See

View source


backgroundBrightGreen()

1
function backgroundBrightGreen<Input>(
2
input: Input,
3
...expressions: ReadOnlyArray
4
): `${Input extends string ? Input<Input> : string}`;

Bright green background code wrapper.

Type parameters

Type parameter
Input extends string | TemplateStringsArray

Parameters

ParameterType
inputInput
expressionsReadOnlyArray

Returns

`${Input extends string ? Input<Input> : string}`

input string with bright green background.

Remarks

Given an input string, it will return a new string with the ANSI codes for bright green background around it.

Example

1
backgroundBrightGreen("Lou"); // "\u001B[102mLou\u001B[49m"
2
// It can also be used as a tag function for tagged templates:
3
backgroundBrightGreen`Lou`; // "\u001B[102mLou\u001B[49m"

See

View source


backgroundBrightMagenta()

1
function backgroundBrightMagenta<Input>(
2
input: Input,
3
...expressions: ReadOnlyArray
4
): `${Input extends string ? Input<Input> : string}`;

Bright magenta background code wrapper.

Type parameters

Type parameter
Input extends string | TemplateStringsArray

Parameters

ParameterType
inputInput
expressionsReadOnlyArray

Returns

`${Input extends string ? Input<Input> : string}`

input string with bright magenta background.

Remarks

Given an input string, it will return a new string with the ANSI codes for bright magenta background around it.

Example

1
backgroundBrightMagenta("Lou"); // "\u001B[105mLou\u001B[49m"
2
// It can also be used as a tag function for tagged templates:
3
backgroundBrightMagenta`Lou`; // "\u001B[105mLou\u001B[49m"

See

View source


backgroundBrightRed()

1
function backgroundBrightRed<Input>(
2
input: Input,
3
...expressions: ReadOnlyArray
4
): `${Input extends string ? Input<Input> : string}`;

Bright red background code wrapper.

Type parameters

Type parameter
Input extends string | TemplateStringsArray

Parameters

ParameterType
inputInput
expressionsReadOnlyArray

Returns

`${Input extends string ? Input<Input> : string}`

input string with bright red background.

Remarks

Given an input string, it will return a new string with the ANSI codes for bright red background around it.

Example

1
backgroundBrightRed("Lou"); // "\u001B[101mLou\u001B[49m"
2
// It can also be used as a tag function for tagged templates:
3
backgroundBrightRed`Lou`; // "\u001B[101mLou\u001B[49m"

See

View source


backgroundBrightWhite()

1
function backgroundBrightWhite<Input>(
2
input: Input,
3
...expressions: ReadOnlyArray
4
): `${Input extends string ? Input<Input> : string}`;

Bright white background code wrapper.

Type parameters

Type parameter
Input extends string | TemplateStringsArray

Parameters

ParameterType
inputInput
expressionsReadOnlyArray

Returns

`${Input extends string ? Input<Input> : string}`

input string with bright white background.

Remarks

Given an input string, it will return a new string with the ANSI codes for bright white background around it.

Example

1
backgroundBrightWhite("Lou"); // "\u001B[107mLou\u001B[49m"
2
// It can also be used as a tag function for tagged templates:
3
backgroundBrightWhite`Lou`; // "\u001B[107mLou\u001B[49m"

See

View source


backgroundBrightYellow()

1
function backgroundBrightYellow<Input>(
2
input: Input,
3
...expressions: ReadOnlyArray
4
): `${Input extends string ? Input<Input> : string}`;

Bright yellow background code wrapper.

Type parameters

Type parameter
Input extends string | TemplateStringsArray

Parameters

ParameterType
inputInput
expressionsReadOnlyArray

Returns

`${Input extends string ? Input<Input> : string}`

input string with bright yellow background.

Remarks

Given an input string, it will return a new string with the ANSI codes for bright yellow background around it.

Example

1
backgroundBrightYellow("Lou"); // "\u001B[103mLou\u001B[49m"
2
// It can also be used as a tag function for tagged templates:
3
backgroundBrightYellow`Lou`; // "\u001B[103mLou\u001B[49m"

See

View source


backgroundColor()

1
function backgroundColor<Open>(
2
open: Open,
3
): <Input>(
4
input: Input,
5
...expressions: ReadOnlyArray
6
) => `[${Open extends readonly [Maybe<number>, Maybe<number>] ? `${Open<Open>[0] extends number ? any[any] : ""};${Open<Open>[1] extends number ? any[any] : ""}` : `${Open}`}m${Input extends string ? Input<Input> : string}`;

Background color code wrapper.

Type parameters

Type parameter
Open extends number

Parameters

ParameterType
openOpen

Returns

Function

Curried function with close ANSI code for background in context.

format function with close and open set.

Type parameters
Type parameter
Input extends string | TemplateStringsArray
Parameters
ParameterTypeDescription
inputInputInput string or TemplateStringArray (when using tagged templates).
expressionsReadOnlyArrayInput expressions (when using tagged templates)
Returns

`[${Open extends readonly [Maybe<number>, Maybe<number>] ? `${Open<Open>[0] extends number ? any[any] : ""};${Open<Open>[1] extends number ? any[any] : ""}` : `${Open}`}m${Input extends string ? Input<Input> : string}`

Formatted input string.

See

format

Remarks

Takes an open ANSI code and an input string and adds the open and close ANSI codes to that string (for background color).

Example

1
backgroundColor(13)("Lou"); // "\u001B[13mLou\u001B[49m"
2
// It can also be used as a tag function for tagged templates:
3
backgroundColor(13)`Lou`; // "\u001B[13mLou\u001B[49m"

See

View source


backgroundCyan()

1
function backgroundCyan<Input>(
2
input: Input,
3
...expressions: ReadOnlyArray
4
): `${Input extends string ? Input<Input> : string}`;

Cyan background code wrapper.

Type parameters

Type parameter
Input extends string | TemplateStringsArray

Parameters

ParameterType
inputInput
expressionsReadOnlyArray

Returns

`${Input extends string ? Input<Input> : string}`

input string with cyan background.

Remarks

Given an input string, it will return a new string with the ANSI codes for cyan background around it.

Example

1
backgroundCyan("Lou"); // "\u001B[46mLou\u001B[49m"
2
// It can also be used as a tag function for tagged templates:
3
backgroundCyan`Lou`; // "\u001B[46mLou\u001B[49m"

See

View source


backgroundGray()

1
function backgroundGray<Input>(
2
input: Input,
3
...expressions: ReadOnlyArray
4
): `${Input extends string ? Input<Input> : string}`;

Gray background code wrapper.

Type parameters

Type parameter
Input extends string | TemplateStringsArray

Parameters

ParameterType
inputInput
expressionsReadOnlyArray

Returns

`${Input extends string ? Input<Input> : string}`

input string with gray background.

Remarks

Given an input string, it will return a new string with the ANSI codes for gray background around it.

Example

1
backgroundGray("Lou"); // "\u001B[100mLou\u001B[49m"
2
// It can also be used as a tag function for tagged templates:
3
backgroundGray`Lou`; // "\u001B[100mLou\u001B[49m"

See

View source


backgroundGreen()

1
function backgroundGreen<Input>(
2
input: Input,
3
...expressions: ReadOnlyArray
4
): `${Input extends string ? Input<Input> : string}`;

Green background code wrapper.

Type parameters

Type parameter
Input extends string | TemplateStringsArray

Parameters

ParameterType
inputInput
expressionsReadOnlyArray

Returns

`${Input extends string ? Input<Input> : string}`

input string with green background.

Remarks

Given an input string, it will return a new string with the ANSI codes for green background around it.

Example

1
backgroundGreen("Lou"); // "\u001B[42mLou\u001B[49m"
2
// It can also be used as a tag function for tagged templates:
3
backgroundGreen`Lou`; // "\u001B[42mLou\u001B[49m"

See

View source


backgroundMagenta()

1
function backgroundMagenta<Input>(
2
input: Input,
3
...expressions: ReadOnlyArray
4
): `${Input extends string ? Input<Input> : string}`;

Magenta background code wrapper.

Type parameters

Type parameter
Input extends string | TemplateStringsArray

Parameters

ParameterType
inputInput
expressionsReadOnlyArray

Returns

`${Input extends string ? Input<Input> : string}`

input string with magenta background.

Remarks

Given an input string, it will return a new string with the ANSI codes for magenta background around it.

Example

1
backgroundMagenta("Lou"); // "\u001B[45mLou\u001B[49m"
2
// It can also be used as a tag function for tagged templates:
3
backgroundMagenta`Lou`; // "\u001B[45mLou\u001B[49m"

See

View source


backgroundRed()

1
function backgroundRed<Input>(
2
input: Input,
3
...expressions: ReadOnlyArray
4
): `${Input extends string ? Input<Input> : string}`;

Red background code wrapper.

Type parameters

Type parameter
Input extends string | TemplateStringsArray

Parameters

ParameterType
inputInput
expressionsReadOnlyArray

Returns

`${Input extends string ? Input<Input> : string}`

input string with red background.

Remarks

Given an input string, it will return a new string with the ANSI codes for red background around it.

Example

1
backgroundRed("Lou"); // "\u001B[41mLou\u001B[49m"
2
// It can also be used as a tag function for tagged templates:
3
backgroundRed`Lou`; // "\u001B[41mLou\u001B[49m"

See

View source


backgroundWhite()

1
function backgroundWhite<Input>(
2
input: Input,
3
...expressions: ReadOnlyArray
4
): `${Input extends string ? Input<Input> : string}`;

White background code wrapper.

Type parameters

Type parameter
Input extends string | TemplateStringsArray

Parameters

ParameterType
inputInput
expressionsReadOnlyArray

Returns

`${Input extends string ? Input<Input> : string}`

input string with white background.

Remarks

Given an input string, it will return a new string with the ANSI codes for white background around it.

Example

1
backgroundWhite("Lou"); // "\u001B[47mLou\u001B[49m"
2
// It can also be used as a tag function for tagged templates:
3
backgroundWhite`Lou`; // "\u001B[47mLou\u001B[49m"

See

View source


backgroundYellow()

1
function backgroundYellow<Input>(
2
input: Input,
3
...expressions: ReadOnlyArray
4
): `${Input extends string ? Input<Input> : string}`;

Yellow background code wrapper.

Type parameters

Type parameter
Input extends string | TemplateStringsArray

Parameters

ParameterType
inputInput
expressionsReadOnlyArray

Returns

`${Input extends string ? Input<Input> : string}`

input string with yellow background.

Remarks

Given an input string, it will return a new string with the ANSI codes for yellow background around it.

Example

1
backgroundYellow("Lou"); // "\u001B[43mLou\u001B[49m"
2
// It can also be used as a tag function for tagged templates:
3
backgroundYellow`Lou`; // "\u001B[43mLou\u001B[49m"

See

View source

Common

Formatter()

1
type Formatter: (templateStrings: TemplateStringsArray | string, ...expressions: ReadOnlyArray) => string;

Formatter function that takes a string or a tagged template.

Remarks

Type to represent a function that works both directly on a string or as a tagged template function.

Example

1
const formatter: Formatter = (input, ...expressions) =>
2
typeof input === "string" ? input : (
3
input
4
.flatMap((string, index) => [string, expressions[index] ?? ""])
5
.join("")
6
);
7
8
formatter("Lou"); // "Lou"
9
formatter`Lou`; // "Lou"

See

Tagged templates

Parameters

ParameterType
templateStringsTemplateStringsArray | string
expressionsReadOnlyArray

Returns

string

View source


resetToInitialState

1
const resetToInitialState: "\u001bc";

RIS sequence.

Remarks

Resets the entire screen to initial state.

Example

1
console.log(resetToInitialState); // "\u001B[c"
2
stdout.write(resetToInitialState); // Resets the entire screen to initial state.

See

View source


controlSequenceIntroducer()

1
function controlSequenceIntroducer<Code>(
2
code: Code,
3
): <Input>(
4
input: Input,
5
) => `[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${Input<Input>[0] extends number ? any[any] : ""};${Input<Input>[1] extends number ? any[any] : ""}` : `${Input & number}`}${Code}`;

CSI sequence generator.

Type parameters

Type parameterDescription
Code extends stringCSI code generic.

Parameters

ParameterTypeDescription
codeCodeCSI code.

Returns

Function

Curried function with code in context.

Takes an input number and returns the CSI sequence.

Type parameters
Type parameterDescription
Input extends number | readonly [Maybe<number>, Maybe<number>]CSI input generic.
Parameters
ParameterTypeDescription
inputInputCSI input.
Returns

`[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${Input<Input>[0] extends number ? any[any] : ""};${Input<Input>[1] extends number ? any[any] : ""}` : `${Input & number}`}${Code}`

CSI sequence.

See

Remarks

Takes a code and an input number and returns the CSI sequence.

Example

1
const selectGraphicRendition = controlSequenceIntroducer("m");
2
selectGraphicRendition(13); // "\u001B[13m"
3
selectGraphicRendition(42); // "\u001B[42m"

See

View source


escapeSequence()

1
function escapeSequence<Input>(input: Input): `${Input}`;

Takes an input string and returns an escaped sequence based on it.

Type parameters

Type parameterDescription
Input extends stringString to escape generic.

Parameters

ParameterTypeDescription
inputInputString to escape.

Returns

`${Input}`

String with ESC character prepended.

Remarks

Escape sequences are used to control the cursor, change colors, and more in the terminal. They are preceded by the ESC character (ASCII code 27, or 0x1b). This functions prepends any given string with the ESC character.

Example

1
escapeSequence("Lou"); // "\x1bLou"

See

ANSI escape code

View source


format()

1
function format<Close>(
2
close: Close,
3
): <Open>(
4
open: Open,
5
) => <Input>(
6
input: Input,
7
...expressions: ReadOnlyArray
8
) => `[${Open extends readonly [Maybe<number>, Maybe<number>] ? `${Open<Open>[0] extends number ? any[any] : ""};${Open<Open>[1] extends number ? any[any] : ""}` : `${Open}`}m${Input extends string ? Input<Input> : string}[${Close extends readonly [Maybe<number>, Maybe<number>] ? `${Close<Close>[0] extends number ? any[any] : ""};${Close<Close>[1] extends number ? any[any] : ""}` : `${Close}`}m`;

Format wrapper function.

Type parameters

Type parameterDescription
Close extends numberClose string generic.

Parameters

ParameterTypeDescription
closeCloseClose string.

Returns

Function

Curried function with close in context.

format function with close set.

Type parameters
Type parameterDescription
Open extends numberOpen string generic.
Parameters
ParameterTypeDescription
openOpenOpen string.
Returns

Function

Curried function with close and open in context.

format function with close and open set.

Type parameters
Type parameter
Input extends string | TemplateStringsArray
Parameters
ParameterTypeDescription
inputInputInput string or TemplateStringArray (when using tagged templates).
expressionsReadOnlyArrayInput expressions (when using tagged templates)
Returns

`[${Open extends readonly [Maybe<number>, Maybe<number>] ? `${Open<Open>[0] extends number ? any[any] : ""};${Open<Open>[1] extends number ? any[any] : ""}` : `${Open}`}m${Input extends string ? Input<Input> : string}[${Close extends readonly [Maybe<number>, Maybe<number>] ? `${Close<Close>[0] extends number ? any[any] : ""};${Close<Close>[1] extends number ? any[any] : ""}` : `${Close}`}m`

Formatted input string.

See

format

See

format

Remarks

Given an open, a close string and an input string, return formatted input (surrounded by open and close).

Example

1
format(13)(42)("Lou"); // "\u001B[42mLou\u001B[13m"
2
// It can also be used as a tag function for tagged templates:
3
format(13)(42)`Lou`; // "\u001B[42mLou\u001B[13m"

See

View source


mix()

1
function mix(...formatters: ReadOnlyArray<Formatter>): Formatter;

Composes formatters.

Parameters

ParameterTypeDescription
formattersReadOnlyArray<Formatter>Array of formatters to be composed.

Returns

Formatter

Formatter composed of the given formatters.

Remarks

Given an array of formatters, it will return a new formatter that will apply all of them to the input string.

Example

1
const redTextWhiteBackground = mix(foregroundRed, backgroundWhite);
2
3
redTextWhiteBackground("Lou");
4
// It can also be used as a tag function for tagged templates:
5
redTextWhiteBackground`Lou`;

See

Formatter

View source


normalizeString()

1
function normalizeString<Input>(
2
input: Input,
3
...expressions: ReadOnlyArray
4
): Input extends string ? Input<Input> : string;

Takes a string or a template string and returns a plain string.

Type parameters

Type parameter
Input extends string | TemplateStringsArray

Parameters

ParameterTypeDescription
inputInputString or template string.
expressionsReadOnlyArrayPossible values passed to the template string.

Returns

Input extends string ? Input<Input> : string

Plain string.

Example

1
normalizeString(`Hello ${13}!`); // "Hello 13!"
2
normalizeString`Hello ${13}!`; // "Hello 13!"

See

Tagged templates

View source


optionalFormat()

1
function optionalFormat<Close>(
2
close: Close,
3
): <Open>(
4
open: Open,
5
) => <Input>(
6
input: Input,
7
...expressions: ReadOnlyArray
8
) => `[${Open extends readonly [Maybe<number>, Maybe<number>] ? `${Open<Open>[0] extends number ? any[any] : ""};${Open<Open>[1] extends number ? any[any] : ""}` : `${Open}`}m${Input extends string ? Input<Input> : string}[${Close extends readonly [Maybe<number>, Maybe<number>] ? `${Close<Close>[0] extends number ? any[any] : ""};${Close<Close>[1] extends number ? any[any] : ""}` : `${Close}`}m`;

Process dependant format function.

Type parameters

Type parameter
Close extends number

Parameters

ParameterType
closeClose

Returns

Function

Either the formatted string, or just the passed string.

format function with close set.

Type parameters
Type parameterDescription
Open extends numberOpen string generic.
Parameters
ParameterTypeDescription
openOpenOpen string.
Returns

Function

Curried function with close and open in context.

format function with close and open set.

Type parameters
Type parameter
Input extends string | TemplateStringsArray
Parameters
ParameterTypeDescription
inputInputInput string or TemplateStringArray (when using tagged templates).
expressionsReadOnlyArrayInput expressions (when using tagged templates)
Returns

`[${Open extends readonly [Maybe<number>, Maybe<number>] ? `${Open<Open>[0] extends number ? any[any] : ""};${Open<Open>[1] extends number ? any[any] : ""}` : `${Open}`}m${Input extends string ? Input<Input> : string}[${Close extends readonly [Maybe<number>, Maybe<number>] ? `${Close<Close>[0] extends number ? any[any] : ""};${Close<Close>[1] extends number ? any[any] : ""}` : `${Close}`}m`

Formatted input string.

See

format

See

format

Remarks

Impure version of format which changes depending on the current NodeJS globalThis.process environment.

Example

1
// In a environment with color:
2
optionalFormat(42)(13)("Lou"); // "\u001B[42mLou\u001B[13m"
3
// In an environment without color:
4
optionalFormat(42)(13)("Lou"); // "Lou"
5
// It also works with tagged templates:
6
optionalFormat(42)(13)`Lou`; // "\u001B[42mLou\u001B[13m"

See

View source


selectGraphicRendition()

1
function selectGraphicRendition<Input>(
2
input: Input,
3
): `[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${Input<Input>[0] extends number ? any[any] : ""};${Input<Input>[1] extends number ? any[any] : ""}` : `${Input & number}`}m`;

Takes an input number and returns the a SGR sequence.

Type parameters

Type parameter
Input extends number | readonly [Maybe<number>, Maybe<number>]

Parameters

ParameterTypeDescription
inputInputInput to escape.

Returns

`[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${Input<Input>[0] extends number ? any[any] : ""};${Input<Input>[1] extends number ? any[any] : ""}` : `${Input & number}`}m`

SGR sequence.

Example

1
controlSequenceIntroducer(13); // "\u001B[13m"
2
controlSequenceIntroducer(42); // "\u001B[42m"

See

View source

Cursor

cursorBack()

1
function cursorBack<Input>(
2
input: Input,
3
): `[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${Input<Input>[0] extends number ? any[any] : ""};${Input<Input>[1] extends number ? any[any] : ""}` : `${Input & number}`}D`;

Moves the cursor input cells back.

Type parameters

Type parameter
Input extends number | readonly [Maybe<number>, Maybe<number>]

Parameters

ParameterTypeDescription
inputInputAmount of cells back.

Returns

`[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${Input<Input>[0] extends number ? any[any] : ""};${Input<Input>[1] extends number ? any[any] : ""}` : `${Input & number}`}D`

CUB sequence.

Remarks

If the cursor is already at the edge of the screen, this has no effect.

Example

1
cursorBack(13); // "\u001B[13C"

See

View source


cursorDown()

1
function cursorDown<Input>(
2
input: Input,
3
): `[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${Input<Input>[0] extends number ? any[any] : ""};${Input<Input>[1] extends number ? any[any] : ""}` : `${Input & number}`}B`;

Moves the cursor input cells down.

Type parameters

Type parameter
Input extends number | readonly [Maybe<number>, Maybe<number>]

Parameters

ParameterTypeDescription
inputInputAmount of cells down.

Returns

`[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${Input<Input>[0] extends number ? any[any] : ""};${Input<Input>[1] extends number ? any[any] : ""}` : `${Input & number}`}B`

CUD sequence.

Remarks

If the cursor is already at the edge of the screen, this has no effect.

Example

1
cursorDown(13); // "\u001B[13B"

See

View source


cursorForward()

1
function cursorForward<Input>(
2
input: Input,
3
): `[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${Input<Input>[0] extends number ? any[any] : ""};${Input<Input>[1] extends number ? any[any] : ""}` : `${Input & number}`}C`;

Moves the cursor input cells forward.

Type parameters

Type parameter
Input extends number | readonly [Maybe<number>, Maybe<number>]

Parameters

ParameterTypeDescription
inputInputAmount of cells forward.

Returns

`[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${Input<Input>[0] extends number ? any[any] : ""};${Input<Input>[1] extends number ? any[any] : ""}` : `${Input & number}`}C`

CUF sequence.

Remarks

If the cursor is already at the edge of the screen, this has no effect.

Example

1
cursorForward(13); // "\u001B[13C"

See

View source


cursorHorizontalAbsolute()

1
function cursorHorizontalAbsolute<Input>(
2
input: Input,
3
): `[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${Input<Input>[0] extends number ? any[any] : ""};${Input<Input>[1] extends number ? any[any] : ""}` : `${Input & number}`}G`;

Moves cursor to the column input.

Type parameters

Type parameter
Input extends number | readonly [Maybe<number>, Maybe<number>]

Parameters

ParameterTypeDescription
inputInputColumn number.

Returns

`[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${Input<Input>[0] extends number ? any[any] : ""};${Input<Input>[1] extends number ? any[any] : ""}` : `${Input & number}`}G`

CHA sequence.

Example

1
cursorHorizontalAbsolute(13); // "\u001B[13G"

See

View source


cursorNextLine()

1
function cursorNextLine<Input>(
2
input: Input,
3
): `[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${Input<Input>[0] extends number ? any[any] : ""};${Input<Input>[1] extends number ? any[any] : ""}` : `${Input & number}`}E`;

Moves cursor to beginning of the line input lines down.

Type parameters

Type parameter
Input extends number | readonly [Maybe<number>, Maybe<number>]

Parameters

ParameterTypeDescription
inputInputAmount of lines down.

Returns

`[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${Input<Input>[0] extends number ? any[any] : ""};${Input<Input>[1] extends number ? any[any] : ""}` : `${Input & number}`}E`

CNL sequence.

Example

1
cursorNextLine(13); // "\u001B[13E"

See

View source


cursorPosition()

1
function cursorPosition<Input>(
2
input: Input,
3
): `[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${Input<Input>[0] extends number ? any[any] : ""};${Input<Input>[1] extends number ? any[any] : ""}` : `${Input & number}`}H`;

Moves the cursor to position input.

Type parameters

Type parameter
Input extends number | readonly [Maybe<number>, Maybe<number>]

Parameters

ParameterTypeDescription
inputInputPosition (row, column)

Returns

`[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${Input<Input>[0] extends number ? any[any] : ""};${Input<Input>[1] extends number ? any[any] : ""}` : `${Input & number}`}H`

CUP sequence.

Example

1
cursorPosition([13, 42]); // "\u001B[13;42H"
2
cursorPosition([undefined, 42]); // "\u001B[;42H"
3
cursorPosition([13, undefined]); // "\u001B[13;H"

See

View source


cursorPreviousLine()

1
function cursorPreviousLine<Input>(
2
input: Input,
3
): `[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${Input<Input>[0] extends number ? any[any] : ""};${Input<Input>[1] extends number ? any[any] : ""}` : `${Input & number}`}F`;

Moves cursor to beginning of the line input lines up.

Type parameters

Type parameter
Input extends number | readonly [Maybe<number>, Maybe<number>]

Parameters

ParameterTypeDescription
inputInputAmount of lines up.

Returns

`[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${Input<Input>[0] extends number ? any[any] : ""};${Input<Input>[1] extends number ? any[any] : ""}` : `${Input & number}`}F`

CPL sequence.

Example

1
cursorPreviousLine(13); // "\u001B[13F"

See

View source


cursorUp()

1
function cursorUp<Input>(
2
input: Input,
3
): `[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${Input<Input>[0] extends number ? any[any] : ""};${Input<Input>[1] extends number ? any[any] : ""}` : `${Input & number}`}A`;

Moves the cursor input cells up.

Type parameters

Type parameter
Input extends number | readonly [Maybe<number>, Maybe<number>]

Parameters

ParameterTypeDescription
inputInputAmount of cells up.

Returns

`[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${Input<Input>[0] extends number ? any[any] : ""};${Input<Input>[1] extends number ? any[any] : ""}` : `${Input & number}`}A`

CUU sequence.

Remarks

If the cursor is already at the edge of the screen, this has no effect.

Example

1
cursorUp(13); // "\u001B[13A"

See

View source

Erase

eraseInDisplay()

1
function eraseInDisplay<Input>(
2
input: Input,
3
): `[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${Input<Input>[0] extends number ? any[any] : ""};${Input<Input>[1] extends number ? any[any] : ""}` : `${Input & number}`}J`;

Clear screen from cursor to beginning, to end of screen, or entire screen.

Type parameters

Type parameter
Input extends number | readonly [Maybe<number>, Maybe<number>]

Parameters

ParameterTypeDescription
inputInput0 (to end of screen), 1 (to beginning of screen), or 2 (entire screen).

Returns

`[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${Input<Input>[0] extends number ? any[any] : ""};${Input<Input>[1] extends number ? any[any] : ""}` : `${Input & number}`}J`

ED sequence.

Example

1
eraseInDisplay(0); // "\u001B[0J" Clear from cursor to end of screen.
2
eraseInDisplay(1); // "\u001B[1J" Clear from cursor to beginning of screen.
3
eraseInDisplay(2); // "\u001B[2J" Clear entire screen.

See

View source


eraseInLine()

1
function eraseInLine<Input>(
2
input: Input,
3
): `[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${Input<Input>[0] extends number ? any[any] : ""};${Input<Input>[1] extends number ? any[any] : ""}` : `${Input & number}`}K`;

Erases the line from cursor to beginning, to end of line, or entire line.

Type parameters

Type parameter
Input extends number | readonly [Maybe<number>, Maybe<number>]

Parameters

ParameterTypeDescription
inputInput0 (to end of line), 1 (to beginning of line), or 2 (entire line).

Returns

`[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${Input<Input>[0] extends number ? any[any] : ""};${Input<Input>[1] extends number ? any[any] : ""}` : `${Input & number}`}K`

EL sequence.

Remarks

inputerases…
0…to end of line.
1…to beginning of line.
2…entire line.

Example

1
eraseInLine(0); // "\u001B[0K" Clear from cursor to end of line.
2
eraseInLine(1); // "\u001B[1K" Clear from cursor to beginning of line.
3
eraseInLine(2); // "\u001B[2K" Clear entire line.

See

CSI (Control Sequence Introducer) sequences

View source

Foreground

foregroundBlack()

1
function foregroundBlack<Input>(
2
input: Input,
3
...expressions: ReadOnlyArray
4
): `${Input extends string ? Input<Input> : string}`;

Black foreground code wrapper.

Type parameters

Type parameter
Input extends string | TemplateStringsArray

Parameters

ParameterType
inputInput
expressionsReadOnlyArray

Returns

`${Input extends string ? Input<Input> : string}`

input string with black foreground.

Remarks

Given an input string, it will return a new string with the ANSI codes for black foreground.

Example

1
foregroundBlack("Lou"); // "\u001B[30mLou\u001B[39m"
2
// It can also be used as a tag function for tagged templates:
3
foregroundBlack`Lou`; // "\u001B[30mLou\u001B[39m"

See

View source


foregroundBlue()

1
function foregroundBlue<Input>(
2
input: Input,
3
...expressions: ReadOnlyArray
4
): `${Input extends string ? Input<Input> : string}`;

Blue foreground code wrapper.

Type parameters

Type parameter
Input extends string | TemplateStringsArray

Parameters

ParameterType
inputInput
expressionsReadOnlyArray

Returns

`${Input extends string ? Input<Input> : string}`

input string with blue foreground.

Remarks

Given an input string, it will return a new string with the ANSI codes for blue foreground.

Example

1
foregroundBlue("Lou"); // "\u001B[34mLou\u001B[39m"
2
// It can also be used as a tag function for tagged templates:
3
foregroundBlue`Lou`; // "\u001B[34mLou\u001B[39m"

See

View source


foregroundBrightBlue()

1
function foregroundBrightBlue<Input>(
2
input: Input,
3
...expressions: ReadOnlyArray
4
): `${Input extends string ? Input<Input> : string}`;

Bright blue foreground code wrapper.

Type parameters

Type parameter
Input extends string | TemplateStringsArray

Parameters

ParameterType
inputInput
expressionsReadOnlyArray

Returns

`${Input extends string ? Input<Input> : string}`

input string with bright blue foreground.

Remarks

Given an input string, it will return a new string with the ANSI codes for bright blue foreground.

Example

1
foregroundBrightBlue("Lou"); // "\u001B[94mLou\u001B[39m"
2
// It can also be used as a tag function for tagged templates:
3
foregroundBrightBlue`Lou`; // "\u001B[94mLou\u001B[39m"

See

View source


foregroundBrightCyan()

1
function foregroundBrightCyan<Input>(
2
input: Input,
3
...expressions: ReadOnlyArray
4
): `${Input extends string ? Input<Input> : string}`;

Bright Cyan foreground code wrapper.

Type parameters

Type parameter
Input extends string | TemplateStringsArray

Parameters

ParameterType
inputInput
expressionsReadOnlyArray

Returns

`${Input extends string ? Input<Input> : string}`

input string with bright cyan foreground.

Remarks

Given an input string, it will return a new string with the ANSI codes for bright Cyan foreground.

Example

1
foregroundBrightCyan("Lou"); // "\u001B[96mLou\u001B[39m"
2
// It can also be used as a tag function for tagged templates:
3
foregroundBrightCyan`Lou`; // "\u001B[96mLou\u001B[39m"

See

View source


foregroundBrightGreen()

1
function foregroundBrightGreen<Input>(
2
input: Input,
3
...expressions: ReadOnlyArray
4
): `${Input extends string ? Input<Input> : string}`;

Bright green foreground code wrapper.

Type parameters

Type parameter
Input extends string | TemplateStringsArray

Parameters

ParameterType
inputInput
expressionsReadOnlyArray

Returns

`${Input extends string ? Input<Input> : string}`

input string with bright green foreground.

Remarks

Given an input string, it will return a new string with the ANSI codes for bright green foreground.

Example

1
foregroundBrightGreen("Lou"); // "\u001B[92mLou\u001B[39m"
2
// It can also be used as a tag function for tagged templates:
3
foregroundBrightGreen`Lou`; // "\u001B[92mLou\u001B[39m"

See

View source


foregroundBrightMagenta()

1
function foregroundBrightMagenta<Input>(
2
input: Input,
3
...expressions: ReadOnlyArray
4
): `${Input extends string ? Input<Input> : string}`;

Bright magenta foreground code wrapper.

Type parameters

Type parameter
Input extends string | TemplateStringsArray

Parameters

ParameterType
inputInput
expressionsReadOnlyArray

Returns

`${Input extends string ? Input<Input> : string}`

input string with bright magenta foreground.

Remarks

Given an input string, it will return a new string with the ANSI codes for bright magenta foreground.

Example

1
foregroundBrightMagenta("Lou"); // "\u001B[95mLou\u001B[39m"
2
// It can also be used as a tag function for tagged templates:
3
foregroundBrightMagenta`Lou`; // "\u001B[95mLou\u001B[39m"

See

View source


foregroundBrightRed()

1
function foregroundBrightRed<Input>(
2
input: Input,
3
...expressions: ReadOnlyArray
4
): `${Input extends string ? Input<Input> : string}`;

Bright red foreground code wrapper.

Type parameters

Type parameter
Input extends string | TemplateStringsArray

Parameters

ParameterType
inputInput
expressionsReadOnlyArray

Returns

`${Input extends string ? Input<Input> : string}`

input string with bright red foreground.

Remarks

Given an input string, it will return a new string with the ANSI codes for bright red foreground.

Example

1
foregroundBrightRed("Lou"); // "\u001B[91mLou\u001B[39m"
2
// It can also be used as a tag function for tagged templates:
3
foregroundBrightRed`Lou`; // "\u001B[91mLou\u001B[39m"

See

View source


foregroundBrightWhite()

1
function foregroundBrightWhite<Input>(
2
input: Input,
3
...expressions: ReadOnlyArray
4
): `${Input extends string ? Input<Input> : string}`;

Bright white foreground code wrapper.

Type parameters

Type parameter
Input extends string | TemplateStringsArray

Parameters

ParameterType
inputInput
expressionsReadOnlyArray

Returns

`${Input extends string ? Input<Input> : string}`

input string with bright white foreground.

Remarks

Given an input string, it will return a new string with the ANSI codes for bright white foreground.

Example

1
foregroundBrightWhite("Lou"); // "\u001B[97mLou\u001B[39m"
2
// It can also be used as a tag function for tagged templates:
3
foregroundBrightWhite`Lou`; // "\u001B[97mLou\u001B[39m"

See

View source


foregroundBrightYellow()

1
function foregroundBrightYellow<Input>(
2
input: Input,
3
...expressions: ReadOnlyArray
4
): `${Input extends string ? Input<Input> : string}`;

Bright yellow foreground code wrapper.

Type parameters

Type parameter
Input extends string | TemplateStringsArray

Parameters

ParameterType
inputInput
expressionsReadOnlyArray

Returns

`${Input extends string ? Input<Input> : string}`

input string with bright yellow foreground.

Remarks

Given an input string, it will return a new string with the ANSI codes for bright yellow foreground.

Example

1
foregroundBrightYellow("Lou"); // "\u001B[93mLou\u001B[39m"
2
// It can also be used as a tag function for tagged templates:
3
foregroundBrightYellow`Lou`; // "\u001B[93mLou\u001B[39m"

See

View source


foregroundColor()

1
function foregroundColor<Open>(
2
open: Open,
3
): <Input>(
4
input: Input,
5
...expressions: ReadOnlyArray
6
) => `[${Open extends readonly [Maybe<number>, Maybe<number>] ? `${Open<Open>[0] extends number ? any[any] : ""};${Open<Open>[1] extends number ? any[any] : ""}` : `${Open}`}m${Input extends string ? Input<Input> : string}`;

Foreground color code wrapper.

Type parameters

Type parameter
Open extends number

Parameters

ParameterType
openOpen

Returns

Function

Curried function with close ANSI code for foreground in context.

format function with close and open set.

Type parameters
Type parameter
Input extends string | TemplateStringsArray
Parameters
ParameterTypeDescription
inputInputInput string or TemplateStringArray (when using tagged templates).
expressionsReadOnlyArrayInput expressions (when using tagged templates)
Returns

`[${Open extends readonly [Maybe<number>, Maybe<number>] ? `${Open<Open>[0] extends number ? any[any] : ""};${Open<Open>[1] extends number ? any[any] : ""}` : `${Open}`}m${Input extends string ? Input<Input> : string}`

Formatted input string.

See

format

Remarks

Takes an open ANSI code and an input string and adds the open and close ANSI codes to that string (for foreground color).

Example

1
foregroundColor(13)("Lou"); // "\u001B[13mLou\u001B[39m"
2
// It can also be used as a tag function for tagged templates:
3
foregroundColor(13)`Lou`; // "\u001B[13mLou\u001B[39m"

See

View source


foregroundCyan()

1
function foregroundCyan<Input>(
2
input: Input,
3
...expressions: ReadOnlyArray
4
): `${Input extends string ? Input<Input> : string}`;

Cyan foreground code wrapper.

Type parameters

Type parameter
Input extends string | TemplateStringsArray

Parameters

ParameterType
inputInput
expressionsReadOnlyArray

Returns

`${Input extends string ? Input<Input> : string}`

input string with cyan foreground.

Remarks

Given an input string, it will return a new string with the ANSI codes for cyan foreground.

Example

1
foregroundCyan("Lou"); // "\u001B[36mLou\u001B[39m"
2
// It can also be used as a tag function for tagged templates:
3
foregroundCyan`Lou`; // "\u001B[36mLou\u001B[39m"

See

View source


foregroundGray()

1
function foregroundGray<Input>(
2
input: Input,
3
...expressions: ReadOnlyArray
4
): `${Input extends string ? Input<Input> : string}`;

Gray foreground code wrapper.

Type parameters

Type parameter
Input extends string | TemplateStringsArray

Parameters

ParameterType
inputInput
expressionsReadOnlyArray

Returns

`${Input extends string ? Input<Input> : string}`

input string with gray foreground.

Remarks

Given an input string, it will return a new string with the ANSI codes for gray foreground.

Example

1
foregroundGray("Lou"); // "\u001B[90mLou\u001B[39m"
2
// It can also be used as a tag function for tagged templates:
3
foregroundGray`Lou`; // "\u001B[90mLou\u001B[39m"

See

View source


foregroundGreen()

1
function foregroundGreen<Input>(
2
input: Input,
3
...expressions: ReadOnlyArray
4
): `${Input extends string ? Input<Input> : string}`;

Green foreground code wrapper.

Type parameters

Type parameter
Input extends string | TemplateStringsArray

Parameters

ParameterType
inputInput
expressionsReadOnlyArray

Returns

`${Input extends string ? Input<Input> : string}`

input string with green foreground.

Remarks

Given an input string, it will return a new string with the ANSI codes for green foreground.

Example

1
foregroundGreen("Lou"); // "\u001B[32mLou\u001B[39m"
2
// It can also be used as a tag function for tagged templates:
3
foregroundGreen`Lou`; // "\u001B[32mLou\u001B[39m"

See

View source


foregroundMagenta()

1
function foregroundMagenta<Input>(
2
input: Input,
3
...expressions: ReadOnlyArray
4
): `${Input extends string ? Input<Input> : string}`;

Magenta foreground code wrapper.

Type parameters

Type parameter
Input extends string | TemplateStringsArray

Parameters

ParameterType
inputInput
expressionsReadOnlyArray

Returns

`${Input extends string ? Input<Input> : string}`

input string with magenta foreground.

Remarks

Given an input string, it will return a new string with the ANSI codes for magenta foreground.

Example

1
foregroundMagenta("Lou"); // "\u001B[35mLou\u001B[39m"
2
// It can also be used as a tag function for tagged templates:
3
foregroundMagenta`Lou`; // "\u001B[35mLou\u001B[39m"

See

View source


foregroundRed()

1
function foregroundRed<Input>(
2
input: Input,
3
...expressions: ReadOnlyArray
4
): `${Input extends string ? Input<Input> : string}`;

Red foreground code wrapper.

Type parameters

Type parameter
Input extends string | TemplateStringsArray

Parameters

ParameterType
inputInput
expressionsReadOnlyArray

Returns

`${Input extends string ? Input<Input> : string}`

input string with red foreground.

Remarks

Given an input string, it will return a new string with the ANSI codes for red foreground.

Example

1
foregroundRed("Lou"); // "\u001B[31mLou\u001B[39m"
2
// It can also be used as a tag function for tagged templates:
3
foregroundRed`Lou`; // "\u001B[31mLou\u001B[39m"

See

View source


foregroundWhite()

1
function foregroundWhite<Input>(
2
input: Input,
3
...expressions: ReadOnlyArray
4
): `${Input extends string ? Input<Input> : string}`;

White foreground code wrapper.

Type parameters

Type parameter
Input extends string | TemplateStringsArray

Parameters

ParameterType
inputInput
expressionsReadOnlyArray

Returns

`${Input extends string ? Input<Input> : string}`

input string with white foreground.

Remarks

Given an input string, it will return a new string with the ANSI codes for white foreground.

Example

1
foregroundWhite("Lou"); // "\u001B[37mLou\u001B[39m"
2
// It can also be used as a tag function for tagged templates:
3
foregroundWhite`Lou`; // "\u001B[37mLou\u001B[39m"

See

View source


foregroundYellow()

1
function foregroundYellow<Input>(
2
input: Input,
3
...expressions: ReadOnlyArray
4
): `${Input extends string ? Input<Input> : string}`;

Yellow foreground code wrapper.

Type parameters

Type parameter
Input extends string | TemplateStringsArray

Parameters

ParameterType
inputInput
expressionsReadOnlyArray

Returns

`${Input extends string ? Input<Input> : string}`

input string with yellow foreground.

Remarks

Given an input string, it will return a new string with the ANSI codes for yellow foreground.

Example

1
foregroundYellow("Lou"); // "\u001B[33mLou\u001B[39m"
2
// It can also be used as a tag function for tagged templates:
3
foregroundYellow`Lou`; // "\u001B[33mLou\u001B[39m"

See

View source

Scroll

scrollDown()

1
function scrollDown<Input>(
2
input: Input,
3
): `[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${Input<Input>[0] extends number ? any[any] : ""};${Input<Input>[1] extends number ? any[any] : ""}` : `${Input & number}`}S`;

Scroll whole page down by input lines. New lines are added at the top.

Type parameters

Type parameter
Input extends number | readonly [Maybe<number>, Maybe<number>]

Parameters

ParameterTypeDescription
inputInputAmount of lines down.

Returns

`[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${Input<Input>[0] extends number ? any[any] : ""};${Input<Input>[1] extends number ? any[any] : ""}` : `${Input & number}`}S`

SD sequence.

Example

1
scrollDown(13); // "\u001B[13S"

See

View source


scrollUp()

1
function scrollUp<Input>(
2
input: Input,
3
): `[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${Input<Input>[0] extends number ? any[any] : ""};${Input<Input>[1] extends number ? any[any] : ""}` : `${Input & number}`}S`;

Scroll whole page up by input lines. New lines are added at the bottom.

Type parameters

Type parameter
Input extends number | readonly [Maybe<number>, Maybe<number>]

Parameters

ParameterTypeDescription
inputInputAmount of lines up.

Returns

`[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${Input<Input>[0] extends number ? any[any] : ""};${Input<Input>[1] extends number ? any[any] : ""}` : `${Input & number}`}S`

SU sequence.

Example

1
scrollUp(13); // "\u001B[13S"

See

View source

Text

bold()

1
function bold<Input>(
2
input: Input,
3
...expressions: ReadOnlyArray
4
): `${Input extends string ? Input<Input> : string}`;

Bold code wrapper.

Type parameters

Type parameter
Input extends string | TemplateStringsArray

Parameters

ParameterType
inputInput
expressionsReadOnlyArray

Returns

`${Input extends string ? Input<Input> : string}`

input string with bold format.

Remarks

Given an input string, it will return a new string with the ANSI codes for bold around it.

Example

1
bold("Lou"); // "\u001B[1mLou\u001B[22m"
2
// It can also be used as a tag function for tagged templates:
3
bold`Lou`; // "\u001B[1mLou\u001B[22m"

See

View source


dimmed()

1
function dimmed<Input>(
2
input: Input,
3
...expressions: ReadOnlyArray
4
): `${Input extends string ? Input<Input> : string}`;

Dimmed code wrapper.

Type parameters

Type parameter
Input extends string | TemplateStringsArray

Parameters

ParameterType
inputInput
expressionsReadOnlyArray

Returns

`${Input extends string ? Input<Input> : string}`

input string with dimmed format.

Remarks

Given an input string, it will return a new string with the ANSI codes for dimmed around it.

Example

1
dimmed("Lou"); // "\u001B[2mLou\u001B[22m"
2
// It can also be used as a tag function for tagged templates:
3
dimmed`Lou`; // "\u001B[2mLou\u001B[22m"

See

View source


inverse()

1
function inverse<Input>(
2
input: Input,
3
...expressions: ReadOnlyArray
4
): `${Input extends string ? Input<Input> : string}`;

Inverse code wrapper.

Type parameters

Type parameter
Input extends string | TemplateStringsArray

Parameters

ParameterType
inputInput
expressionsReadOnlyArray

Returns

`${Input extends string ? Input<Input> : string}`

input string with inverse format.

Remarks

Given an input string, it will return a new string with the ANSI codes for inverse around it.

Example

1
inverse("Lou"); // "\u001B[7mLou\u001B[27m"
2
// It can also be used as a tag function for tagged templates:
3
inverse`Lou`; // "\u001B[7mLou\u001B[27m"

See

View source


italic()

1
function italic<Input>(
2
input: Input,
3
...expressions: ReadOnlyArray
4
): `${Input extends string ? Input<Input> : string}`;

Italic code wrapper.

Type parameters

Type parameter
Input extends string | TemplateStringsArray

Parameters

ParameterType
inputInput
expressionsReadOnlyArray

Returns

`${Input extends string ? Input<Input> : string}`

input string with italic format.

Remarks

Given an input string, it will return a new string with the ANSI codes for italic around it.

Example

1
italic("Lou"); // "\u001B[3mLou\u001B[23m"
2
// It can also be used as a tag function for tagged templates:
3
italic`Lou`; // "\u001B[3mLou\u001B[23m"

See

View source


strikethrough()

1
function strikethrough<Input>(
2
input: Input,
3
...expressions: ReadOnlyArray
4
): `${Input extends string ? Input<Input> : string}`;

Takes an input string and adds the ANSI codes for strikethrough text.

Type parameters

Type parameter
Input extends string | TemplateStringsArray

Parameters

ParameterType
inputInput
expressionsReadOnlyArray

Returns

`${Input extends string ? Input<Input> : string}`

input string with strikethrough format.

Example

1
strikethrough("Lou"); // "\u001B[9mLou\u001B[29m"
2
// It can also be used as a tag function for tagged templates:
3
strikethrough`Lou`; // "\u001B[9mLou\u001B[29m"

See

optionalFormat

View source


underlined()

1
function underlined<Input>(
2
input: Input,
3
...expressions: ReadOnlyArray
4
): `${Input extends string ? Input<Input> : string}`;

Takes an input string and adds the ANSI codes for underlined text.

Type parameters

Type parameter
Input extends string | TemplateStringsArray

Parameters

ParameterType
inputInput
expressionsReadOnlyArray

Returns

`${Input extends string ? Input<Input> : string}`

input string with underlined format.

Example

1
underlined("Lou"); // "\u001B[4mLou\u001B[24m"
2
// It can also be used as a tag function for tagged templates:
3
underlined`Lou`; // "\u001B[4mLou\u001B[24m"

See

optionalFormat

View source