ANSI Reference
📟 Functional CLI ANSI formatting functions.
Usage
📦 Node
Install @lou.codes/ansi
as a dependency:
Import it and use it:
🦕 Deno
Import @lou.codes/ansi
using the npm:
prefix, and use it directly:
🌎 Browser
Import @lou.codes/ansi
using esm.sh, and use it directly:
Useful links
- 📝 Documentation: TypeDoc generated documentation.
- ⏳ Changelog: List of changes between versions.
- ✅ Tests Coverage: Coveralls page with tests coverage.
Background
backgroundBlack
▸ backgroundBlack<Input
>(input
, ...expressions
): `[40m${Input
extends string ? Input<Input> : string}[49m`
Black background code wrapper.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type |
---|---|
input | Input |
...expressions | ReadOnlyArray |
Returns
`[40m${Input extends string ? Input<Input> : string}[49m`
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
See
backgroundBlue
▸ backgroundBlue<Input
>(input
, ...expressions
): `[44m${Input
extends string ? Input<Input> : string}[49m`
Blue background code wrapper.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type |
---|---|
input | Input |
...expressions | ReadOnlyArray |
Returns
`[44m${Input extends string ? Input<Input> : string}[49m`
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
See
backgroundBrightBlue
▸ backgroundBrightBlue<Input
>(input
, ...expressions
):
`[104m${Input extends string ? Input<Input> : string}[49m`
Bright blue background code wrapper.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type |
---|---|
input | Input |
...expressions | ReadOnlyArray |
Returns
`[104m${Input extends string ? Input<Input> : string}[49m`
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
See
backgroundBrightCyan
▸ backgroundBrightCyan<Input
>(input
, ...expressions
):
`[106m${Input extends string ? Input<Input> : string}[49m`
Bright cyan background code wrapper.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type |
---|---|
input | Input |
...expressions | ReadOnlyArray |
Returns
`[106m${Input extends string ? Input<Input> : string}[49m`
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
See
backgroundBrightGreen
▸ backgroundBrightGreen<Input
>(input
, ...expressions
):
`[102m${Input extends string ? Input<Input> : string}[49m`
Bright green background code wrapper.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type |
---|---|
input | Input |
...expressions | ReadOnlyArray |
Returns
`[102m${Input extends string ? Input<Input> : string}[49m`
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
See
backgroundBrightMagenta
▸ backgroundBrightMagenta<Input
>(input
, ...expressions
):
`[105m${Input extends string ? Input<Input> : string}[49m`
Bright magenta background code wrapper.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type |
---|---|
input | Input |
...expressions | ReadOnlyArray |
Returns
`[105m${Input extends string ? Input<Input> : string}[49m`
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
See
backgroundBrightRed
▸ backgroundBrightRed<Input
>(input
, ...expressions
): `[101m${Input
extends string ? Input<Input> : string}[49m`
Bright red background code wrapper.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type |
---|---|
input | Input |
...expressions | ReadOnlyArray |
Returns
`[101m${Input extends string ? Input<Input> : string}[49m`
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
See
backgroundBrightWhite
▸ backgroundBrightWhite<Input
>(input
, ...expressions
):
`[107m${Input extends string ? Input<Input> : string}[49m`
Bright white background code wrapper.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type |
---|---|
input | Input |
...expressions | ReadOnlyArray |
Returns
`[107m${Input extends string ? Input<Input> : string}[49m`
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
See
backgroundBrightYellow
▸ backgroundBrightYellow<Input
>(input
, ...expressions
):
`[103m${Input extends string ? Input<Input> : string}[49m`
Bright yellow background code wrapper.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type |
---|---|
input | Input |
...expressions | ReadOnlyArray |
Returns
`[103m${Input extends string ? Input<Input> : string}[49m`
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
See
backgroundColor
▸ backgroundColor<Open
>(open
): <Input>(input
: Input
,
…expressions
: ReadOnlyArray
) =>
`[${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}[49m`
Background color code wrapper.
Type parameters
Name | Type |
---|---|
Open | extends number |
Parameters
Name | Type |
---|---|
open | Open |
Returns
fn
Curried function with close
ANSI code for background in context.
▸ <Input
>(input
, ...expressions
):
`[${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}[49m`
format function with close
and open
set.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type | Description |
---|---|---|
input | Input | Input string or TemplateStringArray (when using tagged templates). |
...expressions | ReadOnlyArray | Input 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}[49m`
Formatted input
string.
See
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
See
backgroundCyan
▸ backgroundCyan<Input
>(input
, ...expressions
): `[46m${Input
extends string ? Input<Input> : string}[49m`
Cyan background code wrapper.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type |
---|---|
input | Input |
...expressions | ReadOnlyArray |
Returns
`[46m${Input extends string ? Input<Input> : string}[49m`
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
See
backgroundGray
▸ backgroundGray<Input
>(input
, ...expressions
): `[100m${Input
extends string ? Input<Input> : string}[49m`
Gray background code wrapper.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type |
---|---|
input | Input |
...expressions | ReadOnlyArray |
Returns
`[100m${Input extends string ? Input<Input> : string}[49m`
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
See
backgroundGreen
▸ backgroundGreen<Input
>(input
, ...expressions
): `[42m${Input
extends string ? Input<Input> : string}[49m`
Green background code wrapper.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type |
---|---|
input | Input |
...expressions | ReadOnlyArray |
Returns
`[42m${Input extends string ? Input<Input> : string}[49m`
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
See
backgroundMagenta
▸ backgroundMagenta<Input
>(input
, ...expressions
): `[45m${Input
extends string ? Input<Input> : string}[49m`
Magenta background code wrapper.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type |
---|---|
input | Input |
...expressions | ReadOnlyArray |
Returns
`[45m${Input extends string ? Input<Input> : string}[49m`
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
See
backgroundRed
▸ backgroundRed<Input
>(input
, ...expressions
): `[41m${Input
extends string ? Input<Input> : string}[49m`
Red background code wrapper.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type |
---|---|
input | Input |
...expressions | ReadOnlyArray |
Returns
`[41m${Input extends string ? Input<Input> : string}[49m`
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
See
backgroundWhite
▸ backgroundWhite<Input
>(input
, ...expressions
): `[47m${Input
extends string ? Input<Input> : string}[49m`
White background code wrapper.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type |
---|---|
input | Input |
...expressions | ReadOnlyArray |
Returns
`[47m${Input extends string ? Input<Input> : string}[49m`
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
See
backgroundYellow
▸ backgroundYellow<Input
>(input
, ...expressions
): `[43m${Input
extends string ? Input<Input> : string}[49m`
Yellow background code wrapper.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type |
---|---|
input | Input |
...expressions | ReadOnlyArray |
Returns
`[43m${Input extends string ? Input<Input> : string}[49m`
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
See
Common
Formatter
Ƭ 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
See
Type declaration
▸ (templateStrings
, ...expressions
): string
Parameters
Name | Type |
---|---|
templateStrings | TemplateStringsArray | string |
...expressions | ReadOnlyArray |
Returns
string
resetToInitialState
• Const
resetToInitialState: "\u001bc"
RIS sequence.
Remarks
Resets the entire screen to initial state.
Example
See
controlSequenceIntroducer
▸ controlSequenceIntroducer<Code
>(code
): <Input>(input
: Input
)
=>
`[${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
Name | Type | Description |
---|---|---|
Code | extends string | CSI code generic. |
Parameters
Name | Type | Description |
---|---|---|
code | Code | CSI code. |
Returns
fn
Curried function with code
in context.
▸ <Input
>(input
):
`[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${Input<Input>[0]
extends number ? any[any] :
""};${Input<Input>[1] extends number ? any[any] : ""}` : `${Input &
number}`}${Code}`
Takes an input
number and returns the CSI sequence.
Type parameters
Name | Type | Description |
---|---|---|
Input | extends number | readonly [Maybe <number >, Maybe <number >] | CSI input generic. |
Parameters
Name | Type | Description |
---|---|---|
input | Input | CSI 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
See
escapeSequence
▸ escapeSequence<Input
>(input
): `${Input}`
Takes an input
string and returns an escaped sequence based on it.
Type parameters
Name | Type | Description |
---|---|---|
Input | extends string | String to escape generic. |
Parameters
Name | Type | Description |
---|---|---|
input | Input | String 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
See
format
▸ format<Close
>(close
): <Open>(open
: Open
) => <Input>(input
:
Input
, …expressions
: ReadOnlyArray
) =>
`[${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
Name | Type | Description |
---|---|---|
Close | extends number | Close string generic. |
Parameters
Name | Type | Description |
---|---|---|
close | Close | Close string. |
Returns
fn
Curried function with close
in context.
▸ <Open
>(open
): <Input>(input
: Input
, …expressions
:
ReadOnlyArray
) =>
`[${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 function with close
set.
Type parameters
Name | Type | Description |
---|---|---|
Open | extends number | Open string generic. |
Parameters
Name | Type | Description |
---|---|---|
open | Open | Open string. |
Returns
fn
Curried function with close
and open
in context.
▸ <Input
>(input
, ...expressions
):
`[${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 function with close
and open
set.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type | Description |
---|---|---|
input | Input | Input string or TemplateStringArray (when using tagged templates). |
...expressions | ReadOnlyArray | Input 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
See
Remarks
Given an open
, a close
string and an input
string, return formatted
input
(surrounded by open
and close
).
Example
See
mix
▸ mix(...formatters
): Formatter
Composes formatters.
Parameters
Name | Type | Description |
---|---|---|
...formatters | ReadOnlyArray <Formatter > | Array of formatters to be composed. |
Returns
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
See
normalizeString
▸ normalizeString<Input
>(input
, ...expressions
): Input
extends
string
? Input
<Input
> : string
Takes a string or a template string and returns a plain string.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type | Description |
---|---|---|
input | Input | String or template string. |
...expressions | ReadOnlyArray | Possible values passed to the template string. |
Returns
Input
extends string
? Input
<Input
> : string
Plain string.
Example
See
optionalFormat
▸ optionalFormat<Close
>(close
): <Open>(open
: Open
) =>
<Input>(input
: Input
, …expressions
: ReadOnlyArray
) =>
`[${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
Name | Type |
---|---|
Close | extends number |
Parameters
Name | Type |
---|---|
close | Close |
Returns
fn
Either the formatted string, or just the passed string.
▸ <Open
>(open
): <Input>(input
: Input
, …expressions
:
ReadOnlyArray
) =>
`[${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 function with close
set.
Type parameters
Name | Type | Description |
---|---|---|
Open | extends number | Open string generic. |
Parameters
Name | Type | Description |
---|---|---|
open | Open | Open string. |
Returns
fn
Curried function with close
and open
in context.
▸ <Input
>(input
, ...expressions
):
`[${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 function with close
and open
set.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type | Description |
---|---|---|
input | Input | Input string or TemplateStringArray (when using tagged templates). |
...expressions | ReadOnlyArray | Input 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
See
Remarks
Impure version of format which changes depending on
the current NodeJS globalThis.process
environment.
Example
See
selectGraphicRendition
▸ selectGraphicRendition<Input
>(input
):
`[${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
Name | Type |
---|---|
Input | extends number | readonly [Maybe <number >, Maybe <number >] |
Parameters
Name | Type | Description |
---|---|---|
input | Input | Input 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
See
Cursor
cursorBack
▸ cursorBack<Input
>(input
):
`[${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
Name | Type |
---|---|
Input | extends number | readonly [Maybe <number >, Maybe <number >] |
Parameters
Name | Type | Description |
---|---|---|
input | Input | Amount 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
See
cursorDown
▸ cursorDown<Input
>(input
):
`[${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
Name | Type |
---|---|
Input | extends number | readonly [Maybe <number >, Maybe <number >] |
Parameters
Name | Type | Description |
---|---|---|
input | Input | Amount 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
See
cursorForward
▸ cursorForward<Input
>(input
):
`[${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
Name | Type |
---|---|
Input | extends number | readonly [Maybe <number >, Maybe <number >] |
Parameters
Name | Type | Description |
---|---|---|
input | Input | Amount 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
See
cursorHorizontalAbsolute
▸ cursorHorizontalAbsolute<Input
>(input
):
`[${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
Name | Type |
---|---|
Input | extends number | readonly [Maybe <number >, Maybe <number >] |
Parameters
Name | Type | Description |
---|---|---|
input | Input | Column 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
See
cursorNextLine
▸ cursorNextLine<Input
>(input
):
`[${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
Name | Type |
---|---|
Input | extends number | readonly [Maybe <number >, Maybe <number >] |
Parameters
Name | Type | Description |
---|---|---|
input | Input | Amount 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
See
cursorPosition
▸ cursorPosition<Input
>(input
):
`[${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
Name | Type |
---|---|
Input | extends number | readonly [Maybe <number >, Maybe <number >] |
Parameters
Name | Type | Description |
---|---|---|
input | Input | Position (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
See
cursorPreviousLine
▸ cursorPreviousLine<Input
>(input
):
`[${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
Name | Type |
---|---|
Input | extends number | readonly [Maybe <number >, Maybe <number >] |
Parameters
Name | Type | Description |
---|---|---|
input | Input | Amount 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
See
cursorUp
▸ cursorUp<Input
>(input
):
`[${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
Name | Type |
---|---|
Input | extends number | readonly [Maybe <number >, Maybe <number >] |
Parameters
Name | Type | Description |
---|---|---|
input | Input | Amount 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
See
Erase
eraseInDisplay
▸ eraseInDisplay<Input
>(input
):
`[${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
Name | Type |
---|---|
Input | extends number | readonly [Maybe <number >, Maybe <number >] |
Parameters
Name | Type | Description |
---|---|---|
input | Input | 0 (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
See
eraseInLine
▸ eraseInLine<Input
>(input
):
`[${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
Name | Type |
---|---|
Input | extends number | readonly [Maybe <number >, Maybe <number >] |
Parameters
Name | Type | Description |
---|---|---|
input | Input | 0 (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
input | erases… |
---|---|
0 | …to end of line. |
1 | …to beginning of line. |
2 | …entire line. |
Example
See
CSI (Control Sequence Introducer) sequences
Foreground
foregroundBlack
▸ foregroundBlack<Input
>(input
, ...expressions
): `[30m${Input
extends string ? Input<Input> : string}[39m`
Black foreground code wrapper.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type |
---|---|
input | Input |
...expressions | ReadOnlyArray |
Returns
`[30m${Input extends string ? Input<Input> : string}[39m`
input
string with black foreground.
Remarks
Given an input
string, it will return a new string with the ANSI codes for
black foreground.
Example
See
foregroundBlue
▸ foregroundBlue<Input
>(input
, ...expressions
): `[34m${Input
extends string ? Input<Input> : string}[39m`
Blue foreground code wrapper.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type |
---|---|
input | Input |
...expressions | ReadOnlyArray |
Returns
`[34m${Input extends string ? Input<Input> : string}[39m`
input
string with blue foreground.
Remarks
Given an input
string, it will return a new string with the ANSI codes for
blue foreground.
Example
See
foregroundBrightBlue
▸ foregroundBrightBlue<Input
>(input
, ...expressions
): `[94m${Input
extends string ? Input<Input> : string}[39m`
Bright blue foreground code wrapper.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type |
---|---|
input | Input |
...expressions | ReadOnlyArray |
Returns
`[94m${Input extends string ? Input<Input> : string}[39m`
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
See
foregroundBrightCyan
▸ foregroundBrightCyan<Input
>(input
, ...expressions
): `[96m${Input
extends string ? Input<Input> : string}[39m`
Bright Cyan foreground code wrapper.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type |
---|---|
input | Input |
...expressions | ReadOnlyArray |
Returns
`[96m${Input extends string ? Input<Input> : string}[39m`
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
See
foregroundBrightGreen
▸ foregroundBrightGreen<Input
>(input
, ...expressions
):
`[92m${Input extends string ? Input<Input> : string}[39m`
Bright green foreground code wrapper.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type |
---|---|
input | Input |
...expressions | ReadOnlyArray |
Returns
`[92m${Input extends string ? Input<Input> : string}[39m`
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
See
foregroundBrightMagenta
▸ foregroundBrightMagenta<Input
>(input
, ...expressions
):
`[95m${Input extends string ? Input<Input> : string}[39m`
Bright magenta foreground code wrapper.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type |
---|---|
input | Input |
...expressions | ReadOnlyArray |
Returns
`[95m${Input extends string ? Input<Input> : string}[39m`
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
See
foregroundBrightRed
▸ foregroundBrightRed<Input
>(input
, ...expressions
): `[91m${Input
extends string ? Input<Input> : string}[39m`
Bright red foreground code wrapper.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type |
---|---|
input | Input |
...expressions | ReadOnlyArray |
Returns
`[91m${Input extends string ? Input<Input> : string}[39m`
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
See
foregroundBrightWhite
▸ foregroundBrightWhite<Input
>(input
, ...expressions
):
`[97m${Input extends string ? Input<Input> : string}[39m`
Bright white foreground code wrapper.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type |
---|---|
input | Input |
...expressions | ReadOnlyArray |
Returns
`[97m${Input extends string ? Input<Input> : string}[39m`
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
See
foregroundBrightYellow
▸ foregroundBrightYellow<Input
>(input
, ...expressions
):
`[93m${Input extends string ? Input<Input> : string}[39m`
Bright yellow foreground code wrapper.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type |
---|---|
input | Input |
...expressions | ReadOnlyArray |
Returns
`[93m${Input extends string ? Input<Input> : string}[39m`
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
See
foregroundColor
▸ foregroundColor<Open
>(open
): <Input>(input
: Input
,
…expressions
: ReadOnlyArray
) =>
`[${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}[39m`
Foreground color code wrapper.
Type parameters
Name | Type |
---|---|
Open | extends number |
Parameters
Name | Type |
---|---|
open | Open |
Returns
fn
Curried function with close
ANSI code for foreground in context.
▸ <Input
>(input
, ...expressions
):
`[${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}[39m`
format function with close
and open
set.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type | Description |
---|---|---|
input | Input | Input string or TemplateStringArray (when using tagged templates). |
...expressions | ReadOnlyArray | Input 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}[39m`
Formatted input
string.
See
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
See
foregroundCyan
▸ foregroundCyan<Input
>(input
, ...expressions
): `[36m${Input
extends string ? Input<Input> : string}[39m`
Cyan foreground code wrapper.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type |
---|---|
input | Input |
...expressions | ReadOnlyArray |
Returns
`[36m${Input extends string ? Input<Input> : string}[39m`
input
string with cyan foreground.
Remarks
Given an input
string, it will return a new string with the ANSI codes for
cyan foreground.
Example
See
foregroundGray
▸ foregroundGray<Input
>(input
, ...expressions
): `[90m${Input
extends string ? Input<Input> : string}[39m`
Gray foreground code wrapper.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type |
---|---|
input | Input |
...expressions | ReadOnlyArray |
Returns
`[90m${Input extends string ? Input<Input> : string}[39m`
input
string with gray foreground.
Remarks
Given an input
string, it will return a new string with the ANSI codes for
gray foreground.
Example
See
foregroundGreen
▸ foregroundGreen<Input
>(input
, ...expressions
): `[32m${Input
extends string ? Input<Input> : string}[39m`
Green foreground code wrapper.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type |
---|---|
input | Input |
...expressions | ReadOnlyArray |
Returns
`[32m${Input extends string ? Input<Input> : string}[39m`
input
string with green foreground.
Remarks
Given an input
string, it will return a new string with the ANSI codes for
green foreground.
Example
See
foregroundMagenta
▸ foregroundMagenta<Input
>(input
, ...expressions
): `[35m${Input
extends string ? Input<Input> : string}[39m`
Magenta foreground code wrapper.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type |
---|---|
input | Input |
...expressions | ReadOnlyArray |
Returns
`[35m${Input extends string ? Input<Input> : string}[39m`
input
string with magenta foreground.
Remarks
Given an input
string, it will return a new string with the ANSI codes for
magenta foreground.
Example
See
foregroundRed
▸ foregroundRed<Input
>(input
, ...expressions
): `[31m${Input
extends string ? Input<Input> : string}[39m`
Red foreground code wrapper.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type |
---|---|
input | Input |
...expressions | ReadOnlyArray |
Returns
`[31m${Input extends string ? Input<Input> : string}[39m`
input
string with red foreground.
Remarks
Given an input
string, it will return a new string with the ANSI codes for
red foreground.
Example
See
foregroundWhite
▸ foregroundWhite<Input
>(input
, ...expressions
): `[37m${Input
extends string ? Input<Input> : string}[39m`
White foreground code wrapper.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type |
---|---|
input | Input |
...expressions | ReadOnlyArray |
Returns
`[37m${Input extends string ? Input<Input> : string}[39m`
input
string with white foreground.
Remarks
Given an input
string, it will return a new string with the ANSI codes for
white foreground.
Example
See
foregroundYellow
▸ foregroundYellow<Input
>(input
, ...expressions
): `[33m${Input
extends string ? Input<Input> : string}[39m`
Yellow foreground code wrapper.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type |
---|---|
input | Input |
...expressions | ReadOnlyArray |
Returns
`[33m${Input extends string ? Input<Input> : string}[39m`
input
string with yellow foreground.
Remarks
Given an input
string, it will return a new string with the ANSI codes for
yellow foreground.
Example
See
Scroll
scrollDown
▸ scrollDown<Input
>(input
):
`[${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
Name | Type |
---|---|
Input | extends number | readonly [Maybe <number >, Maybe <number >] |
Parameters
Name | Type | Description |
---|---|---|
input | Input | Amount 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
See
scrollUp
▸ scrollUp<Input
>(input
):
`[${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
Name | Type |
---|---|
Input | extends number | readonly [Maybe <number >, Maybe <number >] |
Parameters
Name | Type | Description |
---|---|---|
input | Input | Amount 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
See
Text
bold
▸ bold<Input
>(input
, ...expressions
): `[1m${Input extends string ?
Input<Input> : string}[22m`
Bold code wrapper.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type |
---|---|
input | Input |
...expressions | ReadOnlyArray |
Returns
`[1m${Input extends string ? Input<Input> : string}[22m`
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
See
dimmed
▸ dimmed<Input
>(input
, ...expressions
): `[2m${Input extends string
? Input<Input> : string}[22m`
Dimmed code wrapper.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type |
---|---|
input | Input |
...expressions | ReadOnlyArray |
Returns
`[2m${Input extends string ? Input<Input> : string}[22m`
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
See
inverse
▸ inverse<Input
>(input
, ...expressions
): `[7m${Input extends
string ? Input<Input> : string}[27m`
Inverse code wrapper.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type |
---|---|
input | Input |
...expressions | ReadOnlyArray |
Returns
`[7m${Input extends string ? Input<Input> : string}[27m`
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
See
italic
▸ italic<Input
>(input
, ...expressions
): `[3m${Input extends string
? Input<Input> : string}[23m`
Italic code wrapper.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type |
---|---|
input | Input |
...expressions | ReadOnlyArray |
Returns
`[3m${Input extends string ? Input<Input> : string}[23m`
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
See
strikethrough
▸ strikethrough<Input
>(input
, ...expressions
): `[9m${Input extends
string ? Input<Input> : string}[29m`
Takes an input
string and adds the ANSI codes for strikethrough text.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type |
---|---|
input | Input |
...expressions | ReadOnlyArray |
Returns
`[9m${Input extends string ? Input<Input> : string}[29m`
input
string with strikethrough format.
Example
See
underlined
▸ underlined<Input
>(input
, ...expressions
): `[4m${Input extends
string ? Input<Input> : string}[24m`
Takes an input
string and adds the ANSI codes for underlined text.
Type parameters
Name | Type |
---|---|
Input | extends string | TemplateStringsArray |
Parameters
Name | Type |
---|---|
input | Input |
...expressions | ReadOnlyArray |
Returns
`[4m${Input extends string ? Input<Input> : string}[24m`
input
string with underlined format.
Example
See