0.1.0 • Published 9 years ago

d-ashesss-console v0.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

Console

Provides interface to linux console advanced features.

Install via npm

npm install d-ashesss-console

Demo

To watch a demonstration run bin/demo

Usage

Console

require("d-ashesss-console");

Package will include its features into global console object.

Console::reset() - Resets the terminal to initial state

console.reset;

Console::write() - Writes to stdout without trailing newline

console.write("Hello World!");

Cursor

console.write("OOOOO\nOOOOO\nOOOOO\n");

Cursor::moveUp() - Moves cursor N lines up

console.cursor.moveUp(3);
console.write("X");
XOOOO
OOOOO
OOOOO

Cursor::moveDown() - Moves cursor N lines down

console.cursor.moveDown(2);
console.write("X");
xOOOO
OOOOO
OXOOO

Cursor::moveRight() - Moves cursor N characters right

console.cursor.moveRight(2);
console.write("X");
xOOOO
OOOOO
OxOOX

Cursor::moveLeft() - Moves cursor N characters left

console.cursor.moveLeft(2);
console.write("X");
xOOOO
OOOOO
OxOXx

Cursor::move() - Moves cursor by X:Y

console.cursor.move(-3, -1);
console.write("X");
xOOOO
OXOOO
OxOxx

Cursor::moveTo() - Moves cursor to X:Y position on screen

console.cursor.moveTo(3, 0);
console.write("X");
xOOXO
OxOOO
OxOxx

Cursor::save() - Saves cursor position and attributes. Only one position can be saved at a time: each time you call save() it overrides previously saved position.

Cursor::restore() - Restores cursor position and attributes

console.write("OOOOO\nOO");
console.cursor.save();
console.write("OOO\nOOOOO\n");
console.cursor.restore();
console.write("X");
OOOOO
OOXOO
OOOOO

Screen

Screen::init() - Saves current screen and created new empty session. Behavior is similar to such applications as Vim or Less.

Screen::restore() - Restores screen saved by Screen::init()

Screen::clearUp() - Clears screen up from cursor, including line to the left of cursor

console.write("OOOOO\nOOOOO\nOOOOO\n");
console.cursor.moveTo(2, 1);
console.screen.clearUp();
.....
...OO
OOOOO

Screen::clearDown() - Clears screen down from cursor, including line to the right of cursor

console.write("OOOOO\nOOOOO\nOOOOO\n");
console.cursor.moveTo(2, 1);
console.screen.clearDown();
OOOOO
OO...
.....

Screen::clearLeft() - Clears line to the left of cursor, including cursor position

console.write("OOOOO\nOOOOO\nOOOOO\n");
console.cursor.moveTo(2, 1);
console.screen.clearLeft();
OOOOO
...OO
OOOOO

Screen::clearRight() - Clears line to the right of cursor, including cursor position

console.write("OOOOO\nOOOOO\nOOOOO\n");
console.cursor.moveTo(2, 1);
console.screen.clearRight();
OOOOO
OO...
OOOOO

Screen::clearLine() - Clears entire line and moves cursor to the beginning of the line

console.write("OOOOO\nOOOOO\nOOOOO\n");
console.cursor.moveTo(2, 1);
console.screen.clearLine();
console.write("X");
OOOOO
X....
OOOOO

Screen::clear() - Clears entire screen and moves cursor to upper left corner