Comprehensive Node.js terminal library with 256 colors, interactive components, and advanced graphics capabilities
—
Terminal control capabilities provide low-level access to cursor positioning, screen manipulation, scrolling, and display area management. All methods are chainable and return the Terminal instance.
terminal.moveTo(x: number, y: number): Terminal;Move cursor to absolute position (1-based coordinates).
term.moveTo(10, 5).cyan('Text at column 10, row 5');terminal.move(x: number, y: number): Terminal;
terminal.up(n?: number): Terminal;
terminal.down(n?: number): Terminal;
terminal.left(n?: number): Terminal;
terminal.right(n?: number): Terminal;Move cursor relative to current position. Default movement is 1 unit.
term.up(3).right(5).red('Moved up 3, right 5');terminal.nextLine(n?: number): Terminal;
terminal.previousLine(n?: number): Terminal;
terminal.column(x: number): Terminal;Move to beginning of next/previous line or specific column.
term.nextLine(2).column(1).green('Two lines down, column 1');terminal.getCursorLocation(callback: (error: Error | null, x: number, y: number) => void): void;Get current cursor position asynchronously.
term.getCursorLocation((error, x, y) => {
if (!error) {
console.log(`Cursor at ${x}, ${y}`);
}
});terminal.clear(): Terminal;
terminal.eraseDisplayBelow(): Terminal;
terminal.eraseDisplayAbove(): Terminal;
terminal.eraseEntireDisplay(): Terminal;Clear entire screen or specific display areas.
term.clear(); // Clear entire screen
term.eraseDisplayBelow(); // Clear from cursor downterminal.eraseLineAfter(): Terminal;
terminal.eraseLineBefore(): Terminal;
terminal.eraseEntireLine(): Terminal;Clear parts of current line.
term.eraseLineAfter(); // Clear from cursor to end of line
term.eraseEntireLine(); // Clear entire current lineterminal.scrollUp(n?: number): Terminal;
terminal.scrollDown(n?: number): Terminal;Scroll the entire screen or current scrolling region.
term.scrollUp(3); // Scroll up 3 lines
term.scrollDown(); // Scroll down 1 lineterminal.scrollingRegion(top: number, bottom: number): Terminal;
terminal.resetScrollingRegion(): Terminal;Set or reset the scrollable region of the screen.
term.scrollingRegion(5, 20); // Set scrolling region from line 5 to 20
term.resetScrollingRegion(); // Reset to full screen scrollingterminal.insertLine(n?: number): Terminal;
terminal.deleteLine(n?: number): Terminal;Insert or delete lines at cursor position.
term.insertLine(2); // Insert 2 blank lines
term.deleteLine(); // Delete current lineterminal.insert(n?: number): Terminal;
terminal.delete(n?: number): Terminal;
terminal.backDelete(n?: number): Terminal;Insert spaces, delete characters forward, or delete characters backward.
term.insert(5); // Insert 5 spaces
term.delete(3); // Delete 3 characters forward
term.backDelete(2); // Delete 2 characters backwardterminal.wrapColumn(x: number): Terminal;Set the column where text wrapping occurs.
term.wrapColumn(80); // Wrap text at column 80terminal.grabInput(options?: GrabInputOptions): void;
terminal.releaseInput(): void;Enable or disable input grabbing for keyboard and mouse events.
interface GrabInputOptions {
mouse?: boolean | string;
focus?: boolean;
}// Enable input grabbing with mouse support
term.grabInput({ mouse: 'button' });
// Handle key events
term.on('key', (name, matches, data) => {
if (name === 'CTRL_C') {
term.releaseInput();
process.exit();
}
});
// Release input when done
term.releaseInput();// Terminal dimensions
terminal.width: number;
terminal.height: number;
// Terminal identification
terminal.appName: string;
terminal.appId: string;
terminal.generic: string;Access terminal dimensions and identification information.
console.log(`Terminal size: ${term.width}x${term.height}`);
console.log(`Terminal type: ${term.generic}`);const term = require('terminal-kit').terminal;
// Draw a box using cursor control
term.clear()
.moveTo(10, 5).cyan('+')
.move(10, 0).cyan('+')
.move(0, 5).cyan('+')
.move(-10, 0).cyan('+')
.moveTo(11, 5).cyan('─'.repeat(9))
.moveTo(11, 10).cyan('─'.repeat(9))
.moveTo(10, 6).cyan('│')
.moveTo(10, 7).cyan('│')
.moveTo(10, 8).cyan('│')
.moveTo(10, 9).cyan('│')
.moveTo(20, 6).cyan('│')
.moveTo(20, 7).cyan('│')
.moveTo(20, 8).cyan('│')
.moveTo(20, 9).cyan('│')
.moveTo(12, 7).white('Hello Box!')
.moveTo(1, 12);const term = require('terminal-kit').terminal;
term.grabInput({ mouse: 'button' });
term.on('mouse', (name, data) => {
if (name === 'MOUSE_LEFT_BUTTON_PRESSED') {
term.moveTo(data.x, data.y)
.bgRed(' ')
.moveTo(1, term.height);
}
});
term.on('key', (name) => {
if (name === 'CTRL_C') {
term.releaseInput();
process.exit();
}
});Install with Tessl CLI
npx tessl i tessl/npm-terminal-kit