Skip to content

Latest commit

 

History

History
215 lines (162 loc) · 7.15 KB

Screen.md

File metadata and controls

215 lines (162 loc) · 7.15 KB

Classes

ScreenEventEmitter

Constants

width : number

The width of the screen.

height : number

The height of the screen.

buffer : Array

The screen buffer object.

cursor : object

The cursor object.

Interfaces

StyleIndexObject : Object

The type containing all the possible styles for the text and the index array.

StyleIndexObject : Object

The type containing all the possible styles for the text and the index array.

Kind: global interface
Extends: StyleObject
Properties

Name Type Description
index Array.<number>

The index of the style in the style array.

Screen ⇐ EventEmitter

Kind: global class
Extends: EventEmitter

new Screen(Terminal)

This class is used to manage the screen buffer.

Param Type Description
Terminal object

The terminal object (process.stdout).

Example

const screen = new Screen(process.stdout)

screen.write(...args) ⇒ void

This method is used to write or overwrite a row in the screen buffer at a specific position.

Kind: instance method of Screen

Param Type Description
...args arguments.<object>

The row to write.

Example

screen.write({ text: 'Hello World', color: 'white' })
  screen.write({ text: 'Hello World', color: 'white' }, { text: 'Hello World', color: 'white' })

screen.cursorTo(x, y) ⇒ void

This method is used to change the cursor position.

Kind: instance method of Screen

Param Type Description
x number

The x position.

y number

The y position.

Example

screen.cursorTo(0, 0)

screen.moveCursor(x, y) ⇒ void

This method is used to change the Terminal cursor position.

Kind: instance method of Screen

Param Type Description
x number

The x position.

y number

The y position.

Example

screen.moveCursor(0, 0)

screen.update() ⇒ void

This method is used to clear the screen. It fills the screen buffer with empty rows with the size of the screen.

Kind: instance method of Screen
Example

screen.clear()

screen.print() ⇒ void

This method is used to print the screen buffer to the terminal. It also converts the styles to the terminal format using Chalk.

Kind: instance method of Screen
Example

screen.print()

screen.replaceAt(str, index, replacement) ⇒ string

This method is used to insert a substring into a string at a specific position.

Kind: instance method of Screen

Param Type Description
str string

The string to insert into.

index number

The position to insert the substring.

replacement string

The substring to insert.

Example

screen.replaceAt('Hello Luca', 6, 'Elia') // returns 'Hello Elia'

screen.mergeStyles(newStyleIndex, currentStyleIndex, startIndex, newSize) ⇒ Array.<StyleIndexObject>

This method is used to merge two styleIndex arrays into one. It also recalculates the indexes for the new row.

Kind: instance method of Screen

Param Type Description
newStyleIndex Array.<StyleIndexObject>

The new styleIndex array.

currentStyleIndex Array.<StyleIndexObject>

The current styleIndex array.

startIndex number

The start index of the new styleIndex array (Usually the cursor.x).

newSize number

The new size of the string.

Example

screen.mergeStyles([{ color: 'red', bg: 'black', italic: false, bold: false, index: [0, 5] }, { color: 'white', bg: 'black', italic: false, bold: false, index: [6, 10] }], [{ color: 'magenta', bg: 'black', italic: false, bold: false, index: [0, 30] }], 5, 15)
returns [{ color: 'magenta', bg: 'black', italic: false, bold: false, index: [0, 4] }, { color: 'red', bg: 'black', italic: false, bold: false, index: [5, 10] }, { color: 'white', bg: 'black', italic: false, bold: false, index: [11, 15] }, { color: 'magenta', bg: 'black', italic: false, bold: false, index: [16, 30] }]

screen.sortByIndex(a, b) ⇒ number

This method is used to sort an array of styleIndex objects by child index[0].

Kind: instance method of Screen

Param Type Description
a StyleIndexObject

The first object to compare.

b StyleIndexObject

The second object to compare.

Example

merged.sort(this.sortByIndex)

width : number

The width of the screen.

Kind: global constant

height : number

The height of the screen.

Kind: global constant

buffer : Array

The screen buffer object.

Kind: global constant

cursor : object

The cursor object.

Kind: global constant