@socketsecurity/lib
Version:
Core utilities and infrastructure for Socket.dev security tools
145 lines (144 loc) • 3.08 kB
TypeScript
// Get the actual stdout stream
declare const stdout: NodeJS.WriteStream;
/**
* Write a line to stdout with trailing newline.
*
* @param text - Text to write
* @default text ''
*
* @example
* ```ts
* writeLine('Hello, world!')
* writeLine() // Write empty line
* ```
*/
export declare function writeLine(text?: string): void;
/**
* Write text to stdout without adding a newline.
*
* @param text - Text to write
*
* @example
* ```ts
* write('Loading...')
* // Later: clear and update
* ```
*/
export declare function write(text: string): void;
/**
* Clear the current line on stdout.
* Only works in TTY environments.
*
* @example
* ```ts
* write('Processing...')
* clearLine()
* write('Done!')
* ```
*/
export declare function clearLine(): void;
/**
* Move cursor to specific position on stdout.
* Only works in TTY environments.
*
* @param x - Column position (0-based)
* @param y - Row position (0-based, optional)
*
* @example
* ```ts
* cursorTo(0) // Move to start of line
* cursorTo(10, 5) // Move to column 10, row 5
* ```
*/
export declare function cursorTo(x: number, y?: number | undefined): void;
/**
* Clear screen from cursor position down to bottom.
* Only works in TTY environments.
*
* @example
* ```ts
* cursorTo(0, 5)
* clearScreenDown() // Clear from row 5 to bottom
* ```
*/
export declare function clearScreenDown(): void;
/**
* Check if stdout is connected to a TTY (terminal).
*
* @returns `true` if stdout is a TTY, `false` if piped/redirected
*
* @example
* ```ts
* if (isTTY()) {
* // Show interactive UI
* } else {
* // Use simple text output
* }
* ```
*/
export declare function isTTY(): boolean;
/**
* Get the number of columns (width) in the terminal.
*
* @returns Terminal width in characters
* @default 80
*
* @example
* ```ts
* const width = getColumns()
* console.log(`Terminal is ${width} characters wide`)
* ```
*/
export declare function getColumns(): number;
/**
* Get the number of rows (height) in the terminal.
*
* @returns Terminal height in lines
* @default 24
*
* @example
* ```ts
* const height = getRows()
* console.log(`Terminal is ${height} lines tall`)
* ```
*/
export declare function getRows(): number;
/**
* Hide the cursor on stdout.
* Useful for cleaner output during animations.
*
* @example
* ```ts
* hideCursor()
* // Show animation
* showCursor()
* ```
*/
export declare function hideCursor(): void;
/**
* Show the cursor on stdout.
* Should be called after `hideCursor()`.
*
* @example
* ```ts
* hideCursor()
* // Show animation
* showCursor()
* ```
*/
export declare function showCursor(): void;
/**
* Register handlers to ensure cursor is shown on process exit.
* Prevents hidden cursor after abnormal termination.
* Handles SIGINT (Ctrl+C) and SIGTERM signals.
*
* @example
* ```ts
* ensureCursorOnExit()
* hideCursor()
* // Even if process crashes, cursor will be restored
* ```
*/
export declare function ensureCursorOnExit(): void;
// Export the raw stream for advanced usage
export { stdout };