LogoPear Docs

bare-ansi-escapes

Parse and produce ANSI escape sequences

stable

bare-ansi-escapes — Parse and produce ANSI escape sequences.

npm i bare-ansi-escapes

Usage

const KeyDecoder = require('bare-ansi-escapes/key-decoder')

readableStream.pipe(new KeyDecoder()).on('data', (key) => console.log(key))

API

Functions

cursorUp(n?: number): string

Source

Return the ANSI escape sequence that moves the cursor up n lines.

Parameters

ParameterTypeDefaultDescription
n?numberNumber of lines to move up; defaults to 1.

cursorDown(n?: number): string

Source

Return the ANSI escape sequence that moves the cursor down n lines.

Parameters

ParameterTypeDefaultDescription
n?numberNumber of lines to move down; defaults to 1.

cursorForward(n?: number): string

Source

Return the ANSI escape sequence that moves the cursor forward n columns.

Parameters

ParameterTypeDefaultDescription
n?numberNumber of columns to move forward; defaults to 1.

cursorBack(n?: number): string

Source

Return the ANSI escape sequence that moves the cursor back n columns.

Parameters

ParameterTypeDefaultDescription
n?numberNumber of columns to move back; defaults to 1.

cursorNextLine(n?: number): string

Source

Return the ANSI escape sequence that moves the cursor to the start of the line n lines down.

Parameters

ParameterTypeDefaultDescription
n?numberNumber of lines down to move; defaults to 1.

cursorPreviousLine(n?: number): string

Source

Return the ANSI escape sequence that moves the cursor to the start of the line n lines up.

Parameters

ParameterTypeDefaultDescription
n?numberNumber of lines up to move; defaults to 1.

cursorPosition(column: number, row?: number): string

Source

Return the ANSI escape sequence that moves the cursor to column and, if given, row.

Parameters

ParameterTypeDefaultDescription
columnnumberZero-based column to move the cursor to.
row?numberZero-based row to move the cursor to; defaults to 0 (the current row).

scrollUp(n?: number): string

Source

Return the ANSI escape sequence that scrolls the display up n lines.

Parameters

ParameterTypeDefaultDescription
n?numberNumber of lines to scroll the display up; defaults to 1.

scrollDown(n?: number): string

Source

Return the ANSI escape sequence that scrolls the display down n lines.

Parameters

ParameterTypeDefaultDescription
n?numberNumber of lines to scroll the display down; defaults to 1.

Constants and variables

constants: { ESC: string; CSI: string; SGR: (n: number) => string }

Source

The raw escape sequence building blocks: ESC, CSI, and the SGR (Select Graphic Rendition) sequence builder.

cursorHide: string

Source

ANSI escape sequence that hides the cursor.

cursorShow: string

Source

ANSI escape sequence that shows the cursor.

eraseDisplayEnd: string

Source

ANSI escape sequence that erases the display from the cursor to the end.

eraseDisplayStart: string

Source

ANSI escape sequence that erases the display from the start to the cursor.

eraseDisplay: string

Source

ANSI escape sequence that erases the entire display.

eraseLineEnd: string

Source

ANSI escape sequence that erases the line from the cursor to the end.

eraseLineStart: string

Source

ANSI escape sequence that erases the line from the start to the cursor.

eraseLine: string

Source

ANSI escape sequence that erases the entire line.

modifierReset: string

Source

SGR escape sequence that resets all modifiers.

modifierBold: string

Source

SGR escape sequence that enables bold text.

modifierDim: string

Source

SGR escape sequence that enables dim text.

modifierItalic: string

Source

SGR escape sequence that enables italic text.

modifierUnderline: string

Source

SGR escape sequence that enables underlined text.

modifierNormal: string

Source

SGR escape sequence that resets bold/dim to normal intensity.

modifierNotItalic: string

Source

SGR escape sequence that disables italic text.

modifierNotUnderline: string

Source

SGR escape sequence that disables underlined text.

colorBlack: string

Source

SGR escape sequence that sets the foreground color to black.

colorRed: string

Source

SGR escape sequence that sets the foreground color to red.

colorGreen: string

Source

SGR escape sequence that sets the foreground color to green.

colorYellow: string

Source

SGR escape sequence that sets the foreground color to yellow.

colorBlue: string

Source

SGR escape sequence that sets the foreground color to blue.

colorMagenta: string

Source

SGR escape sequence that sets the foreground color to magenta.

colorCyan: string

Source

SGR escape sequence that sets the foreground color to cyan.

colorWhite: string

Source

SGR escape sequence that sets the foreground color to white.

colorDefault: string

Source

SGR escape sequence that resets the foreground color to the default.

colorBrightBlack: string

Source

SGR escape sequence that sets the foreground color to bright black.

colorBrightRed: string

Source

SGR escape sequence that sets the foreground color to bright red.

colorBrightGreen: string

Source

SGR escape sequence that sets the foreground color to bright green.

colorBrightYellow: string

Source

SGR escape sequence that sets the foreground color to bright yellow.

colorBrightBlue: string

Source

SGR escape sequence that sets the foreground color to bright blue.

colorBrightMagenta: string

Source

SGR escape sequence that sets the foreground color to bright magenta.

colorBrightCyan: string

Source

SGR escape sequence that sets the foreground color to bright cyan.

colorBrightWhite: string

Source

SGR escape sequence that sets the foreground color to bright white.

bare-ansi-escapes/key-decoder

KeyDecoder

new KeyDecoder(opts?: KeyDecoderOptions)

Source

Create a KeyDecoder, optionally configuring the input encoding and escapeCodeTimeout.

Parameters

ParameterTypeDefaultDescription
opts?KeyDecoderOptionsOptions controlling the encoding and escapeCodeTimeout used to decode input; see KeyDecoderOptions.

encoding: BufferEncoding

Source

The encoding used to decode incoming byte data into characters.

Key

new Key(name: string | number, sequence: string, ctrl: boolean, meta: boolean, shift: boolean)

Source

Create a Key with the given name, raw sequence, and modifier flags.

Parameters

ParameterTypeDefaultDescription
namestring | numberThe decoded key name, e.g. 'up', 'return', or a single character.
sequencestringThe raw input sequence the key was decoded from.
ctrlbooleanWhether the Ctrl modifier was held.
metabooleanWhether the Meta (Alt) modifier was held.
shiftbooleanWhether the Shift modifier was held.

ctrl: boolean

Source

Whether the Ctrl modifier was held.

meta: boolean

Source

Whether the Meta (Alt) modifier was held.

name: string

Source

The decoded key name, e.g. 'up', 'return', or a single character.

sequence: string

Source

The raw input sequence the key was decoded from.

shift: boolean

Source

Whether the Shift modifier was held.

Types

KeyDecoderOptions

interface KeyDecoderOptions {
  encoding?: BufferEncoding
  escapeCodeTimeout?: number
}
Source

KeyDecoderEvents

interface KeyDecoderEvents extends TransformEvents {
  data: [key: Key]
}
Source

See also

On this page