Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • Canvas

Implements

Index

Constructors

constructor

  • Creates canvas that writes direct to stdout by default. You can override destination stream with another Writable stream. Also, you can specify custom width and height of viewport where cursor will render the frame.

    example

    Canvas.create({stream: fs.createWriteStream(), width: 20, height: 20});

    Parameters

    Returns Canvas

Properties

Readonly cells

cells: Cell[]

cursorX

cursorX: number = 0

cursorY

cursorY: number = 0

height

height: number

lastFrame

lastFrame: string[]

stream

stream: WriteStream = process.stdout

width

width: number

Methods

background

  • background(color: string): Canvas
  • Set the background color. This color is used for filling the whole cell in the TTY.

    example

    canvas.background('white'); canvas.background('#000000'); canvas.background('rgb(255, 255, 255)'); canvas.background('none'); // disables background filling (will be used default filling)

    Parameters

    • color: string

      Color name, rgb, hex or none if you want to disable background filling

    Returns Canvas

blink

  • blink(isBlink?: boolean): Canvas
  • Toggle blink display mode.

    example

    canvas.blink(); // enable blink mode canvas.blink(false); // disable blink mode

    Parameters

    • Default value isBlink: boolean = true

    Returns Canvas

bold

  • bold(isBold?: boolean): Canvas
  • Toggle bold display mode.

    example

    canvas.bold(); // enable bold mode canvas.bold(false); // disable bold mode

    Parameters

    • Default value isBold: boolean = true

    Returns Canvas

dim

  • dim(isDim?: boolean): Canvas
  • Toggle dim display mode.

    example

    canvas.dim(); // enable dim mode canvas.dim(false); // disable dim mode

    Parameters

    • Default value isDim: boolean = true

    Returns Canvas

down

  • Move the cursor down.

    example

    canvas.down(); // moves cursor down by one cell canvas.down(5); // moves cursor down by five cells

    Parameters

    • Default value y: number = 1

    Returns Canvas

erase

  • erase(x1: number, y1: number, x2: number, y2: number): Canvas
  • Erase the specified region. The region describes the rectangle shape which need to erase.

    example

    canvas.erase(0, 0, 5, 5);

    Parameters

    • x1: number
    • y1: number
    • x2: number
    • y2: number

    Returns Canvas

eraseLine

eraseScreen

eraseToDown

eraseToEnd

eraseToStart

eraseToUp

flush

  • Flush changes to the real terminal, taking only modified cells. Firstly, we get modified cells that have been affected by write method. Secondly, we compare these modified cells with the last frame. If cell has changes that doesn't equal to the cell from the last frame - write to the stream.

    Returns Canvas

foreground

  • foreground(color: string): Canvas
  • Set the foreground color. This color is used when text is rendering.

    example

    canvas.foreground('white'); canvas.foreground('#000000'); canvas.foreground('rgb(255, 255, 255)'); canvas.foreground('none'); // disables foreground filling (will be used default filling)

    Parameters

    • color: string

      Color name, rgb, hex or none if you want to disable foreground filling

    Returns Canvas

getPointerFromXY

  • getPointerFromXY(x?: number, y?: number): number
  • Get index of the virtual terminal representation from (x, y) coordinates.

    example

    canvas.getPointerFromXY(0, 0); // returns 0 canvas.getPointerFromXY(); // x and y in this case is current position of the cursor

    Parameters

    • Default value x: number = this.cursorX
    • Default value y: number = this.cursorY

    Returns number

    Returns index in the buffer array

getXYFromPointer

  • getXYFromPointer(index: number): [number, number]
  • Get (x, y) coordinate from the virtual terminal pointer.

    example

    canvas.getXYFromPointer(0); // returns [0, 0]

    Parameters

    • index: number

      Index in the buffer

    Returns [number, number]

    Returns an array [x, y]

hidden

  • hidden(isHidden?: boolean): Canvas
  • Toggle hidden display mode.

    example

    canvas.hidden(); // enable hidden mode canvas.hidden(false); // disable hidden mode

    Parameters

    • Default value isHidden: boolean = true

    Returns Canvas

hideCursor

  • Set the terminal cursor invisible. Applies immediately without calling flush.

    example

    canvas.hideCursor();

    Returns Canvas

left

  • Move the cursor left.

    example

    canvas.left(); // moves cursor left by one cell canvas.left(5); // moves cursor left by five cells

    Parameters

    • Default value x: number = 1

    Returns Canvas

moveBy

  • moveBy(x: number, y: number): Canvas
  • Move the cursor position relative to the current coordinates.

    example

    canvas.moveBy(5, 5); // moves cursor to the right and down by five cells

    Parameters

    • x: number

      Offset by X coordinate

    • y: number

      Offset by Y coordinate

    Returns Canvas

moveTo

  • moveTo(x: number, y: number): Canvas
  • Set the cursor position by absolute coordinates.

    example

    canvas.moveTo(10, 10); // moves cursor to the (10, 10) coordinate

    Parameters

    • x: number

      X coordinate

    • y: number

      Y coordinate

    Returns Canvas

reset

restoreScreen

  • Restore terminal state from the buffer. Applies immediately without calling flush.

    example

    canvas.restoreScreen();

    Returns Canvas

reverse

  • reverse(isReverse?: boolean): Canvas
  • Toggle reverse display mode.

    example

    canvas.reverse(); // enable reverse mode canvas.reverse(false); // disable reverse mode

    Parameters

    • Default value isReverse: boolean = true

    Returns Canvas

right

  • Move the cursor right.

    example

    canvas.right(); // moves cursor right by one cell canvas.right(5); // moves cursor right by five cells

    Parameters

    • Default value x: number = 1

    Returns Canvas

saveScreen

  • Save current terminal state into the buffer. Applies immediately without calling flush method.

    example

    canvas.saveScreen();

    Returns Canvas

showCursor

underlined

  • underlined(isUnderlined?: boolean): Canvas
  • Toggle underlined display mode.

    example

    canvas.underlined(); // enable underlined mode canvas.underlined(false); // disable underlined mode

    Parameters

    • Default value isUnderlined: boolean = true

    Returns Canvas

up

  • Move the cursor up.

    example

    canvas.up(); // moves cursor up by one cell canvas.up(5); // moves cursor up by five cells

    Parameters

    • Default value y: number = 1

    Returns Canvas

write

  • Write to the buffer. It doesn't apply immediately, but stores in virtual terminal that represented as array of Cell instances. For applying changes, you need to call flush method.

    example

    canvas.write('Hello, world').flush();

    Parameters

    • data: string

      Data to write to the terminal

    Returns Canvas

Static create

Object literals

cursorBackground

cursorBackground: object

b

b: number = -1

g

g: number = -1

r

r: number = -1

cursorDisplay

cursorDisplay: object

blink

blink: false = false

bold

bold: false = false

dim

dim: false = false

hidden

hidden: false = false

reverse

reverse: false = false

underlined

underlined: false = false

cursorForeground

cursorForeground: object

b

b: number = -1

g

g: number = -1

r

r: number = -1

Legend

  • Constructor
  • Property
  • Method
  • Property
  • Static method

Generated using TypeDoc