movehat 0.4.0 → 0.4.1
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/ui/spinner.js +21 -6
- package/package.json +1 -1
package/dist/ui/spinner.js
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
import ora from 'ora';
|
|
2
2
|
import { shouldUseColor } from './colors.js';
|
|
3
|
+
import { coloredSymbol } from './symbols.js';
|
|
4
|
+
/**
|
|
5
|
+
* Persist a spinner's final line with a color-gated status symbol.
|
|
6
|
+
*
|
|
7
|
+
* ora's own `.succeed()` / `.fail()` color their log-symbols through ora's
|
|
8
|
+
* internal TTY detection, which still emits ANSI on the persisted line when
|
|
9
|
+
* stdout is piped (non-TTY) even though our `shouldUseColor()` says no color.
|
|
10
|
+
* Routing the symbol through `coloredSymbol` (gated by `shouldUseColor`) keeps
|
|
11
|
+
* piped output escape-free while preserving the colored glyph in a real TTY.
|
|
12
|
+
*/
|
|
13
|
+
const persist = (spin, type, text) => {
|
|
14
|
+
spin.stopAndPersist(text === undefined
|
|
15
|
+
? { symbol: coloredSymbol(type) }
|
|
16
|
+
: { symbol: coloredSymbol(type), text });
|
|
17
|
+
};
|
|
3
18
|
/**
|
|
4
19
|
* Create and start a spinner
|
|
5
20
|
* Automatically disabled in non-TTY environments (CI, pipes)
|
|
@@ -63,12 +78,12 @@ export const withSpinner = async (startText, task, successText, errorText, inden
|
|
|
63
78
|
const spin = spinner({ text: startText, indent });
|
|
64
79
|
try {
|
|
65
80
|
const result = await task();
|
|
66
|
-
spin
|
|
81
|
+
persist(spin, 'success', successText || startText.replace(/\.\.\.?$/, ''));
|
|
67
82
|
return result;
|
|
68
83
|
}
|
|
69
84
|
catch (error) {
|
|
70
85
|
const errMsg = error instanceof Error ? error.message : String(error);
|
|
71
|
-
spin
|
|
86
|
+
persist(spin, 'error', errorText || `Failed: ${errMsg}`);
|
|
72
87
|
throw error;
|
|
73
88
|
}
|
|
74
89
|
};
|
|
@@ -104,12 +119,12 @@ export const withTimedSpinner = async (label, task, indent = 0) => {
|
|
|
104
119
|
}, 500);
|
|
105
120
|
try {
|
|
106
121
|
const result = await task();
|
|
107
|
-
spin
|
|
122
|
+
persist(spin, 'success', `${label} (${((Date.now() - start) / 1000).toFixed(1)}s)`);
|
|
108
123
|
return result;
|
|
109
124
|
}
|
|
110
125
|
catch (error) {
|
|
111
126
|
const errMsg = error instanceof Error ? error.message : String(error);
|
|
112
|
-
spin
|
|
127
|
+
persist(spin, 'error', errMsg);
|
|
113
128
|
throw error;
|
|
114
129
|
}
|
|
115
130
|
finally {
|
|
@@ -146,11 +161,11 @@ export const createSpinnerChain = () => {
|
|
|
146
161
|
currentSpinner = spinner({ text, indent });
|
|
147
162
|
try {
|
|
148
163
|
const result = await task();
|
|
149
|
-
currentSpinner
|
|
164
|
+
persist(currentSpinner, 'success');
|
|
150
165
|
return result;
|
|
151
166
|
}
|
|
152
167
|
catch (error) {
|
|
153
|
-
currentSpinner
|
|
168
|
+
persist(currentSpinner, 'error');
|
|
154
169
|
throw error;
|
|
155
170
|
}
|
|
156
171
|
},
|