@inquirer/core 0.0.15-alpha.0 → 0.0.18-alpha.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/hooks.js +44 -48
- package/index.js +7 -9
- package/lib/Paginator.js +1 -4
- package/lib/screen-manager.js +1 -4
- package/lib/utils.js +5 -8
- package/package.json +3 -3
package/hooks.js
CHANGED
|
@@ -70,54 +70,50 @@ exports.useEffect = (cb, depArray) => {
|
|
|
70
70
|
index++;
|
|
71
71
|
};
|
|
72
72
|
|
|
73
|
-
exports.useRef = (val) => {
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
exports.useRef = (val) => exports.useState({ current: val })[0];
|
|
74
|
+
|
|
75
|
+
exports.createPrompt = (view) => (options) => {
|
|
76
|
+
// Default `input` to stdin
|
|
77
|
+
const input = process.stdin;
|
|
78
|
+
|
|
79
|
+
// Add mute capabilities to the output
|
|
80
|
+
const output = new MuteStream();
|
|
81
|
+
output.pipe(process.stdout);
|
|
82
|
+
|
|
83
|
+
const rl = readline.createInterface({
|
|
84
|
+
terminal: true,
|
|
85
|
+
input,
|
|
86
|
+
output,
|
|
87
|
+
});
|
|
88
|
+
const screen = new ScreenManager(rl);
|
|
89
|
+
|
|
90
|
+
return new Promise((resolve, reject) => {
|
|
91
|
+
sessionRl = rl;
|
|
92
|
+
|
|
93
|
+
const done = (value) => {
|
|
94
|
+
let len = cleanupHook.length;
|
|
95
|
+
while (len--) {
|
|
96
|
+
cleanupHook(len);
|
|
97
|
+
}
|
|
98
|
+
screen.done();
|
|
99
|
+
|
|
100
|
+
// Reset hooks state
|
|
101
|
+
hooks = [];
|
|
102
|
+
index = 0;
|
|
103
|
+
sessionRl = undefined;
|
|
76
104
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const input = process.stdin;
|
|
81
|
-
|
|
82
|
-
// Add mute capabilities to the output
|
|
83
|
-
const output = new MuteStream();
|
|
84
|
-
output.pipe(process.stdout);
|
|
85
|
-
|
|
86
|
-
const rl = readline.createInterface({
|
|
87
|
-
terminal: true,
|
|
88
|
-
input,
|
|
89
|
-
output,
|
|
90
|
-
});
|
|
91
|
-
const screen = new ScreenManager(rl);
|
|
92
|
-
|
|
93
|
-
return new Promise((resolve, reject) => {
|
|
94
|
-
sessionRl = rl;
|
|
95
|
-
|
|
96
|
-
const done = (value) => {
|
|
97
|
-
let len = cleanupHook.length;
|
|
98
|
-
while (len--) {
|
|
99
|
-
cleanupHook(len);
|
|
100
|
-
}
|
|
101
|
-
screen.done();
|
|
102
|
-
|
|
103
|
-
// Reset hooks state
|
|
104
|
-
hooks = [];
|
|
105
|
-
index = 0;
|
|
106
|
-
sessionRl = undefined;
|
|
107
|
-
|
|
108
|
-
// Finally we resolve our promise
|
|
109
|
-
resolve(value);
|
|
110
|
-
};
|
|
105
|
+
// Finally we resolve our promise
|
|
106
|
+
resolve(value);
|
|
107
|
+
};
|
|
111
108
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
};
|
|
109
|
+
hooks = [];
|
|
110
|
+
const workLoop = (config) => {
|
|
111
|
+
index = 0;
|
|
112
|
+
handleChange = () => workLoop(config);
|
|
113
|
+
screen.render(...[view(config, done)].flat().filter(Boolean));
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// TODO: we should display a loader while we get the default options.
|
|
117
|
+
getPromptConfig(options).then(workLoop, reject);
|
|
118
|
+
});
|
|
123
119
|
};
|
package/index.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
const _ = {
|
|
2
|
-
isFunction: require('lodash/isFunction'),
|
|
3
|
-
noop: require('lodash/noop'),
|
|
4
|
-
};
|
|
5
1
|
const readline = require('readline');
|
|
6
2
|
const chalk = require('chalk');
|
|
7
3
|
const MuteStream = require('mute-stream');
|
|
@@ -50,7 +46,7 @@ class StateManager {
|
|
|
50
46
|
this.screen = new ScreenManager(this.rl);
|
|
51
47
|
|
|
52
48
|
let config = configFactory;
|
|
53
|
-
if (
|
|
49
|
+
if (typeof configFactory === 'function') {
|
|
54
50
|
config = configFactory(this.rl);
|
|
55
51
|
}
|
|
56
52
|
|
|
@@ -70,7 +66,7 @@ class StateManager {
|
|
|
70
66
|
|
|
71
67
|
// Load asynchronous properties
|
|
72
68
|
const showLoader = setTimeout(this.startLoading, 500);
|
|
73
|
-
if (
|
|
69
|
+
if (typeof message === 'function') {
|
|
74
70
|
message = await runAsync(message)();
|
|
75
71
|
}
|
|
76
72
|
|
|
@@ -85,14 +81,16 @@ class StateManager {
|
|
|
85
81
|
}
|
|
86
82
|
|
|
87
83
|
onKeypress(value, key) {
|
|
88
|
-
const { onKeypress
|
|
84
|
+
const { onKeypress } = this.config;
|
|
89
85
|
// Ignore enter keypress. The "line" event is handling those.
|
|
90
86
|
if (key.name === 'enter' || key.name === 'return') {
|
|
91
87
|
return;
|
|
92
88
|
}
|
|
93
89
|
|
|
94
90
|
this.setState({ value: this.rl.line, error: null });
|
|
95
|
-
|
|
91
|
+
if (onKeypress) {
|
|
92
|
+
onKeypress(this.rl.line, key, this.getState(), this.setState);
|
|
93
|
+
}
|
|
96
94
|
}
|
|
97
95
|
|
|
98
96
|
startLoading() {
|
|
@@ -195,7 +193,7 @@ class StateManager {
|
|
|
195
193
|
prefix: this.getPrefix(),
|
|
196
194
|
...state,
|
|
197
195
|
// Only pass message down if it's a string. Otherwise we're still in init state
|
|
198
|
-
message:
|
|
196
|
+
message: typeof message === 'function' ? 'Loading...' : message,
|
|
199
197
|
value: transformer(value, { isFinal: status === 'done' }),
|
|
200
198
|
validate: undefined,
|
|
201
199
|
filter: undefined,
|
package/lib/Paginator.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const _ = {
|
|
4
|
-
flatten: require('lodash/flatten'),
|
|
5
|
-
};
|
|
6
3
|
const chalk = require('chalk');
|
|
7
4
|
const cliWidth = require('cli-width');
|
|
8
5
|
const { breakLines } = require('./utils');
|
|
@@ -45,7 +42,7 @@ class Paginator {
|
|
|
45
42
|
this.lastIndex = active;
|
|
46
43
|
|
|
47
44
|
// Duplicate the lines so it give an infinite list look
|
|
48
|
-
const infinite =
|
|
45
|
+
const infinite = [lines, lines, lines].flat();
|
|
49
46
|
const topIndex = Math.max(0, active + lines.length - this.pointer);
|
|
50
47
|
|
|
51
48
|
const section = infinite.splice(topIndex, pageSize).join('\n');
|
package/lib/screen-manager.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
const _ = {
|
|
2
|
-
last: require('lodash/last'),
|
|
3
|
-
};
|
|
4
1
|
const cliWidth = require('cli-width');
|
|
5
2
|
const stripAnsi = require('strip-ansi');
|
|
6
3
|
const stringWidth = require('string-width');
|
|
@@ -9,7 +6,7 @@ const util = require('./readline');
|
|
|
9
6
|
const { breakLines } = require('./utils');
|
|
10
7
|
|
|
11
8
|
const height = (content) => content.split('\n').length;
|
|
12
|
-
const lastLine = (content) =>
|
|
9
|
+
const lastLine = (content) => content.split('\n').pop();
|
|
13
10
|
|
|
14
11
|
module.exports = class ScreenManager {
|
|
15
12
|
constructor(rl) {
|
package/lib/utils.js
CHANGED
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
const _ = {
|
|
2
|
-
flatten: require('lodash/flatten'),
|
|
3
|
-
};
|
|
4
|
-
|
|
5
1
|
/**
|
|
6
2
|
* Force line returns at specific width. This function is ANSI code friendly and it'll
|
|
7
3
|
* ignore invisible codes during width calculation.
|
|
8
|
-
* @param {string}
|
|
4
|
+
* @param {string} content
|
|
9
5
|
* @param {number} width
|
|
10
6
|
* @return {string}
|
|
11
7
|
*/
|
|
12
8
|
exports.breakLines = (content, width) => {
|
|
13
9
|
const regex = new RegExp('(?:(?:\\033[[0-9;]*m)*.?){1,' + width + '}', 'g');
|
|
14
|
-
return
|
|
15
|
-
|
|
10
|
+
return content
|
|
11
|
+
.split('\n')
|
|
12
|
+
.flatMap((line) => {
|
|
16
13
|
const chunk = line.match(regex);
|
|
17
14
|
// Remove the last match as it's always empty
|
|
18
15
|
chunk.pop();
|
|
19
16
|
return chunk || '';
|
|
20
17
|
})
|
|
21
|
-
|
|
18
|
+
.join('\n');
|
|
22
19
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inquirer/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18-alpha.0",
|
|
4
4
|
"description": "Core Inquirer prompt API",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": "SBoudrias/Inquirer.js",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"ansi-escapes": "^4.2.1",
|
|
17
17
|
"chalk": "^4.1.1",
|
|
18
|
-
"cli-spinners": "^2.6.
|
|
18
|
+
"cli-spinners": "^2.6.1",
|
|
19
19
|
"cli-width": "^3.0.0",
|
|
20
20
|
"lodash": "^4.17.21",
|
|
21
21
|
"mute-stream": "^0.0.8",
|
|
@@ -26,5 +26,5 @@
|
|
|
26
26
|
"publishConfig": {
|
|
27
27
|
"access": "public"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "e71313db1a6e26f501b58d75a9d3acf53dab5da7"
|
|
30
30
|
}
|