or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

advanced.mdcursor.mdindex.mdlines.mdscreen.md
tile.json

index.mddocs/

ANSI Escapes

ANSI Escapes provides a comprehensive collection of ANSI escape codes for terminal manipulation, enabling precise control over cursor positioning, screen clearing, text formatting, and terminal display properties. It offers cross-platform compatibility and supports both Node.js and browser environments.

Package Information

  • Package Name: ansi-escapes
  • Package Type: npm
  • Language: JavaScript (ES Module)
  • Installation: npm install ansi-escapes

Core Imports

import ansiEscapes from 'ansi-escapes';

For named imports:

import { cursorTo, cursorUp, clearScreen, beep } from 'ansi-escapes';

For CommonJS environments:

const ansiEscapes = require('ansi-escapes');

Basic Usage

import ansiEscapes from 'ansi-escapes';

// Move cursor to position (10, 5) and clear the line
process.stdout.write(ansiEscapes.cursorTo(10, 5) + ansiEscapes.eraseLine);

// Move cursor up 2 rows and to the left edge
process.stdout.write(ansiEscapes.cursorUp(2) + ansiEscapes.cursorLeft);

// Clear the entire terminal
process.stdout.write(ansiEscapes.clearTerminal);

// Create a clickable link
console.log(ansiEscapes.link('Click here', 'https://example.com'));

Browser Usage with Xterm.js:

import ansiEscapes from 'ansi-escapes';
import { Terminal } from 'xterm';

const terminal = new Terminal();
terminal.write(ansiEscapes.cursorUp(2) + ansiEscapes.cursorLeft);

Architecture

ANSI Escapes is organized around several key functional areas:

  • Cursor Control: Functions and constants for positioning, movement, and visibility
  • Screen Management: Operations for clearing, scrolling, and screen buffer control
  • Line Operations: Targeted erasing of lines and line portions
  • Advanced Features: Hyperlinks, images, and iTerm2-specific functionality

All functions return ANSI escape code strings that can be written directly to terminal outputs or used with terminal emulators.

Capabilities

Cursor Positioning and Movement

Core cursor control operations for precise terminal positioning and relative movement.

function cursorTo(x: number, y?: number): string;
function cursorMove(x: number, y?: number): string;
function cursorUp(count?: number): string;
function cursorDown(count?: number): string;
function cursorForward(count?: number): string;
function cursorBackward(count?: number): string;

const cursorLeft: string;
const cursorSavePosition: string;
const cursorRestorePosition: string;
const cursorGetPosition: string;
const cursorNextLine: string;
const cursorPrevLine: string;
const cursorHide: string;
const cursorShow: string;

Cursor Operations

Screen and Terminal Management

Operations for managing terminal display, clearing screens, and controlling screen buffers.

const clearScreen: string;
const clearTerminal: string;
const enterAlternativeScreen: string;
const exitAlternativeScreen: string;
const scrollUp: string;
const scrollDown: string;
const eraseScreen: string;
const beep: string;

Screen Management

Line Erasing Operations

Targeted line manipulation for clearing specific portions of terminal lines.

function eraseLines(count: number): string;

const eraseEndLine: string;
const eraseStartLine: string;
const eraseLine: string;
const eraseDown: string;
const eraseUp: string;

Line Operations

Advanced Terminal Features

Modern terminal features including hyperlinks, image display, and iTerm2 integration.

function link(text: string, url: string): string;
function image(data: Uint8Array, options?: ImageOptions): string;

const iTerm: {
  setCwd(cwd?: string): string;
  annotation(message: string, options?: AnnotationOptions): string;
};

Advanced Features

Types

interface ImageOptions {
  width?: 'auto' | number | string;
  height?: 'auto' | number | string; 
  preserveAspectRatio?: boolean;
}

interface AnnotationOptions {
  length?: number;
  x?: number;
  y?: number;
  isHidden?: boolean;
}