- Screen ⇐
EventEmitter
- 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.
- StyleIndexObject :
Object
The type containing all the possible styles for the text and the index array.
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. |
Kind: global class
Extends: EventEmitter
- Screen ⇐
EventEmitter
- new Screen(Terminal)
- .write(...args) ⇒
void
- .cursorTo(x, y) ⇒
void
- .moveCursor(x, y) ⇒
void
- .update() ⇒
void
- .print() ⇒
void
- .replaceAt(str, index, replacement) ⇒
string
- .mergeStyles(newStyleIndex, currentStyleIndex, startIndex, newSize) ⇒
Array.<StyleIndexObject>
- .sortByIndex(a, b) ⇒
number
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)
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' })
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)
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)
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()
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()
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] }]
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)
The width of the screen.
The height of the screen.
The screen buffer object.
The cursor object.
Kind: global constant