@inquirer/core 0.0.17-alpha.0 → 0.0.20-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/LICENSE +2 -2
- package/index.js +7 -9
- package/lib/Paginator.js +1 -4
- package/lib/screen-manager.js +1 -4
- package/lib/utils.js +7 -15
- package/package.json +5 -4
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright (c)
|
|
1
|
+
Copyright (c) 2022 Simon Boudrias
|
|
2
2
|
|
|
3
3
|
Permission is hereby granted, free of charge, to any person
|
|
4
4
|
obtaining a copy of this software and associated documentation
|
|
@@ -19,4 +19,4 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
|
19
19
|
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
20
20
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
21
21
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
-
OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
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,14 @@
|
|
|
1
|
-
const
|
|
2
|
-
flatten: require('lodash/flatten'),
|
|
3
|
-
};
|
|
1
|
+
const wrapAnsi = require('wrap-ansi');
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
4
|
* Force line returns at specific width. This function is ANSI code friendly and it'll
|
|
7
5
|
* ignore invisible codes during width calculation.
|
|
8
|
-
* @param {string}
|
|
6
|
+
* @param {string} content
|
|
9
7
|
* @param {number} width
|
|
10
8
|
* @return {string}
|
|
11
9
|
*/
|
|
12
|
-
exports.breakLines = (content, width) =>
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
// Remove the last match as it's always empty
|
|
18
|
-
chunk.pop();
|
|
19
|
-
return chunk || '';
|
|
20
|
-
})
|
|
21
|
-
).join('\n');
|
|
22
|
-
};
|
|
10
|
+
exports.breakLines = (content, width) =>
|
|
11
|
+
content
|
|
12
|
+
.split('\n')
|
|
13
|
+
.map((line) => wrapAnsi(line, width, { trim: false, hard: true }).split('\n'))
|
|
14
|
+
.join('\n');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inquirer/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20-alpha.0",
|
|
4
4
|
"description": "Core Inquirer prompt API",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": "SBoudrias/Inquirer.js",
|
|
@@ -15,16 +15,17 @@
|
|
|
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",
|
|
22
22
|
"run-async": "^2.3.0",
|
|
23
23
|
"string-width": "^4.1.0",
|
|
24
|
-
"strip-ansi": "^6.0.0"
|
|
24
|
+
"strip-ansi": "^6.0.0",
|
|
25
|
+
"wrap-ansi": "^7.0.0"
|
|
25
26
|
},
|
|
26
27
|
"publishConfig": {
|
|
27
28
|
"access": "public"
|
|
28
29
|
},
|
|
29
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "83b807522ca6e10ab90a6921eac9d9655e2dac38"
|
|
30
31
|
}
|