UNPKG

@remotex-labs/xansi

Version:

A lightweight ANSI utility library for styling terminal output

122 lines (121 loc) 3.37 kB
// src/components/ansi.component.ts function E(R) { process.stdout.write ? process.stdout.write(R) : console.log(R); } function t(R, r = 0) { return `\x1B[${R};${r}H`; } function e(R) { return R.replace(/\x1b\[[0-9;]*m/g, ""); } var x = { /** * Clears from the cursor to the end of the line * * @see https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_sequences * @since 1.0.0 */ CLEAR_LINE: "\x1B[K", /** * Moves the cursor to the "home" position (row 1, column 1). * * @see https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_sequences * @since 1.2.0 */ CURSOR_HOME: "\x1B[H", /** * Hides the cursor * * @see https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_sequences * @since 1.0.0 */ HIDE_CURSOR: "\x1B[?25l", /** * Shows the cursor * * @see https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_sequences * @since 1.0.0 */ SHOW_CURSOR: "\x1B[?25h", /** * Saves the current cursor position * * @see https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_sequences * @since 1.0.0 */ SAVE_CURSOR: "\x1B[s", /** * Restores the cursor to the previously saved position * * @see https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_sequences * @since 1.0.0 */ RESTORE_CURSOR: "\x1B[u", /** * Resets the terminal to its initial state (RIS - Reset to Initial State). * Clears screen, scrollback buffer, and most settings. * This is a "hard reset" escape code. * * @see https://en.wikipedia.org/wiki/ANSI_escape_code#Reset_(RIS) * @since 1.0.0 */ RESET_TERMINAL: "\x1Bc", /** * Clears the screen from the cursor position to the end of the screen. * * Equivalent to `ESC[J` or `ESC[0J`. * Leaves the scrollback buffer intact. * * @see https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_sequences * @since 1.0.0 */ CLEAR_SCREEN_DOWN: "\x1B[0J", /** * Clears the screen from the cursor position to the beginning of the screen. * * Equivalent to `ESC[1J`. * * @see https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_sequences * @since 1.0.0 */ CLEAR_SCREEN_UP: "\x1B[1J", /** * Clears the entire screen and moves the cursor to the home position (top-left). * * Equivalent to `ESC[2JESC[H`. * Does not clear the scrollback buffer. * * @see https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_sequences * @since 1.0.0 */ CLEAR_SCREEN: "\x1B[2J\x1B[H", /** * Clears the entire screen and deletes all lines saved in the scrollback buffer. * * Equivalent to `ESC[3JESC[H`. * Supported in xterm and many modern terminal emulators. * * @see https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_sequences * @since 1.0.0 */ CLEAR_SCREEN_FULL: "\x1B[3J\x1B[H", /** * Moves the cursor to the beginning of the current line (column 1). * * @remarks * Unlike `\r` (carriage return), this is an ANSI escape sequence that * explicitly positions the cursor at column 1, regardless of terminal state. * It does not affect the row — only the horizontal position is changed. * * @see https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_sequences * @since 1.3.0 */ CURSOR_LINE_START: "\x1B[1G" }; export { x as ANSI, t as moveCursor, e as stripAnsi, E as writeRaw }; //# sourceMappingURL=ansi.component.js.map