File size: 1,759 Bytes
3530df7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# @inquirer/ansi

A lightweight package providing ANSI escape sequences for terminal cursor manipulation and screen clearing.

# Installation

<table>
<tr>
  <th>npm</th>
  <th>yarn</th>
</tr>
<tr>
<td>

```sh
npm install @inquirer/ansi
```

</td>
<td>

```sh
yarn add @inquirer/ansi
```

</td>
</tr>
</table>

## Usage

```js
import {
  cursorUp,
  cursorDown,
  cursorTo,
  cursorLeft,
  cursorHide,
  cursorShow,
  eraseLines,
} from '@inquirer/ansi';

// Move cursor up 3 lines
process.stdout.write(cursorUp(3));

// Move cursor to specific position (x: 10, y: 5)
process.stdout.write(cursorTo(10, 5));

// Hide/show cursor
process.stdout.write(cursorHide);
process.stdout.write(cursorShow);

// Clear 5 lines
process.stdout.write(eraseLines(5));
```

Or when used inside an inquirer prompt:

```js
import { cursorHide } from '@inquirer/ansi';
import { createPrompt } from '@inquirer/core';

export default createPrompt((config, done: (value: void) => void) => {
  return `Choose an option${cursorHide}`;
});
```

## API

### Cursor Movement

- **`cursorUp(count?: number)`** - Move cursor up by `count` lines (default: 1)
- **`cursorDown(count?: number)`** - Move cursor down by `count` lines (default: 1)
- **`cursorTo(x: number, y?: number)`** - Move cursor to position (x, y). If y is omitted, only moves horizontally
- **`cursorLeft`** - Move cursor to beginning of line

### Cursor Visibility

- **`cursorHide`** - Hide the cursor
- **`cursorShow`** - Show the cursor

### Screen Manipulation

- **`eraseLines(count: number)`** - Clear `count` lines and position cursor at the beginning of the first cleared line

# License

Copyright (c) 2025 Simon Boudrias (twitter: [@vaxilart](https://twitter.com/Vaxilart))<br/>
Licensed under the MIT license.