@remotex-labs/xansi
Version:
A lightweight ANSI utility library for styling terminal output
147 lines (145 loc) • 4.09 kB
JavaScript
;
var e = Object.defineProperty;
var o = Object.getOwnPropertyDescriptor;
var s = Object.getOwnPropertyNames;
var n = Object.prototype.hasOwnProperty;
var C = (R, r) => {
for (var t in r)
e(R, t, { get: r[t], enumerable: !0 });
}, S = (R, r, t, x) => {
if (r && typeof r == "object" || typeof r == "function")
for (let E of s(r))
!n.call(R, E) && E !== t && e(R, E, { get: () => r[E], enumerable: !(x = o(r, E)) || x.enumerable });
return R;
};
var _ = (R) => S(e({}, "__esModule", { value: !0 }), R);
// src/components/ansi.component.ts
var A = {};
C(A, {
ANSI: () => c,
moveCursor: () => b,
stripAnsi: () => u,
writeRaw: () => i
});
module.exports = _(A);
function i(R) {
process.stdout.write ? process.stdout.write(R) : console.log(R);
}
function b(R, r = 0) {
return `\x1B[${R};${r}H`;
}
function u(R) {
return R.replace(/\x1b\[[0-9;]*m/g, "");
}
var c = {
/**
* 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"
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
ANSI,
moveCursor,
stripAnsi,
writeRaw
});
//# sourceMappingURL=ansi.component.js.map