kodevu 0.1.15 → 0.1.16
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/package.json +1 -1
- package/src/progress-ui.js +29 -12
package/package.json
CHANGED
package/src/progress-ui.js
CHANGED
|
@@ -2,7 +2,6 @@ import readline from "node:readline";
|
|
|
2
2
|
|
|
3
3
|
const SPINNER_FRAMES = ["|", "/", "-", "\\"];
|
|
4
4
|
const DEFAULT_BAR_WIDTH = 24;
|
|
5
|
-
const MIN_BAR_WIDTH = 8;
|
|
6
5
|
|
|
7
6
|
function clampProgress(value) {
|
|
8
7
|
if (!Number.isFinite(value)) {
|
|
@@ -109,16 +108,34 @@ class ProgressItem {
|
|
|
109
108
|
buildLine(prefix, suffix) {
|
|
110
109
|
const availableWidth = this.display.getAvailableWidth();
|
|
111
110
|
const pct = `${Math.round(this.progress * 100)}`.padStart(3, " ");
|
|
112
|
-
const
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
111
|
+
const parts = [prefix, this.label];
|
|
112
|
+
const suffixText = suffix ? ` ${suffix}` : "";
|
|
113
|
+
|
|
114
|
+
if (availableWidth < 10) {
|
|
115
|
+
return truncateLine(`${prefix} ${pct}%`, availableWidth);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const fullReservedWidth = prefix.length + this.label.length + pct.length + suffixText.length + 4;
|
|
119
|
+
const fullBarWidth = availableWidth - fullReservedWidth;
|
|
120
|
+
|
|
121
|
+
if (fullBarWidth >= 4) {
|
|
122
|
+
return truncateLine(
|
|
123
|
+
`${parts.join(" ")} ${buildBar(this.progress, Math.min(this.barWidth, fullBarWidth))} ${pct}%${suffixText}`,
|
|
124
|
+
availableWidth
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const compactReservedWidth = prefix.length + pct.length + suffixText.length + 4;
|
|
129
|
+
const compactBarWidth = availableWidth - compactReservedWidth;
|
|
130
|
+
|
|
131
|
+
if (compactBarWidth >= 4) {
|
|
132
|
+
return truncateLine(
|
|
133
|
+
`${prefix} ${buildBar(this.progress, compactBarWidth)} ${pct}%${suffixText}`,
|
|
134
|
+
availableWidth
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return truncateLine(`${prefix} ${pct}%${suffixText}`, availableWidth);
|
|
122
139
|
}
|
|
123
140
|
|
|
124
141
|
writeFallback(line) {
|
|
@@ -237,7 +254,7 @@ export class ProgressDisplay {
|
|
|
237
254
|
|
|
238
255
|
getAvailableWidth() {
|
|
239
256
|
const columns = this.stream.columns || 80;
|
|
240
|
-
return Math.max(columns - 1,
|
|
257
|
+
return Math.max(columns - 1, 1);
|
|
241
258
|
}
|
|
242
259
|
|
|
243
260
|
handleResize() {
|