ANSI by Lou
📟 Functional CLI ANSI formatting functions.
Usage
📦 Node
Install @lou.codes/ansi
as a dependency:
pnpm add @lou.codes/ansi# ornpm install @lou.codes/ansi# oryarn add @lou.codes/ansi
Import it and use it:
import { foregroundRed } from "@lou.codes/ansi";
foregroundRed`Hello world!`; // "Hello world!" in red text.
🦕 Deno
Import @lou.codes/ansi
using the npm:
prefix, and use it directly:
import { foregroundRed } from "npm:@lou.codes/ansi";
foregroundRed`Hello world!`; // "Hello world!" in red text.
🌎 Browser
Import @lou.codes/ansi
using esm.sh, and use it directly:
<script type="module"> import { foregroundRed } from "https://esm.sh/@lou.codes/ansi";
foregroundRed`Hello world!`; // "Hello world!" in red text.</script>
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 : 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 : 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
backgroundBlack("Lou"); // "\x1b[40mLou\x1b[49m"// It can also be used as a tag function for tagged templates:backgroundBlack`Lou`; // "\x1b[40mLou\x1b[49m"
See
backgroundBlue
▸ backgroundBlue<Input
>(input
, ...expressions
): `[44m${Input
extends string ? 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 : 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
backgroundBlue("Lou"); // "\x1b[44mLou\x1b[49m"// It can also be used as a tag function for tagged templates:backgroundBlue`Lou`; // "\x1b[44mLou\x1b[49m"
See
backgroundBrightBlue
▸ backgroundBrightBlue<Input
>(input
, ...expressions
):
`[104m${Input extends string ? 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 : 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
backgroundBrightBlue("Lou"); // "\x1b[104mLou\x1b[49m"// It can also be used as a tag function for tagged templates:backgroundBrightBlue`Lou`; // "\x1b[104mLou\x1b[49m"
See
backgroundBrightCyan
▸ backgroundBrightCyan<Input
>(input
, ...expressions
):
`[106m${Input extends string ? 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 : 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
backgroundBrightCyan("Lou"); // "\x1b[106mLou\x1b[49m"// It can also be used as a tag function for tagged templates:backgroundBrightCyan`Lou`; // "\x1b[106mLou\x1b[49m"
See
backgroundBrightGreen
▸ backgroundBrightGreen<Input
>(input
, ...expressions
):
`[102m${Input extends string ? 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 : 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
backgroundBrightGreen("Lou"); // "\x1b[102mLou\x1b[49m"// It can also be used as a tag function for tagged templates:backgroundBrightGreen`Lou`; // "\x1b[102mLou\x1b[49m"
See
backgroundBrightMagenta
▸ backgroundBrightMagenta<Input
>(input
, ...expressions
):
`[105m${Input extends string ? 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 : 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
backgroundBrightMagenta("Lou"); // "\x1b[105mLou\x1b[49m"// It can also be used as a tag function for tagged templates:backgroundBrightMagenta`Lou`; // "\x1b[105mLou\x1b[49m"
See
backgroundBrightRed
▸ backgroundBrightRed<Input
>(input
, ...expressions
): `[101m${Input
extends string ? 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 : 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
backgroundBrightRed("Lou"); // "\x1b[101mLou\x1b[49m"// It can also be used as a tag function for tagged templates:backgroundBrightRed`Lou`; // "\x1b[101mLou\x1b[49m"
See
backgroundBrightWhite
▸ backgroundBrightWhite<Input
>(input
, ...expressions
):
`[107m${Input extends string ? 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 : 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
backgroundBrightWhite("Lou"); // "\x1b[107mLou\x1b[49m"// It can also be used as a tag function for tagged templates:backgroundBrightWhite`Lou`; // "\x1b[107mLou\x1b[49m"
See
backgroundBrightYellow
▸ backgroundBrightYellow<Input
>(input
, ...expressions
):
`[103m${Input extends string ? 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 : 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
backgroundBrightYellow("Lou"); // "\x1b[103mLou\x1b[49m"// It can also be used as a tag function for tagged templates:backgroundBrightYellow`Lou`; // "\x1b[103mLou\x1b[49m"
See
backgroundColor
▸ backgroundColor<Open
>(open
): <Input>(input
: Input
,
…expressions
: ReadOnlyArray
) =>
`[${Open extends readonly [Maybe<number>, Maybe<number>] ? `${First<Open>
extends number ? First<Open> :
""};${Second<Open> extends number ? Second<Open> : ""}` : `${Open &
number}`}m${Input extends string ? 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>] ? `${First<Open>
extends number ? First<Open> :
""};${Second<Open> extends number ? Second<Open> : ""}` : `${Open &
number}`}m${Input extends string ? 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>] ? `${First<Open> extends number ? First<Open> : ""};${Second<Open> extends number ? Second<Open> : ""}` : `${Open & number}`}m${Input extends string ? 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
backgroundColor(13)("Lou"); // "\x1b[13mLou\x1b[49m"// It can also be used as a tag function for tagged templates:backgroundColor(13)`Lou`; // "\x1b[13mLou\x1b[49m"
See
backgroundCyan
▸ backgroundCyan<Input
>(input
, ...expressions
): `[46m${Input
extends string ? 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 : 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
backgroundCyan("Lou"); // "\x1b[46mLou\x1b[49m"// It can also be used as a tag function for tagged templates:backgroundCyan`Lou`; // "\x1b[46mLou\x1b[49m"
See
backgroundGray
▸ backgroundGray<Input
>(input
, ...expressions
): `[100m${Input
extends string ? 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 : 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
backgroundGray("Lou"); // "\x1b[100mLou\x1b[49m"// It can also be used as a tag function for tagged templates:backgroundGray`Lou`; // "\x1b[100mLou\x1b[49m"
See
backgroundGreen
▸ backgroundGreen<Input
>(input
, ...expressions
): `[42m${Input
extends string ? 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 : 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
backgroundGreen("Lou"); // "\x1b[42mLou\x1b[49m"// It can also be used as a tag function for tagged templates:backgroundGreen`Lou`; // "\x1b[42mLou\x1b[49m"
See
backgroundMagenta
▸ backgroundMagenta<Input
>(input
, ...expressions
): `[45m${Input
extends string ? 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 : 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
backgroundMagenta("Lou"); // "\x1b[45mLou\x1b[49m"// It can also be used as a tag function for tagged templates:backgroundMagenta`Lou`; // "\x1b[45mLou\x1b[49m"
See
backgroundRed
▸ backgroundRed<Input
>(input
, ...expressions
): `[41m${Input
extends string ? 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 : 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
backgroundRed("Lou"); // "\x1b[41mLou\x1b[49m"// It can also be used as a tag function for tagged templates:backgroundRed`Lou`; // "\x1b[41mLou\x1b[49m"
See
backgroundWhite
▸ backgroundWhite<Input
>(input
, ...expressions
): `[47m${Input
extends string ? 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 : 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
backgroundWhite("Lou"); // "\x1b[47mLou\x1b[49m"// It can also be used as a tag function for tagged templates:backgroundWhite`Lou`; // "\x1b[47mLou\x1b[49m"
See
backgroundYellow
▸ backgroundYellow<Input
>(input
, ...expressions
): `[43m${Input
extends string ? 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 : 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
backgroundYellow("Lou"); // "\x1b[43mLou\x1b[49m"// It can also be used as a tag function for tagged templates:backgroundYellow`Lou`; // "\x1b[43mLou\x1b[49m"
See
Common
Formatter
Ƭ Formatter: Function
<readonly [input: 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
const formatter: Formatter = (input, ...expressions) => typeof input === "string" ? input : ( input .flatMap((string, index) => [string, expressions[index] ?? ""]) .join("") );
formatter("Lou"); // "Lou"formatter`Lou`; // "Lou"
See
Param
Array of strings for template strings or a single string, followed by an array of expressions (if any).
resetToInitialState
• Const
resetToInitialState: "\u001bc"
RIS sequence.
Remarks
Resets the entire screen to initial state.
Example
console.log(resetToInitialState); // "\x1b[c"stdout.write(resetToInitialState); // Resets the entire screen to initial state.
See
controlSequenceIntroducer
▸ controlSequenceIntroducer<Code
>(code
): <Input>(input
: Input
)
=>
`[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${First<Input>
extends number ? First<Input> :
""};${Second<Input> extends number ? Second<Input> : ""}` : `${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>] ? `${First<Input>
extends number ? First<Input> :
""};${Second<Input> extends number ? Second<Input> : ""}` : `${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>] ? `${First<Input> extends number ? First<Input> : ""};${Second<Input> extends number ? Second<Input> : ""}` : `${Input & number}`}${Code}`
CSI sequence.
See
Remarks
Takes a code
and an input
number and returns the CSI sequence.
Example
const selectGraphicRendition = controlSequenceIntroducer("m");selectGraphicRendition(13); // "\x1b[13m"selectGraphicRendition(42); // "\x1b[42m"
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
escapeSequence("Lou"); // "\x1bLou"
See
format
▸ format<Close
>(close
): <Open>(open
: Open
) => <Input>(input
:
Input
, …expressions
: ReadOnlyArray
) =>
`[${Open extends readonly [Maybe<number>, Maybe<number>] ? `${First<Open>
extends number ? First<Open> :
""};${Second<Open> extends number ? Second<Open> : ""}` : `${Open &
number}`}m${Input extends string ? Input : string}[${Close extends readonly
[Maybe<number>, Maybe<number>] ?
`${First<Close> extends number ? First<Close> : ""};${Second<Close>
extends number ? Second<Close> : ""}` : `${Close & number}`}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>] ? `${First<Open>
extends number ? First<Open> :
""};${Second<Open> extends number ? Second<Open> : ""}` : `${Open &
number}`}m${Input extends string ? Input : string}[${Close extends readonly
[Maybe<number>, Maybe<number>] ?
`${First<Close> extends number ? First<Close> : ""};${Second<Close>
extends number ? Second<Close> : ""}` : `${Close & number}`}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>] ? `${First<Open>
extends number ? First<Open> :
""};${Second<Open> extends number ? Second<Open> : ""}` : `${Open &
number}`}m${Input extends string ? Input : string}[${Close extends readonly
[Maybe<number>, Maybe<number>] ?
`${First<Close> extends number ? First<Close> : ""};${Second<Close>
extends number ? Second<Close> : ""}` : `${Close & number}`}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>] ? `${First<Open> extends number ? First<Open> : ""};${Second<Open> extends number ? Second<Open> : ""}` : `${Open & number}`}m${Input extends string ? Input : string}[${Close extends readonly [Maybe<number>, Maybe<number>] ? `${First<Close> extends number ? First<Close> : ""};${Second<Close> extends number ? Second<Close> : ""}` : `${Close & number}`}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
format(13)(42)("Lou"); // "\x1b[42mLou\x1b[13m"// It can also be used as a tag function for tagged templates:format(13)(42)`Lou`; // "\x1b[42mLou\x1b[13m"
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
const redTextWhiteBackground = mix(foregroundRed, backgroundWhite);
redTextWhiteBackground("Lou");// It can also be used as a tag function for tagged templates:redTextWhiteBackground`Lou`;
See
normalizeString
▸ normalizeString<Input
>(input
, ...expressions
): Input
extends
string
? 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
: string
Plain string.
Example
normalizeString(`Hello ${13}!`); // "Hello 13!"normalizeString`Hello ${13}!`; // "Hello 13!"
See
optionalFormat
▸ optionalFormat<Close
>(close
): <Open>(open
: Open
) =>
<Input>(input
: Input
, …expressions
: ReadOnlyArray
) =>
`[${Open extends readonly [Maybe<number>, Maybe<number>] ? `${First<Open>
extends number ? First<Open> :
""};${Second<Open> extends number ? Second<Open> : ""}` : `${Open &
number}`}m${Input extends string ? Input : string}[${Close extends readonly
[Maybe<number>, Maybe<number>] ?
`${First<Close> extends number ? First<Close> : ""};${Second<Close>
extends number ? Second<Close> : ""}` : `${Close & number}`}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>] ? `${First<Open>
extends number ? First<Open> :
""};${Second<Open> extends number ? Second<Open> : ""}` : `${Open &
number}`}m${Input extends string ? Input : string}[${Close extends readonly
[Maybe<number>, Maybe<number>] ?
`${First<Close> extends number ? First<Close> : ""};${Second<Close>
extends number ? Second<Close> : ""}` : `${Close & number}`}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>] ? `${First<Open>
extends number ? First<Open> :
""};${Second<Open> extends number ? Second<Open> : ""}` : `${Open &
number}`}m${Input extends string ? Input : string}[${Close extends readonly
[Maybe<number>, Maybe<number>] ?
`${First<Close> extends number ? First<Close> : ""};${Second<Close>
extends number ? Second<Close> : ""}` : `${Close & number}`}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>] ? `${First<Open> extends number ? First<Open> : ""};${Second<Open> extends number ? Second<Open> : ""}` : `${Open & number}`}m${Input extends string ? Input : string}[${Close extends readonly [Maybe<number>, Maybe<number>] ? `${First<Close> extends number ? First<Close> : ""};${Second<Close> extends number ? Second<Close> : ""}` : `${Close & number}`}m`
Formatted input
string.
See
See
Remarks
Impure version of format which changes depending on
the current NodeJS globalThis.process
environment.
Example
// In a environment with color:optionalFormat(42)(13)("Lou"); // "\x1b[42mLou\x1b[13m"// In an environment without color:optionalFormat(42)(13)("Lou"); // "Lou"// It also works with tagged templates:optionalFormat(42)(13)`Lou`; // "\x1b[42mLou\x1b[13m"
See
selectGraphicRendition
▸ selectGraphicRendition<Input
>(input
):
`[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${First<Input>
extends number ? First<Input> :
""};${Second<Input> extends number ? Second<Input> : ""}` : `${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>] ? `${First<Input> extends number ? First<Input> : ""};${Second<Input> extends number ? Second<Input> : ""}` : `${Input & number}`}m`
SGR sequence.
Example
controlSequenceIntroducer(13); // "\x1b[13m"controlSequenceIntroducer(42); // "\x1b[42m"
See
Cursor
cursorBack
▸ cursorBack<Input
>(input
):
`[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${First<Input>
extends number ? First<Input> :
""};${Second<Input> extends number ? Second<Input> : ""}` : `${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>] ? `${First<Input> extends number ? First<Input> : ""};${Second<Input> extends number ? Second<Input> : ""}` : `${Input & number}`}D`
CUB sequence.
Remarks
If the cursor is already at the edge of the screen, this has no effect.
Example
cursorBack(13); // "\x1b[13C"
See
cursorDown
▸ cursorDown<Input
>(input
):
`[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${First<Input>
extends number ? First<Input> :
""};${Second<Input> extends number ? Second<Input> : ""}` : `${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>] ? `${First<Input> extends number ? First<Input> : ""};${Second<Input> extends number ? Second<Input> : ""}` : `${Input & number}`}B`
CUD sequence.
Remarks
If the cursor is already at the edge of the screen, this has no effect.
Example
cursorDown(13); // "\x1b[13B"
See
cursorForward
▸ cursorForward<Input
>(input
):
`[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${First<Input>
extends number ? First<Input> :
""};${Second<Input> extends number ? Second<Input> : ""}` : `${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>] ? `${First<Input> extends number ? First<Input> : ""};${Second<Input> extends number ? Second<Input> : ""}` : `${Input & number}`}C`
CUF sequence.
Remarks
If the cursor is already at the edge of the screen, this has no effect.
Example
cursorForward(13); // "\x1b[13C"
See
cursorHorizontalAbsolute
▸ cursorHorizontalAbsolute<Input
>(input
):
`[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${First<Input>
extends number ? First<Input> :
""};${Second<Input> extends number ? Second<Input> : ""}` : `${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>] ? `${First<Input> extends number ? First<Input> : ""};${Second<Input> extends number ? Second<Input> : ""}` : `${Input & number}`}G`
CHA sequence.
Example
cursorHorizontalAbsolute(13); // "\x1b[13G"
See
cursorNextLine
▸ cursorNextLine<Input
>(input
):
`[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${First<Input>
extends number ? First<Input> :
""};${Second<Input> extends number ? Second<Input> : ""}` : `${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>] ? `${First<Input> extends number ? First<Input> : ""};${Second<Input> extends number ? Second<Input> : ""}` : `${Input & number}`}E`
CNL sequence.
Example
cursorNextLine(13); // "\x1b[13E"
See
cursorPosition
▸ cursorPosition<Input
>(input
):
`[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${First<Input>
extends number ? First<Input> :
""};${Second<Input> extends number ? Second<Input> : ""}` : `${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>] ? `${First<Input> extends number ? First<Input> : ""};${Second<Input> extends number ? Second<Input> : ""}` : `${Input & number}`}H`
CUP sequence.
Example
cursorPosition([13, 42]); // "\x1b[13;42H"cursorPosition([undefined, 42]); // "\x1b[;42H"cursorPosition([13, undefined]); // "\x1b[13;H"
See
cursorPreviousLine
▸ cursorPreviousLine<Input
>(input
):
`[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${First<Input>
extends number ? First<Input> :
""};${Second<Input> extends number ? Second<Input> : ""}` : `${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>] ? `${First<Input> extends number ? First<Input> : ""};${Second<Input> extends number ? Second<Input> : ""}` : `${Input & number}`}F`
CPL sequence.
Example
cursorPreviousLine(13); // "\x1b[13F"
See
cursorUp
▸ cursorUp<Input
>(input
):
`[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${First<Input>
extends number ? First<Input> :
""};${Second<Input> extends number ? Second<Input> : ""}` : `${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>] ? `${First<Input> extends number ? First<Input> : ""};${Second<Input> extends number ? Second<Input> : ""}` : `${Input & number}`}A`
CUU sequence.
Remarks
If the cursor is already at the edge of the screen, this has no effect.
Example
cursorUp(13); // "\x1b[13A"
See
Erase
eraseInDisplay
▸ eraseInDisplay<Input
>(input
):
`[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${First<Input>
extends number ? First<Input> :
""};${Second<Input> extends number ? Second<Input> : ""}` : `${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>] ? `${First<Input> extends number ? First<Input> : ""};${Second<Input> extends number ? Second<Input> : ""}` : `${Input & number}`}J`
ED sequence.
Example
eraseInDisplay(0); // "\x1b[0J" Clear from cursor to end of screen.eraseInDisplay(1); // "\x1b[1J" Clear from cursor to beginning of screen.eraseInDisplay(2); // "\x1b[2J" Clear entire screen.
See
eraseInLine
▸ eraseInLine<Input
>(input
):
`[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${First<Input>
extends number ? First<Input> :
""};${Second<Input> extends number ? Second<Input> : ""}` : `${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>] ? `${First<Input> extends number ? First<Input> : ""};${Second<Input> extends number ? Second<Input> : ""}` : `${Input & number}`}K`
EL sequence.
Remarks
input | erases… |
---|---|
0 | …to end of line. |
1 | …to beginning of line. |
2 | …entire line. |
Example
eraseInLine(0); // "\x1b[0K" Clear from cursor to end of line.eraseInLine(1); // "\x1b[1K" Clear from cursor to beginning of line.eraseInLine(2); // "\x1b[2K" Clear entire line.
See
CSI (Control Sequence Introducer) sequences
Foreground
foregroundBlack
▸ foregroundBlack<Input
>(input
, ...expressions
): `[30m${Input
extends string ? 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 : 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
foregroundBlack("Lou"); // "\x1b[30mLou\x1b[39m"// It can also be used as a tag function for tagged templates:foregroundBlack`Lou`; // "\x1b[30mLou\x1b[39m"
See
foregroundBlue
▸ foregroundBlue<Input
>(input
, ...expressions
): `[34m${Input
extends string ? 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 : 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
foregroundBlue("Lou"); // "\x1b[34mLou\x1b[39m"// It can also be used as a tag function for tagged templates:foregroundBlue`Lou`; // "\x1b[34mLou\x1b[39m"
See
foregroundBrightBlue
▸ foregroundBrightBlue<Input
>(input
, ...expressions
): `[94m${Input
extends string ? 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 : 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
foregroundBrightBlue("Lou"); // "\x1b[94mLou\x1b[39m"// It can also be used as a tag function for tagged templates:foregroundBrightBlue`Lou`; // "\x1b[94mLou\x1b[39m"
See
foregroundBrightCyan
▸ foregroundBrightCyan<Input
>(input
, ...expressions
): `[96m${Input
extends string ? 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 : 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
foregroundBrightCyan("Lou"); // "\x1b[96mLou\x1b[39m"// It can also be used as a tag function for tagged templates:foregroundBrightCyan`Lou`; // "\x1b[96mLou\x1b[39m"
See
foregroundBrightGreen
▸ foregroundBrightGreen<Input
>(input
, ...expressions
):
`[92m${Input extends string ? 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 : 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
foregroundBrightGreen("Lou"); // "\x1b[92mLou\x1b[39m"// It can also be used as a tag function for tagged templates:foregroundBrightGreen`Lou`; // "\x1b[92mLou\x1b[39m"
See
foregroundBrightMagenta
▸ foregroundBrightMagenta<Input
>(input
, ...expressions
):
`[95m${Input extends string ? 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 : 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
foregroundBrightMagenta("Lou"); // "\x1b[95mLou\x1b[39m"// It can also be used as a tag function for tagged templates:foregroundBrightMagenta`Lou`; // "\x1b[95mLou\x1b[39m"
See
foregroundBrightRed
▸ foregroundBrightRed<Input
>(input
, ...expressions
): `[91m${Input
extends string ? 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 : 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
foregroundBrightRed("Lou"); // "\x1b[91mLou\x1b[39m"// It can also be used as a tag function for tagged templates:foregroundBrightRed`Lou`; // "\x1b[91mLou\x1b[39m"
See
foregroundBrightWhite
▸ foregroundBrightWhite<Input
>(input
, ...expressions
):
`[97m${Input extends string ? 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 : 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
foregroundBrightWhite("Lou"); // "\x1b[97mLou\x1b[39m"// It can also be used as a tag function for tagged templates:foregroundBrightWhite`Lou`; // "\x1b[97mLou\x1b[39m"
See
foregroundBrightYellow
▸ foregroundBrightYellow<Input
>(input
, ...expressions
):
`[93m${Input extends string ? 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 : 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
foregroundBrightYellow("Lou"); // "\x1b[93mLou\x1b[39m"// It can also be used as a tag function for tagged templates:foregroundBrightYellow`Lou`; // "\x1b[93mLou\x1b[39m"
See
foregroundColor
▸ foregroundColor<Open
>(open
): <Input>(input
: Input
,
…expressions
: ReadOnlyArray
) =>
`[${Open extends readonly [Maybe<number>, Maybe<number>] ? `${First<Open>
extends number ? First<Open> :
""};${Second<Open> extends number ? Second<Open> : ""}` : `${Open &
number}`}m${Input extends string ? 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>] ? `${First<Open>
extends number ? First<Open> :
""};${Second<Open> extends number ? Second<Open> : ""}` : `${Open &
number}`}m${Input extends string ? 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>] ? `${First<Open> extends number ? First<Open> : ""};${Second<Open> extends number ? Second<Open> : ""}` : `${Open & number}`}m${Input extends string ? 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
foregroundColor(13)("Lou"); // "\x1b[13mLou\x1b[39m"// It can also be used as a tag function for tagged templates:foregroundColor(13)`Lou`; // "\x1b[13mLou\x1b[39m"
See
foregroundCyan
▸ foregroundCyan<Input
>(input
, ...expressions
): `[36m${Input
extends string ? 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 : 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
foregroundCyan("Lou"); // "\x1b[36mLou\x1b[39m"// It can also be used as a tag function for tagged templates:foregroundCyan`Lou`; // "\x1b[36mLou\x1b[39m"
See
foregroundGray
▸ foregroundGray<Input
>(input
, ...expressions
): `[90m${Input
extends string ? 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 : 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
foregroundGray("Lou"); // "\x1b[90mLou\x1b[39m"// It can also be used as a tag function for tagged templates:foregroundGray`Lou`; // "\x1b[90mLou\x1b[39m"
See
foregroundGreen
▸ foregroundGreen<Input
>(input
, ...expressions
): `[32m${Input
extends string ? 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 : 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
foregroundGreen("Lou"); // "\x1b[32mLou\x1b[39m"// It can also be used as a tag function for tagged templates:foregroundGreen`Lou`; // "\x1b[32mLou\x1b[39m"
See
foregroundMagenta
▸ foregroundMagenta<Input
>(input
, ...expressions
): `[35m${Input
extends string ? 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 : 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
foregroundMagenta("Lou"); // "\x1b[35mLou\x1b[39m"// It can also be used as a tag function for tagged templates:foregroundMagenta`Lou`; // "\x1b[35mLou\x1b[39m"
See
foregroundRed
▸ foregroundRed<Input
>(input
, ...expressions
): `[31m${Input
extends string ? 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 : 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
foregroundRed("Lou"); // "\x1b[31mLou\x1b[39m"// It can also be used as a tag function for tagged templates:foregroundRed`Lou`; // "\x1b[31mLou\x1b[39m"
See
foregroundWhite
▸ foregroundWhite<Input
>(input
, ...expressions
): `[37m${Input
extends string ? 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 : 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
foregroundWhite("Lou"); // "\x1b[37mLou\x1b[39m"// It can also be used as a tag function for tagged templates:foregroundWhite`Lou`; // "\x1b[37mLou\x1b[39m"
See
foregroundYellow
▸ foregroundYellow<Input
>(input
, ...expressions
): `[33m${Input
extends string ? 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 : 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
foregroundYellow("Lou"); // "\x1b[33mLou\x1b[39m"// It can also be used as a tag function for tagged templates:foregroundYellow`Lou`; // "\x1b[33mLou\x1b[39m"
See
Scroll
scrollDown
▸ scrollDown<Input
>(input
):
`[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${First<Input>
extends number ? First<Input> :
""};${Second<Input> extends number ? Second<Input> : ""}` : `${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>] ? `${First<Input> extends number ? First<Input> : ""};${Second<Input> extends number ? Second<Input> : ""}` : `${Input & number}`}S`
SD sequence.
Example
scrollDown(13); // "\x1b[13S"
See
scrollUp
▸ scrollUp<Input
>(input
):
`[${Input extends readonly [Maybe<number>, Maybe<number>] ? `${First<Input>
extends number ? First<Input> :
""};${Second<Input> extends number ? Second<Input> : ""}` : `${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>] ? `${First<Input> extends number ? First<Input> : ""};${Second<Input> extends number ? Second<Input> : ""}` : `${Input & number}`}S`
SU sequence.
Example
scrollUp(13); // "\x1b[13S"
See
Text
bold
▸ bold<Input
>(input
, ...expressions
): `[1m${Input extends string ?
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 : 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
bold("Lou"); // "\x1b[1mLou\x1b[22m"// It can also be used as a tag function for tagged templates:bold`Lou`; // "\x1b[1mLou\x1b[22m"
See
dimmed
▸ dimmed<Input
>(input
, ...expressions
): `[2m${Input extends string
? 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 : 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
dimmed("Lou"); // "\x1b[2mLou\x1b[22m"// It can also be used as a tag function for tagged templates:dimmed`Lou`; // "\x1b[2mLou\x1b[22m"
See
inverse
▸ inverse<Input
>(input
, ...expressions
): `[7m${Input extends
string ? 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 : 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
inverse("Lou"); // "\x1b[7mLou\x1b[27m"// It can also be used as a tag function for tagged templates:inverse`Lou`; // "\x1b[7mLou\x1b[27m"
See
italic
▸ italic<Input
>(input
, ...expressions
): `[3m${Input extends string
? 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 : 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
italic("Lou"); // "\x1b[3mLou\x1b[23m"// It can also be used as a tag function for tagged templates:italic`Lou`; // "\x1b[3mLou\x1b[23m"
See
strikethrough
▸ strikethrough<Input
>(input
, ...expressions
): `[9m${Input extends
string ? 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 : string}[29m`
input
string with strikethrough format.
Example
strikethrough("Lou"); // "\x1b[9mLou\x1b[29m"// It can also be used as a tag function for tagged templates:strikethrough`Lou`; // "\x1b[9mLou\x1b[29m"
See
underlined
▸ underlined<Input
>(input
, ...expressions
): `[4m${Input extends
string ? 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 : string}[24m`
input
string with underlined format.
Example
underlined("Lou"); // "\x1b[4mLou\x1b[24m"// It can also be used as a tag function for tagged templates:underlined`Lou`; // "\x1b[4mLou\x1b[24m"
See