ANSI Constants
The ansi module exposes every low-level ANSI / VT100 escape sequence used internally by ts-better-console. You can import any of them directly if you need fine-grained terminal control.
Byte Enum
Raw byte values for protocol-level buffer parsing (mouse events, escape sequence detection).
enum Byte {ESC = 0x1b,}
BRACKET = 0x5b,
MOUSE_M = 0x4d,
Control Characters
const CTRL_C = "\x03";
const BACKSPACE = "\x7f";
Primitives
const ESC = "\x1b";
const CSI = "\x1b[";
Cursor
const CURSOR_SAVE = "\x1b7";
const CURSOR_RESTORE = "\x1b8";
const CURSOR_HIDE = "\x1b[?25l";
const CURSOR_SHOW = "\x1b[?25h";
const cursorUp = (n: number) => `${CSI}${n}A`;
const cursorDown = (n: number) => `...B`;
const cursorForward = (n: number) => `...C`;
const cursorBackward = (n: number) => `...D`;
const cursorTo = (row: number, col: number = 1) => `...H`;
const cursorToColumn = (col: number) => `...G`;
Erase
const ERASE_LINE = "\x1b[2K"; // erase entire line
const ERASE_TO_EOL = "\x1b[K"; // erase to end of line
const ERASE_BELOW = "\x1b[0J"; // erase below cursor
const ERASE_TO_END = "\x1b[J"; // erase to end of screen
const INSERT_LINE = "\x1b[L"; // insert blank line
Scroll Region
const SCROLL_RESET = "\x1b[r";
const scrollRegion = (top: number, bottom: number) => `...r`;
Line Wrapping & Mouse
const WRAP_ON = "\x1b[?7h";
const WRAP_OFF = "\x1b[?7l";
const MOUSE_ON = "\x1b[?1000h";
const MOUSE_OFF = "\x1b[?1000l";
Arrow Keys
const KEY_UP = "\x1b[A";
const KEY_DOWN = "\x1b[B";
const KEY_RIGHT = "\x1b[C";
const KEY_LEFT = "\x1b[D";
SGR Helpers
const RESET = "\x1b[0m"; // also exported as cls
const DIM = "\x1b[2m";
const DIM_OFF = "\x1b[22m";
Helpers
Utility functions for working with ANSI-encoded strings.
const stripAnsi = (str: string) => string;
// Removes all ANSI escape sequences, returning only visible text
const visible = stripAnsi("\x1b[31mred text\x1b[0m"); // → "red text"
Import
import {CURSOR_HIDE, CURSOR_SHOW,} from "ts-better-console";
cursorTo, cursorForward, cursorToColumn,
ERASE_LINE,
RESET,
stripAnsi,
Want to support this project?
If you find ts-better-console useful and want to support its development, consider starring the GitHub repository or buying me a coffee! Your support helps me dedicate more time to improving the library and adding new features.
Want to contribute to this project?
Contributions are welcome! If you're interested in improving the library, fixing bugs, or adding new features, feel free to check out the GitHub repository and submit a pull request. Whether you're a seasoned developer or new to open source, your contributions can make a difference!