@inquirer/core 10.2.1 → 10.3.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/dist/commonjs/index.d.ts +1 -1
- package/dist/commonjs/index.js +9 -2
- package/dist/commonjs/lib/key.d.ts +3 -2
- package/dist/commonjs/lib/key.js +14 -2
- package/dist/commonjs/lib/screen-manager.js +8 -16
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/lib/key.d.ts +3 -2
- package/dist/esm/lib/key.js +14 -2
- package/dist/esm/lib/screen-manager.js +7 -12
- package/package.json +6 -6
package/dist/commonjs/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { isUpKey, isDownKey, isSpaceKey, isBackspaceKey, isTabKey, isNumberKey, isEnterKey, type KeypressEvent, type Keybinding, } from './lib/key.ts';
|
|
2
2
|
export * from './lib/errors.ts';
|
|
3
3
|
export { usePrefix } from './lib/use-prefix.ts';
|
|
4
4
|
export { useState } from './lib/use-state.ts';
|
package/dist/commonjs/index.js
CHANGED
|
@@ -14,8 +14,15 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.Separator = exports.createPrompt = exports.usePagination = exports.makeTheme = exports.useKeypress = exports.useRef = exports.useMemo = exports.useEffect = exports.useState = exports.usePrefix = void 0;
|
|
18
|
-
|
|
17
|
+
exports.Separator = exports.createPrompt = exports.usePagination = exports.makeTheme = exports.useKeypress = exports.useRef = exports.useMemo = exports.useEffect = exports.useState = exports.usePrefix = exports.isEnterKey = exports.isNumberKey = exports.isTabKey = exports.isBackspaceKey = exports.isSpaceKey = exports.isDownKey = exports.isUpKey = void 0;
|
|
18
|
+
var key_ts_1 = require("./lib/key.js");
|
|
19
|
+
Object.defineProperty(exports, "isUpKey", { enumerable: true, get: function () { return key_ts_1.isUpKey; } });
|
|
20
|
+
Object.defineProperty(exports, "isDownKey", { enumerable: true, get: function () { return key_ts_1.isDownKey; } });
|
|
21
|
+
Object.defineProperty(exports, "isSpaceKey", { enumerable: true, get: function () { return key_ts_1.isSpaceKey; } });
|
|
22
|
+
Object.defineProperty(exports, "isBackspaceKey", { enumerable: true, get: function () { return key_ts_1.isBackspaceKey; } });
|
|
23
|
+
Object.defineProperty(exports, "isTabKey", { enumerable: true, get: function () { return key_ts_1.isTabKey; } });
|
|
24
|
+
Object.defineProperty(exports, "isNumberKey", { enumerable: true, get: function () { return key_ts_1.isNumberKey; } });
|
|
25
|
+
Object.defineProperty(exports, "isEnterKey", { enumerable: true, get: function () { return key_ts_1.isEnterKey; } });
|
|
19
26
|
__exportStar(require("./lib/errors.js"), exports);
|
|
20
27
|
var use_prefix_ts_1 = require("./lib/use-prefix.js");
|
|
21
28
|
Object.defineProperty(exports, "usePrefix", { enumerable: true, get: function () { return use_prefix_ts_1.usePrefix; } });
|
|
@@ -2,8 +2,9 @@ export type KeypressEvent = {
|
|
|
2
2
|
name: string;
|
|
3
3
|
ctrl: boolean;
|
|
4
4
|
};
|
|
5
|
-
export
|
|
6
|
-
export declare const
|
|
5
|
+
export type Keybinding = 'emacs' | 'vim';
|
|
6
|
+
export declare const isUpKey: (key: KeypressEvent, keybindings?: ReadonlyArray<Keybinding>) => boolean;
|
|
7
|
+
export declare const isDownKey: (key: KeypressEvent, keybindings?: ReadonlyArray<Keybinding>) => boolean;
|
|
7
8
|
export declare const isSpaceKey: (key: KeypressEvent) => boolean;
|
|
8
9
|
export declare const isBackspaceKey: (key: KeypressEvent) => boolean;
|
|
9
10
|
export declare const isTabKey: (key: KeypressEvent) => boolean;
|
package/dist/commonjs/lib/key.js
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isEnterKey = exports.isNumberKey = exports.isTabKey = exports.isBackspaceKey = exports.isSpaceKey = exports.isDownKey = exports.isUpKey = void 0;
|
|
4
|
-
const isUpKey = (key) =>
|
|
4
|
+
const isUpKey = (key, keybindings = []) =>
|
|
5
|
+
// The up key
|
|
6
|
+
key.name === 'up' ||
|
|
7
|
+
// Vim keybinding: hjkl keys map to left/down/up/right
|
|
8
|
+
(keybindings.includes('vim') && key.name === 'k') ||
|
|
9
|
+
// Emacs keybinding: Ctrl+P means "previous" in Emacs navigation conventions
|
|
10
|
+
(keybindings.includes('emacs') && key.ctrl && key.name === 'p');
|
|
5
11
|
exports.isUpKey = isUpKey;
|
|
6
|
-
const isDownKey = (key) =>
|
|
12
|
+
const isDownKey = (key, keybindings = []) =>
|
|
13
|
+
// The down key
|
|
14
|
+
key.name === 'down' ||
|
|
15
|
+
// Vim keybinding: hjkl keys map to left/down/up/right
|
|
16
|
+
(keybindings.includes('vim') && key.name === 'j') ||
|
|
17
|
+
// Emacs keybinding: Ctrl+N means "next" in Emacs navigation conventions
|
|
18
|
+
(keybindings.includes('emacs') && key.ctrl && key.name === 'n');
|
|
7
19
|
exports.isDownKey = isDownKey;
|
|
8
20
|
const isSpaceKey = (key) => key.name === 'space';
|
|
9
21
|
exports.isSpaceKey = isSpaceKey;
|
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
const node_util_1 = require("node:util");
|
|
7
|
-
const ansi_escapes_1 = __importDefault(require("ansi-escapes"));
|
|
8
4
|
const utils_ts_1 = require("./utils.js");
|
|
5
|
+
const ansi_1 = require("@inquirer/ansi");
|
|
9
6
|
const height = (content) => content.split('\n').length;
|
|
10
7
|
const lastLine = (content) => content.split('\n').pop() ?? '';
|
|
11
|
-
function cursorDown(n) {
|
|
12
|
-
return n > 0 ? ansi_escapes_1.default.cursorDown(n) : '';
|
|
13
|
-
}
|
|
14
8
|
class ScreenManager {
|
|
15
9
|
// These variables are keeping information to allow correct prompt re-rendering
|
|
16
10
|
height = 0;
|
|
@@ -59,30 +53,28 @@ class ScreenManager {
|
|
|
59
53
|
const bottomContentHeight = promptLineUpDiff + (bottomContent ? height(bottomContent) : 0);
|
|
60
54
|
// Return cursor to the input position (on top of the bottomContent)
|
|
61
55
|
if (bottomContentHeight > 0)
|
|
62
|
-
output +=
|
|
56
|
+
output += (0, ansi_1.cursorUp)(bottomContentHeight);
|
|
63
57
|
// Return cursor to the initial left offset.
|
|
64
|
-
output +=
|
|
58
|
+
output += (0, ansi_1.cursorTo)(this.cursorPos.cols);
|
|
65
59
|
/**
|
|
66
60
|
* Render and store state for future re-rendering
|
|
67
61
|
*/
|
|
68
|
-
this.write(cursorDown(this.extraLinesUnderPrompt) +
|
|
69
|
-
ansi_escapes_1.default.eraseLines(this.height) +
|
|
70
|
-
output);
|
|
62
|
+
this.write((0, ansi_1.cursorDown)(this.extraLinesUnderPrompt) + (0, ansi_1.eraseLines)(this.height) + output);
|
|
71
63
|
this.extraLinesUnderPrompt = bottomContentHeight;
|
|
72
64
|
this.height = height(output);
|
|
73
65
|
}
|
|
74
66
|
checkCursorPos() {
|
|
75
67
|
const cursorPos = this.rl.getCursorPos();
|
|
76
68
|
if (cursorPos.cols !== this.cursorPos.cols) {
|
|
77
|
-
this.write(
|
|
69
|
+
this.write((0, ansi_1.cursorTo)(cursorPos.cols));
|
|
78
70
|
this.cursorPos = cursorPos;
|
|
79
71
|
}
|
|
80
72
|
}
|
|
81
73
|
done({ clearContent }) {
|
|
82
74
|
this.rl.setPrompt('');
|
|
83
|
-
let output = cursorDown(this.extraLinesUnderPrompt);
|
|
84
|
-
output += clearContent ?
|
|
85
|
-
output +=
|
|
75
|
+
let output = (0, ansi_1.cursorDown)(this.extraLinesUnderPrompt);
|
|
76
|
+
output += clearContent ? (0, ansi_1.eraseLines)(this.height) : '\n';
|
|
77
|
+
output += ansi_1.cursorShow;
|
|
86
78
|
this.write(output);
|
|
87
79
|
this.rl.close();
|
|
88
80
|
}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { isUpKey, isDownKey, isSpaceKey, isBackspaceKey, isTabKey, isNumberKey, isEnterKey, type KeypressEvent, type Keybinding, } from './lib/key.ts';
|
|
2
2
|
export * from './lib/errors.ts';
|
|
3
3
|
export { usePrefix } from './lib/use-prefix.ts';
|
|
4
4
|
export { useState } from './lib/use-state.ts';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { isUpKey, isDownKey, isSpaceKey, isBackspaceKey, isTabKey, isNumberKey, isEnterKey, } from "./lib/key.js";
|
|
2
2
|
export * from "./lib/errors.js";
|
|
3
3
|
export { usePrefix } from "./lib/use-prefix.js";
|
|
4
4
|
export { useState } from "./lib/use-state.js";
|
package/dist/esm/lib/key.d.ts
CHANGED
|
@@ -2,8 +2,9 @@ export type KeypressEvent = {
|
|
|
2
2
|
name: string;
|
|
3
3
|
ctrl: boolean;
|
|
4
4
|
};
|
|
5
|
-
export
|
|
6
|
-
export declare const
|
|
5
|
+
export type Keybinding = 'emacs' | 'vim';
|
|
6
|
+
export declare const isUpKey: (key: KeypressEvent, keybindings?: ReadonlyArray<Keybinding>) => boolean;
|
|
7
|
+
export declare const isDownKey: (key: KeypressEvent, keybindings?: ReadonlyArray<Keybinding>) => boolean;
|
|
7
8
|
export declare const isSpaceKey: (key: KeypressEvent) => boolean;
|
|
8
9
|
export declare const isBackspaceKey: (key: KeypressEvent) => boolean;
|
|
9
10
|
export declare const isTabKey: (key: KeypressEvent) => boolean;
|
package/dist/esm/lib/key.js
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
|
-
export const isUpKey = (key) =>
|
|
2
|
-
|
|
1
|
+
export const isUpKey = (key, keybindings = []) =>
|
|
2
|
+
// The up key
|
|
3
|
+
key.name === 'up' ||
|
|
4
|
+
// Vim keybinding: hjkl keys map to left/down/up/right
|
|
5
|
+
(keybindings.includes('vim') && key.name === 'k') ||
|
|
6
|
+
// Emacs keybinding: Ctrl+P means "previous" in Emacs navigation conventions
|
|
7
|
+
(keybindings.includes('emacs') && key.ctrl && key.name === 'p');
|
|
8
|
+
export const isDownKey = (key, keybindings = []) =>
|
|
9
|
+
// The down key
|
|
10
|
+
key.name === 'down' ||
|
|
11
|
+
// Vim keybinding: hjkl keys map to left/down/up/right
|
|
12
|
+
(keybindings.includes('vim') && key.name === 'j') ||
|
|
13
|
+
// Emacs keybinding: Ctrl+N means "next" in Emacs navigation conventions
|
|
14
|
+
(keybindings.includes('emacs') && key.ctrl && key.name === 'n');
|
|
3
15
|
export const isSpaceKey = (key) => key.name === 'space';
|
|
4
16
|
export const isBackspaceKey = (key) => key.name === 'backspace';
|
|
5
17
|
export const isTabKey = (key) => key.name === 'tab';
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { stripVTControlCharacters } from 'node:util';
|
|
2
|
-
import ansiEscapes from 'ansi-escapes';
|
|
3
2
|
import { breakLines, readlineWidth } from "./utils.js";
|
|
3
|
+
import { cursorDown, cursorUp, cursorTo, cursorShow, eraseLines } from '@inquirer/ansi';
|
|
4
4
|
const height = (content) => content.split('\n').length;
|
|
5
5
|
const lastLine = (content) => content.split('\n').pop() ?? '';
|
|
6
|
-
function cursorDown(n) {
|
|
7
|
-
return n > 0 ? ansiEscapes.cursorDown(n) : '';
|
|
8
|
-
}
|
|
9
6
|
export default class ScreenManager {
|
|
10
7
|
// These variables are keeping information to allow correct prompt re-rendering
|
|
11
8
|
height = 0;
|
|
@@ -54,30 +51,28 @@ export default class ScreenManager {
|
|
|
54
51
|
const bottomContentHeight = promptLineUpDiff + (bottomContent ? height(bottomContent) : 0);
|
|
55
52
|
// Return cursor to the input position (on top of the bottomContent)
|
|
56
53
|
if (bottomContentHeight > 0)
|
|
57
|
-
output +=
|
|
54
|
+
output += cursorUp(bottomContentHeight);
|
|
58
55
|
// Return cursor to the initial left offset.
|
|
59
|
-
output +=
|
|
56
|
+
output += cursorTo(this.cursorPos.cols);
|
|
60
57
|
/**
|
|
61
58
|
* Render and store state for future re-rendering
|
|
62
59
|
*/
|
|
63
|
-
this.write(cursorDown(this.extraLinesUnderPrompt) +
|
|
64
|
-
ansiEscapes.eraseLines(this.height) +
|
|
65
|
-
output);
|
|
60
|
+
this.write(cursorDown(this.extraLinesUnderPrompt) + eraseLines(this.height) + output);
|
|
66
61
|
this.extraLinesUnderPrompt = bottomContentHeight;
|
|
67
62
|
this.height = height(output);
|
|
68
63
|
}
|
|
69
64
|
checkCursorPos() {
|
|
70
65
|
const cursorPos = this.rl.getCursorPos();
|
|
71
66
|
if (cursorPos.cols !== this.cursorPos.cols) {
|
|
72
|
-
this.write(
|
|
67
|
+
this.write(cursorTo(cursorPos.cols));
|
|
73
68
|
this.cursorPos = cursorPos;
|
|
74
69
|
}
|
|
75
70
|
}
|
|
76
71
|
done({ clearContent }) {
|
|
77
72
|
this.rl.setPrompt('');
|
|
78
73
|
let output = cursorDown(this.extraLinesUnderPrompt);
|
|
79
|
-
output += clearContent ?
|
|
80
|
-
output +=
|
|
74
|
+
output += clearContent ? eraseLines(this.height) : '\n';
|
|
75
|
+
output += cursorShow;
|
|
81
76
|
this.write(output);
|
|
82
77
|
this.rl.close();
|
|
83
78
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inquirer/core",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.3.0",
|
|
4
4
|
"description": "Core Inquirer prompt API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"answer",
|
|
@@ -74,9 +74,9 @@
|
|
|
74
74
|
"tsc": "tshy"
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"@inquirer/
|
|
78
|
-
"@inquirer/
|
|
79
|
-
"
|
|
77
|
+
"@inquirer/ansi": "^1.0.1",
|
|
78
|
+
"@inquirer/figures": "^1.0.14",
|
|
79
|
+
"@inquirer/type": "^3.0.9",
|
|
80
80
|
"cli-width": "^4.1.0",
|
|
81
81
|
"mute-stream": "^2.0.0",
|
|
82
82
|
"signal-exit": "^4.1.0",
|
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
87
|
"@arethetypeswrong/cli": "^0.18.2",
|
|
88
|
-
"@inquirer/testing": "^2.1.
|
|
88
|
+
"@inquirer/testing": "^2.1.51",
|
|
89
89
|
"@types/mute-stream": "^0.0.4",
|
|
90
90
|
"@types/node": "^24.0.15",
|
|
91
91
|
"@types/wrap-ansi": "^3.0.0",
|
|
@@ -114,5 +114,5 @@
|
|
|
114
114
|
".": "./src/index.ts"
|
|
115
115
|
}
|
|
116
116
|
},
|
|
117
|
-
"gitHead": "
|
|
117
|
+
"gitHead": "87cb01e67a25983bdaf0d74a7685915c0afb5f23"
|
|
118
118
|
}
|