ansi-escapes
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
type-fest | 3.13.1 | 76.66 kB | (MIT OR CC0-1.0) | prod |
The ansi-escapes package provides ANSI escape codes for manipulating the terminal in JavaScript. ANSI escape codes are sequences of bytes which can be used to control formatting, color, and other output layout tasks in text terminals. This npm package can be used to move the cursor, erase text, scroll display, and even display images or create clickable links in compatible terminals.
To use ansi-escapes, you first need to install it via npm using the command npm install ansi-escapes
. You can then import ansi-escapes in your JavaScript file using ES6 imports. Here is an example of how to move the cursor two rows up and to the left:
import ansiEscapes from 'ansi-escapes';
process.stdout.write(ansiEscapes.cursorUp(2) + ansiEscapes.cursorLeft);
This will result in the code '\u001B[2A\u001B[1000D' which performs the desired actions in the terminal. The package can also be used in the browser with Xterm.js:
import ansiEscapes from 'ansi-escapes';
import {Terminal} from 'xterm';
import 'xterm/css/xterm.css';
const terminal = new Terminal({...});
terminal.write(ansiEscapes.cursorUp(2) + ansiEscapes.cursorLeft);
The ansi-escapes documentation is found in the package's README on GitHub. It gives a complete list of all of the functions available in the package and how to use them. Each function is accompanied by short descriptions and examples that demonstrate their usage. Among these, you can find functions to manipulate the cursor position, to erase lines, to scroll up and down, to display images, create clickable links, and many other useful terminal manipulations. So, for a detailed guide on how to use ansi-escapes, the README on GitHub is the best source to refer to.