@inquirer/core 8.2.2 → 8.2.3
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.
|
@@ -89,9 +89,8 @@ function createPrompt(view) {
|
|
|
89
89
|
resolve(value);
|
|
90
90
|
});
|
|
91
91
|
}
|
|
92
|
-
function workLoop(
|
|
92
|
+
function workLoop() {
|
|
93
93
|
store.index = 0;
|
|
94
|
-
store.handleChange = () => workLoop(resolvedConfig);
|
|
95
94
|
try {
|
|
96
95
|
const nextView = view(config, done);
|
|
97
96
|
const [content, bottomContent] = typeof nextView === 'string' ? [nextView] : nextView;
|
|
@@ -103,7 +102,8 @@ function createPrompt(view) {
|
|
|
103
102
|
reject(error);
|
|
104
103
|
}
|
|
105
104
|
}
|
|
106
|
-
workLoop(
|
|
105
|
+
store.handleChange = () => workLoop();
|
|
106
|
+
workLoop();
|
|
107
107
|
// Re-renders only happen when the state change; but the readline cursor could change position
|
|
108
108
|
// and that also requires a re-render (and a manual one because we mute the streams).
|
|
109
109
|
// We set the listener after the initial workLoop to avoid a double render if render triggered
|
|
@@ -6,19 +6,32 @@ const use_state_mjs_1 = require('./use-state.js');
|
|
|
6
6
|
const use_effect_mjs_1 = require('./use-effect.js');
|
|
7
7
|
const make_theme_mjs_1 = require('./make-theme.js');
|
|
8
8
|
function usePrefix({ isLoading = false, theme, }) {
|
|
9
|
+
const [showLoader, setShowLoader] = (0, use_state_mjs_1.useState)(false);
|
|
9
10
|
const [tick, setTick] = (0, use_state_mjs_1.useState)(0);
|
|
10
11
|
const { prefix, spinner } = (0, make_theme_mjs_1.makeTheme)(theme);
|
|
11
12
|
(0, use_effect_mjs_1.useEffect)(() => {
|
|
12
13
|
if (isLoading) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
let tickInterval;
|
|
15
|
+
let inc = -1;
|
|
16
|
+
// Delay displaying spinner by 300ms, to avoid flickering
|
|
17
|
+
const delayTimeout = setTimeout(node_async_hooks_1.AsyncResource.bind(() => {
|
|
18
|
+
setShowLoader(true);
|
|
19
|
+
tickInterval = setInterval(node_async_hooks_1.AsyncResource.bind(() => {
|
|
20
|
+
inc = inc + 1;
|
|
21
|
+
setTick(inc % spinner.frames.length);
|
|
22
|
+
}), spinner.interval);
|
|
23
|
+
}), 300);
|
|
24
|
+
return () => {
|
|
25
|
+
clearTimeout(delayTimeout);
|
|
26
|
+
clearInterval(tickInterval);
|
|
27
|
+
};
|
|
17
28
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
29
|
+
else {
|
|
30
|
+
setShowLoader(false);
|
|
31
|
+
}
|
|
32
|
+
}, [isLoading]);
|
|
33
|
+
if (showLoader) {
|
|
34
|
+
return spinner.frames[tick];
|
|
22
35
|
}
|
|
23
36
|
return prefix;
|
|
24
37
|
}
|
|
@@ -59,9 +59,8 @@ export function createPrompt(view) {
|
|
|
59
59
|
resolve(value);
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
|
-
function workLoop(
|
|
62
|
+
function workLoop() {
|
|
63
63
|
store.index = 0;
|
|
64
|
-
store.handleChange = () => workLoop(resolvedConfig);
|
|
65
64
|
try {
|
|
66
65
|
const nextView = view(config, done);
|
|
67
66
|
const [content, bottomContent] = typeof nextView === 'string' ? [nextView] : nextView;
|
|
@@ -73,7 +72,8 @@ export function createPrompt(view) {
|
|
|
73
72
|
reject(error);
|
|
74
73
|
}
|
|
75
74
|
}
|
|
76
|
-
workLoop(
|
|
75
|
+
store.handleChange = () => workLoop();
|
|
76
|
+
workLoop();
|
|
77
77
|
// Re-renders only happen when the state change; but the readline cursor could change position
|
|
78
78
|
// and that also requires a re-render (and a manual one because we mute the streams).
|
|
79
79
|
// We set the listener after the initial workLoop to avoid a double render if render triggered
|
|
@@ -3,19 +3,32 @@ import { useState } from './use-state.mjs';
|
|
|
3
3
|
import { useEffect } from './use-effect.mjs';
|
|
4
4
|
import { makeTheme } from './make-theme.mjs';
|
|
5
5
|
export function usePrefix({ isLoading = false, theme, }) {
|
|
6
|
+
const [showLoader, setShowLoader] = useState(false);
|
|
6
7
|
const [tick, setTick] = useState(0);
|
|
7
8
|
const { prefix, spinner } = makeTheme(theme);
|
|
8
9
|
useEffect(() => {
|
|
9
10
|
if (isLoading) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
let tickInterval;
|
|
12
|
+
let inc = -1;
|
|
13
|
+
// Delay displaying spinner by 300ms, to avoid flickering
|
|
14
|
+
const delayTimeout = setTimeout(AsyncResource.bind(() => {
|
|
15
|
+
setShowLoader(true);
|
|
16
|
+
tickInterval = setInterval(AsyncResource.bind(() => {
|
|
17
|
+
inc = inc + 1;
|
|
18
|
+
setTick(inc % spinner.frames.length);
|
|
19
|
+
}), spinner.interval);
|
|
20
|
+
}), 300);
|
|
21
|
+
return () => {
|
|
22
|
+
clearTimeout(delayTimeout);
|
|
23
|
+
clearInterval(tickInterval);
|
|
24
|
+
};
|
|
14
25
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
26
|
+
else {
|
|
27
|
+
setShowLoader(false);
|
|
28
|
+
}
|
|
29
|
+
}, [isLoading]);
|
|
30
|
+
if (showLoader) {
|
|
31
|
+
return spinner.frames[tick];
|
|
19
32
|
}
|
|
20
33
|
return prefix;
|
|
21
34
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inquirer/core",
|
|
3
|
-
"version": "8.2.
|
|
3
|
+
"version": "8.2.3",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=18"
|
|
6
6
|
},
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"@inquirer/figures": "^1.0.3",
|
|
61
61
|
"@inquirer/type": "^1.3.3",
|
|
62
62
|
"@types/mute-stream": "^0.0.4",
|
|
63
|
-
"@types/node": "^20.
|
|
63
|
+
"@types/node": "^20.14.6",
|
|
64
64
|
"@types/wrap-ansi": "^3.0.0",
|
|
65
65
|
"ansi-escapes": "^4.3.2",
|
|
66
66
|
"chalk": "^4.1.2",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"wrap-ansi": "^6.2.0"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
|
-
"@inquirer/testing": "^2.1.
|
|
75
|
+
"@inquirer/testing": "^2.1.22"
|
|
76
76
|
},
|
|
77
77
|
"scripts": {
|
|
78
78
|
"tsc": "yarn run tsc:esm && yarn run tsc:cjs",
|
|
@@ -97,5 +97,5 @@
|
|
|
97
97
|
}
|
|
98
98
|
},
|
|
99
99
|
"sideEffects": false,
|
|
100
|
-
"gitHead": "
|
|
100
|
+
"gitHead": "cc52a353abb1b7f3b3dc81b9e6da7ed478099dbf"
|
|
101
101
|
}
|