UNPKG

aahook

Version:

A CLI tool that displays ASCII art when commands succeed or fail

124 lines 2.84 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Renderer = void 0; /** * Renderer class for terminal output control * Handles ANSI escape sequences for animation rendering */ class Renderer { constructor(stdout = process.stdout) { this.stdout = stdout; this.isInteractive = stdout.isTTY || false; } /** * Hide terminal cursor */ hideCursor() { if (this.isInteractive) { this.stdout.write('\x1b[?25l'); } } /** * Show terminal cursor */ showCursor() { if (this.isInteractive) { this.stdout.write('\x1b[?25h'); } } /** * Clear current line */ clearLine() { if (this.isInteractive) { this.stdout.write('\x1b[2K\r'); } } /** * Clear screen from cursor position */ clearScreen() { if (this.isInteractive) { this.stdout.write('\x1b[0J'); } } /** * Move cursor to specific position */ moveCursor(x, y) { if (this.isInteractive) { this.stdout.write(`\x1b[${y};${x}H`); } } /** * Move cursor up by n lines */ moveCursorUp(lines) { if (this.isInteractive && lines > 0) { this.stdout.write(`\x1b[${lines}A`); } } /** * Move cursor down by n lines */ moveCursorDown(lines) { if (this.isInteractive && lines > 0) { this.stdout.write(`\x1b[${lines}B`); } } /** * Save current cursor position */ savePosition() { if (this.isInteractive) { this.stdout.write('\x1b7'); } } /** * Restore saved cursor position */ restorePosition() { if (this.isInteractive) { this.stdout.write('\x1b8'); } } /** * Write content to stdout */ write(content) { this.stdout.write(content); } /** * Write content with newline */ writeLine(content) { this.stdout.write(content + '\n'); } /** * Clean up and restore terminal state */ cleanup() { this.showCursor(); // Don't add extra newline here - let the animation handle it } /** * Check if terminal supports animations */ supportsAnimation() { return this.isInteractive && !process.env.CI && process.env.TERM !== 'dumb'; } /** * Get terminal dimensions */ getTerminalSize() { if (this.isInteractive) { return { columns: this.stdout.columns || 80, rows: this.stdout.rows || 24 }; } return { columns: 80, rows: 24 }; } } exports.Renderer = Renderer; //# sourceMappingURL=renderer.js.map