@inquirer/ansi 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +99 -0
- package/dist/commonjs/index.d.ts +14 -0
- package/dist/commonjs/index.js +28 -0
- package/dist/commonjs/package.json +3 -0
- package/dist/esm/index.d.ts +14 -0
- package/dist/esm/index.js +21 -0
- package/dist/esm/package.json +3 -0
- package/package.json +96 -0
package/README.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# @inquirer/ansi
|
|
2
|
+
|
|
3
|
+
A lightweight package providing ANSI escape sequences for terminal cursor manipulation and screen clearing.
|
|
4
|
+
|
|
5
|
+
# Special Thanks
|
|
6
|
+
|
|
7
|
+
<div align="center" markdown="1">
|
|
8
|
+
|
|
9
|
+
[](https://graphite.dev/?utm_source=github&utm_medium=repo&utm_campaign=inquirerjs)<br>
|
|
10
|
+
|
|
11
|
+
### [Graphite is the AI developer productivity platform helping teams on GitHub ship higher quality software, faster](https://graphite.dev/?utm_source=github&utm_medium=repo&utm_campaign=inquirerjs)
|
|
12
|
+
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
# Installation
|
|
16
|
+
|
|
17
|
+
<table>
|
|
18
|
+
<tr>
|
|
19
|
+
<th>npm</th>
|
|
20
|
+
<th>yarn</th>
|
|
21
|
+
</tr>
|
|
22
|
+
<tr>
|
|
23
|
+
<td>
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
npm install @inquirer/ansi
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
</td>
|
|
30
|
+
<td>
|
|
31
|
+
|
|
32
|
+
```sh
|
|
33
|
+
yarn add @inquirer/ansi
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
</td>
|
|
37
|
+
</tr>
|
|
38
|
+
</table>
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
|
|
42
|
+
```js
|
|
43
|
+
import {
|
|
44
|
+
cursorUp,
|
|
45
|
+
cursorDown,
|
|
46
|
+
cursorTo,
|
|
47
|
+
cursorLeft,
|
|
48
|
+
cursorHide,
|
|
49
|
+
cursorShow,
|
|
50
|
+
eraseLines,
|
|
51
|
+
} from '@inquirer/ansi';
|
|
52
|
+
|
|
53
|
+
// Move cursor up 3 lines
|
|
54
|
+
process.stdout.write(cursorUp(3));
|
|
55
|
+
|
|
56
|
+
// Move cursor to specific position (x: 10, y: 5)
|
|
57
|
+
process.stdout.write(cursorTo(10, 5));
|
|
58
|
+
|
|
59
|
+
// Hide/show cursor
|
|
60
|
+
process.stdout.write(cursorHide);
|
|
61
|
+
process.stdout.write(cursorShow);
|
|
62
|
+
|
|
63
|
+
// Clear 5 lines
|
|
64
|
+
process.stdout.write(eraseLines(5));
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Or when used inside an inquirer prompt:
|
|
68
|
+
|
|
69
|
+
```js
|
|
70
|
+
import { cursorHide } from '@inquirer/ansi';
|
|
71
|
+
import { createPrompt } from '@inquirer/core';
|
|
72
|
+
|
|
73
|
+
export default createPrompt((config, done: (value: void) => void) => {
|
|
74
|
+
return `Choose an option${cursorHide}`;
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## API
|
|
79
|
+
|
|
80
|
+
### Cursor Movement
|
|
81
|
+
|
|
82
|
+
- **`cursorUp(count?: number)`** - Move cursor up by `count` lines (default: 1)
|
|
83
|
+
- **`cursorDown(count?: number)`** - Move cursor down by `count` lines (default: 1)
|
|
84
|
+
- **`cursorTo(x: number, y?: number)`** - Move cursor to position (x, y). If y is omitted, only moves horizontally
|
|
85
|
+
- **`cursorLeft`** - Move cursor to beginning of line
|
|
86
|
+
|
|
87
|
+
### Cursor Visibility
|
|
88
|
+
|
|
89
|
+
- **`cursorHide`** - Hide the cursor
|
|
90
|
+
- **`cursorShow`** - Show the cursor
|
|
91
|
+
|
|
92
|
+
### Screen Manipulation
|
|
93
|
+
|
|
94
|
+
- **`eraseLines(count: number)`** - Clear `count` lines and position cursor at the beginning of the first cleared line
|
|
95
|
+
|
|
96
|
+
# License
|
|
97
|
+
|
|
98
|
+
Copyright (c) 2025 Simon Boudrias (twitter: [@vaxilart](https://twitter.com/Vaxilart))<br/>
|
|
99
|
+
Licensed under the MIT license.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Move cursor to first column */
|
|
2
|
+
export declare const cursorLeft: string;
|
|
3
|
+
/** Hide the cursor */
|
|
4
|
+
export declare const cursorHide: string;
|
|
5
|
+
/** Show the cursor */
|
|
6
|
+
export declare const cursorShow: string;
|
|
7
|
+
/** Move cursor up by count rows */
|
|
8
|
+
export declare const cursorUp: (rows?: number) => string;
|
|
9
|
+
/** Move cursor down by count rows */
|
|
10
|
+
export declare const cursorDown: (rows?: number) => string;
|
|
11
|
+
/** Move cursor to position (x, y) */
|
|
12
|
+
export declare const cursorTo: (x: number, y?: number) => string;
|
|
13
|
+
/** Erase the specified number of lines above the cursor */
|
|
14
|
+
export declare const eraseLines: (lines: number) => string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.eraseLines = exports.cursorTo = exports.cursorDown = exports.cursorUp = exports.cursorShow = exports.cursorHide = exports.cursorLeft = void 0;
|
|
4
|
+
const ESC = '\u001B[';
|
|
5
|
+
/** Move cursor to first column */
|
|
6
|
+
exports.cursorLeft = ESC + 'G';
|
|
7
|
+
/** Hide the cursor */
|
|
8
|
+
exports.cursorHide = ESC + '?25l';
|
|
9
|
+
/** Show the cursor */
|
|
10
|
+
exports.cursorShow = ESC + '?25h';
|
|
11
|
+
/** Move cursor up by count rows */
|
|
12
|
+
const cursorUp = (rows = 1) => (rows > 0 ? `${ESC}${rows}A` : '');
|
|
13
|
+
exports.cursorUp = cursorUp;
|
|
14
|
+
/** Move cursor down by count rows */
|
|
15
|
+
const cursorDown = (rows = 1) => rows > 0 ? `${ESC}${rows}B` : '';
|
|
16
|
+
exports.cursorDown = cursorDown;
|
|
17
|
+
/** Move cursor to position (x, y) */
|
|
18
|
+
const cursorTo = (x, y) => {
|
|
19
|
+
if (typeof y === 'number' && !Number.isNaN(y)) {
|
|
20
|
+
return `${ESC}${y + 1};${x + 1}H`;
|
|
21
|
+
}
|
|
22
|
+
return `${ESC}${x + 1}G`;
|
|
23
|
+
};
|
|
24
|
+
exports.cursorTo = cursorTo;
|
|
25
|
+
const eraseLine = ESC + '2K';
|
|
26
|
+
/** Erase the specified number of lines above the cursor */
|
|
27
|
+
const eraseLines = (lines) => lines > 0 ? (eraseLine + (0, exports.cursorUp)(1)).repeat(lines - 1) + eraseLine + exports.cursorLeft : '';
|
|
28
|
+
exports.eraseLines = eraseLines;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Move cursor to first column */
|
|
2
|
+
export declare const cursorLeft: string;
|
|
3
|
+
/** Hide the cursor */
|
|
4
|
+
export declare const cursorHide: string;
|
|
5
|
+
/** Show the cursor */
|
|
6
|
+
export declare const cursorShow: string;
|
|
7
|
+
/** Move cursor up by count rows */
|
|
8
|
+
export declare const cursorUp: (rows?: number) => string;
|
|
9
|
+
/** Move cursor down by count rows */
|
|
10
|
+
export declare const cursorDown: (rows?: number) => string;
|
|
11
|
+
/** Move cursor to position (x, y) */
|
|
12
|
+
export declare const cursorTo: (x: number, y?: number) => string;
|
|
13
|
+
/** Erase the specified number of lines above the cursor */
|
|
14
|
+
export declare const eraseLines: (lines: number) => string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const ESC = '\u001B[';
|
|
2
|
+
/** Move cursor to first column */
|
|
3
|
+
export const cursorLeft = ESC + 'G';
|
|
4
|
+
/** Hide the cursor */
|
|
5
|
+
export const cursorHide = ESC + '?25l';
|
|
6
|
+
/** Show the cursor */
|
|
7
|
+
export const cursorShow = ESC + '?25h';
|
|
8
|
+
/** Move cursor up by count rows */
|
|
9
|
+
export const cursorUp = (rows = 1) => (rows > 0 ? `${ESC}${rows}A` : '');
|
|
10
|
+
/** Move cursor down by count rows */
|
|
11
|
+
export const cursorDown = (rows = 1) => rows > 0 ? `${ESC}${rows}B` : '';
|
|
12
|
+
/** Move cursor to position (x, y) */
|
|
13
|
+
export const cursorTo = (x, y) => {
|
|
14
|
+
if (typeof y === 'number' && !Number.isNaN(y)) {
|
|
15
|
+
return `${ESC}${y + 1};${x + 1}H`;
|
|
16
|
+
}
|
|
17
|
+
return `${ESC}${x + 1}G`;
|
|
18
|
+
};
|
|
19
|
+
const eraseLine = ESC + '2K';
|
|
20
|
+
/** Erase the specified number of lines above the cursor */
|
|
21
|
+
export const eraseLines = (lines) => lines > 0 ? (eraseLine + cursorUp(1)).repeat(lines - 1) + eraseLine + cursorLeft : '';
|
package/package.json
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@inquirer/ansi",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"engines": {
|
|
5
|
+
"node": ">=18"
|
|
6
|
+
},
|
|
7
|
+
"author": "Simon Boudrias <admin@simonboudrias.com>",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/SBoudrias/Inquirer.js.git"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"answer",
|
|
15
|
+
"answers",
|
|
16
|
+
"ask",
|
|
17
|
+
"base",
|
|
18
|
+
"cli",
|
|
19
|
+
"command",
|
|
20
|
+
"command-line",
|
|
21
|
+
"confirm",
|
|
22
|
+
"enquirer",
|
|
23
|
+
"generate",
|
|
24
|
+
"generator",
|
|
25
|
+
"hyper",
|
|
26
|
+
"input",
|
|
27
|
+
"inquire",
|
|
28
|
+
"inquirer",
|
|
29
|
+
"interface",
|
|
30
|
+
"iterm",
|
|
31
|
+
"javascript",
|
|
32
|
+
"menu",
|
|
33
|
+
"node",
|
|
34
|
+
"nodejs",
|
|
35
|
+
"prompt",
|
|
36
|
+
"promptly",
|
|
37
|
+
"prompts",
|
|
38
|
+
"question",
|
|
39
|
+
"readline",
|
|
40
|
+
"scaffold",
|
|
41
|
+
"scaffolder",
|
|
42
|
+
"scaffolding",
|
|
43
|
+
"stdin",
|
|
44
|
+
"stdout",
|
|
45
|
+
"terminal",
|
|
46
|
+
"tty",
|
|
47
|
+
"ui",
|
|
48
|
+
"yeoman",
|
|
49
|
+
"yo",
|
|
50
|
+
"zsh",
|
|
51
|
+
"ansi"
|
|
52
|
+
],
|
|
53
|
+
"sideEffects": false,
|
|
54
|
+
"files": [
|
|
55
|
+
"dist"
|
|
56
|
+
],
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@arethetypeswrong/cli": "^0.18.2",
|
|
59
|
+
"@repo/tsconfig": "workspace:*",
|
|
60
|
+
"tshy": "^3.0.2"
|
|
61
|
+
},
|
|
62
|
+
"tshy": {
|
|
63
|
+
"exclude": [
|
|
64
|
+
"src/**/*.test.ts"
|
|
65
|
+
],
|
|
66
|
+
"exports": {
|
|
67
|
+
"./package.json": "./package.json",
|
|
68
|
+
".": "./src/index.ts"
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
"scripts": {
|
|
72
|
+
"tsc": "tshy",
|
|
73
|
+
"attw": "attw --pack"
|
|
74
|
+
},
|
|
75
|
+
"type": "module",
|
|
76
|
+
"publishConfig": {
|
|
77
|
+
"access": "public"
|
|
78
|
+
},
|
|
79
|
+
"exports": {
|
|
80
|
+
"./package.json": "./package.json",
|
|
81
|
+
".": {
|
|
82
|
+
"import": {
|
|
83
|
+
"types": "./dist/esm/index.d.ts",
|
|
84
|
+
"default": "./dist/esm/index.js"
|
|
85
|
+
},
|
|
86
|
+
"require": {
|
|
87
|
+
"types": "./dist/commonjs/index.d.ts",
|
|
88
|
+
"default": "./dist/commonjs/index.js"
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
"main": "./dist/commonjs/index.js",
|
|
93
|
+
"types": "./dist/commonjs/index.d.ts",
|
|
94
|
+
"module": "./dist/esm/index.js",
|
|
95
|
+
"homepage": "https://github.com/SBoudrias/Inquirer.js/blob/main/packages/ansi/README.md"
|
|
96
|
+
}
|