"use strict";
/* Socket Lib - Built with rolldown */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_runtime = require('../_virtual/_rolldown/runtime.js');
const require_stdio__internal = require('./_internal.js');
let node_process = require("node:process");
node_process = require_runtime.__toESM(node_process);
let node_tty = require("node:tty");

//#region src/stdio/stdout.ts
/**
* @file Standard output stream utilities. Provides utilities for writing to
*   stdout with formatting and control.
*/
const stdout = node_process.default.stdout;
let _cursorExitRegistered = false;
/**
* Clear the current line on stdout. Only works in TTY environments.
*
* @example
*   ;```ts
*   write('Processing...')
*   clearLine()
*   write('Done!')
*   ```
*/
function clearLine() {
	require_stdio__internal.clearLineOn(stdout);
}
/**
* 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
*   ```
*/
function clearScreenDown() {
	if (stdout.isTTY) stdout.clearScreenDown();
}
/**
* Move cursor to specific position on stdout. Only works in TTY environments.
*
* @example
*   ;```ts
*   cursorTo(0) // Move to start of line
*   cursorTo(10, 5) // Move to column 10, row 5
*   ```
*
* @param x - Column position (0-based)
* @param y - Row position (0-based, optional)
*/
function cursorTo(x, y) {
	require_stdio__internal.cursorToOn(stdout, x, y);
}
/**
* 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
*   ```
*/
function ensureCursorOnExit() {
	if (_cursorExitRegistered) return;
	_cursorExitRegistered = true;
	node_process.default.on("exit", showCursor);
	node_process.default.on("SIGINT", () => {
		showCursor();
		node_process.default.exit(130);
	});
	node_process.default.on("SIGTERM", () => {
		showCursor();
		node_process.default.exit(143);
	});
}
/**
* Get the number of columns (width) in the terminal.
*
* @example
*   ```ts
*   const width = getColumns()
*   console.log(`Terminal is ${width} characters wide`)
*   ```
*
* @default 80
*
* @returns Terminal width in characters
*/
function getColumns() {
	return require_stdio__internal.getColumnsOf(stdout);
}
/**
* Get the number of rows (height) in the terminal.
*
* @example
*   ```ts
*   const height = getRows()
*   console.log(`Terminal is ${height} lines tall`)
*   ```
*
* @default 24
*
* @returns Terminal height in lines
*/
function getRows() {
	return require_stdio__internal.getRowsOf(stdout);
}
/**
* Hide the cursor on stdout. Useful for cleaner output during animations.
*
* @example
*   ;```ts
*   hideCursor()
*   // Show animation
*   showCursor()
*   ```
*/
function hideCursor() {
	if (stdout.isTTY && stdout instanceof node_tty.WriteStream) stdout.write("\x1B[?25l");
}
/**
* Check if stdout is connected to a TTY (terminal).
*
* @example
*   ;```ts
*   if (isTTY()) {
*     // Show interactive UI
*   } else {
*     // Use simple text output
*   }
*   ```
*
* @returns `true` if stdout is a TTY, `false` if piped/redirected
*/
function isTTY() {
	return require_stdio__internal.isTTYOf(stdout);
}
/**
* Show the cursor on stdout. Should be called after `hideCursor()`.
*
* @example
*   ;```ts
*   hideCursor()
*   // Show animation
*   showCursor()
*   ```
*/
function showCursor() {
	if (stdout.isTTY && stdout instanceof node_tty.WriteStream) stdout.write("\x1B[?25h");
}
/**
* Write text to stdout without adding a newline.
*
* @example
*   ;```ts
*   write('Loading...')
*   // Later: clear and update
*   ```
*
* @param text - Text to write.
*/
function write(text) {
	stdout.write(text);
}
/**
* Write a line to stdout with trailing newline.
*
* @example
*   ;```ts
*   writeLine('Hello, world!')
*   writeLine() // Write empty line
*   ```
*
* @default text ''
*
* @param text - Text to write.
*/
function writeLine(text = "") {
	stdout.write(`${text}\n`);
}

//#endregion
exports.clearLine = clearLine;
exports.clearScreenDown = clearScreenDown;
exports.cursorTo = cursorTo;
exports.ensureCursorOnExit = ensureCursorOnExit;
exports.getColumns = getColumns;
exports.getRows = getRows;
exports.hideCursor = hideCursor;
exports.isTTY = isTTY;
exports.showCursor = showCursor;
exports.stdout = stdout;
exports.write = write;
exports.writeLine = writeLine;