@tuicomponents/progress 0.1.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/index.cjs +370 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +199 -0
- package/dist/index.d.ts +199 -0
- package/dist/index.js +340 -0
- package/dist/index.js.map +1 -0
- package/package.json +50 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
ProgressComponent: () => ProgressComponent,
|
|
24
|
+
computeProgressLayout: () => computeProgressLayout,
|
|
25
|
+
createProgress: () => createProgress,
|
|
26
|
+
getProgressChars: () => getProgressChars,
|
|
27
|
+
progressInputSchema: () => progressInputSchema,
|
|
28
|
+
progressStyleSchema: () => progressStyleSchema,
|
|
29
|
+
renderProgressAnsi: () => renderProgressAnsi,
|
|
30
|
+
renderProgressMarkdown: () => renderProgressMarkdown
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(index_exports);
|
|
33
|
+
|
|
34
|
+
// src/progress.ts
|
|
35
|
+
var import_core2 = require("@tuicomponents/core");
|
|
36
|
+
var import_zod_to_json_schema = require("zod-to-json-schema");
|
|
37
|
+
|
|
38
|
+
// src/schema.ts
|
|
39
|
+
var import_zod = require("zod");
|
|
40
|
+
var progressStyleSchema = import_zod.z.enum([
|
|
41
|
+
"block",
|
|
42
|
+
"shaded",
|
|
43
|
+
"bracket",
|
|
44
|
+
"arrow",
|
|
45
|
+
"ascii"
|
|
46
|
+
]);
|
|
47
|
+
var progressInputSchema = import_zod.z.object({
|
|
48
|
+
/**
|
|
49
|
+
* Current progress value (0 or greater).
|
|
50
|
+
* Required unless indeterminate state is desired.
|
|
51
|
+
*/
|
|
52
|
+
value: import_zod.z.number().nonnegative(),
|
|
53
|
+
/**
|
|
54
|
+
* Maximum value (determines 100%).
|
|
55
|
+
* @default 100
|
|
56
|
+
*/
|
|
57
|
+
max: import_zod.z.number().positive().default(100),
|
|
58
|
+
/**
|
|
59
|
+
* Width of the progress bar in characters.
|
|
60
|
+
* @default 20
|
|
61
|
+
*/
|
|
62
|
+
width: import_zod.z.number().int().positive().default(20),
|
|
63
|
+
/**
|
|
64
|
+
* Style for progress bar characters.
|
|
65
|
+
* @default "block"
|
|
66
|
+
*/
|
|
67
|
+
style: progressStyleSchema.default("block"),
|
|
68
|
+
/**
|
|
69
|
+
* Custom filled character (overrides style default).
|
|
70
|
+
*/
|
|
71
|
+
filledChar: import_zod.z.string().length(1).optional(),
|
|
72
|
+
/**
|
|
73
|
+
* Custom empty character (overrides style default).
|
|
74
|
+
*/
|
|
75
|
+
emptyChar: import_zod.z.string().length(1).optional(),
|
|
76
|
+
/**
|
|
77
|
+
* Optional label to display before the progress bar.
|
|
78
|
+
*/
|
|
79
|
+
label: import_zod.z.string().optional(),
|
|
80
|
+
/**
|
|
81
|
+
* Whether to show percentage after the bar.
|
|
82
|
+
* @default true
|
|
83
|
+
*/
|
|
84
|
+
showPercentage: import_zod.z.boolean().default(true),
|
|
85
|
+
/**
|
|
86
|
+
* Whether to show the current/max value (e.g., "12/25").
|
|
87
|
+
* @default false
|
|
88
|
+
*/
|
|
89
|
+
showValue: import_zod.z.boolean().default(false)
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// src/chars.ts
|
|
93
|
+
var blockChars = {
|
|
94
|
+
filled: "\u2588",
|
|
95
|
+
empty: "\u2591",
|
|
96
|
+
leftBracket: "",
|
|
97
|
+
rightBracket: ""
|
|
98
|
+
};
|
|
99
|
+
var shadedChars = {
|
|
100
|
+
filled: "\u2593",
|
|
101
|
+
empty: "\u2591",
|
|
102
|
+
leftBracket: "",
|
|
103
|
+
rightBracket: ""
|
|
104
|
+
};
|
|
105
|
+
var bracketChars = {
|
|
106
|
+
filled: "\u2588",
|
|
107
|
+
empty: "\u2591",
|
|
108
|
+
leftBracket: "[",
|
|
109
|
+
rightBracket: "]"
|
|
110
|
+
};
|
|
111
|
+
var arrowChars = {
|
|
112
|
+
filled: ">",
|
|
113
|
+
empty: "-",
|
|
114
|
+
leftBracket: "",
|
|
115
|
+
rightBracket: ""
|
|
116
|
+
};
|
|
117
|
+
var asciiChars = {
|
|
118
|
+
filled: "#",
|
|
119
|
+
empty: ".",
|
|
120
|
+
leftBracket: "",
|
|
121
|
+
rightBracket: ""
|
|
122
|
+
};
|
|
123
|
+
function getProgressChars(style) {
|
|
124
|
+
switch (style) {
|
|
125
|
+
case "block":
|
|
126
|
+
return blockChars;
|
|
127
|
+
case "shaded":
|
|
128
|
+
return shadedChars;
|
|
129
|
+
case "bracket":
|
|
130
|
+
return bracketChars;
|
|
131
|
+
case "arrow":
|
|
132
|
+
return arrowChars;
|
|
133
|
+
case "ascii":
|
|
134
|
+
return asciiChars;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// src/layout.ts
|
|
139
|
+
function computeProgressLayout(input, chars) {
|
|
140
|
+
const rawPercentage = input.max > 0 ? input.value / input.max * 100 : 0;
|
|
141
|
+
const percentage = Math.min(100, Math.max(0, rawPercentage));
|
|
142
|
+
const barWidth = input.width;
|
|
143
|
+
const filledCount = Math.round(percentage / 100 * barWidth);
|
|
144
|
+
const emptyCount = barWidth - filledCount;
|
|
145
|
+
const filledChar = input.filledChar ?? chars.filled;
|
|
146
|
+
const emptyChar = input.emptyChar ?? chars.empty;
|
|
147
|
+
const filledBar = filledChar.repeat(filledCount);
|
|
148
|
+
const emptyBar = emptyChar.repeat(emptyCount);
|
|
149
|
+
const percentageStr = `${String(Math.round(percentage))}%`;
|
|
150
|
+
const valueStr = `${String(input.value)}/${String(input.max)}`;
|
|
151
|
+
return {
|
|
152
|
+
label: input.label ?? "",
|
|
153
|
+
filledBar,
|
|
154
|
+
emptyBar,
|
|
155
|
+
leftBracket: chars.leftBracket,
|
|
156
|
+
rightBracket: chars.rightBracket,
|
|
157
|
+
percentage,
|
|
158
|
+
percentageStr,
|
|
159
|
+
valueStr,
|
|
160
|
+
filledCount,
|
|
161
|
+
emptyCount,
|
|
162
|
+
barWidth
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// src/renderers.ts
|
|
167
|
+
var import_core = require("@tuicomponents/core");
|
|
168
|
+
function renderProgressAnsi(layout, input, theme) {
|
|
169
|
+
const parts = [];
|
|
170
|
+
if (layout.label) {
|
|
171
|
+
const coloredLabel = theme ? theme.semantic.header(layout.label) : layout.label;
|
|
172
|
+
parts.push(coloredLabel);
|
|
173
|
+
parts.push(" ");
|
|
174
|
+
}
|
|
175
|
+
if (layout.leftBracket) {
|
|
176
|
+
const coloredBracket = theme ? theme.semantic.border(layout.leftBracket) : layout.leftBracket;
|
|
177
|
+
parts.push(coloredBracket);
|
|
178
|
+
}
|
|
179
|
+
const coloredFilled = theme ? theme.semantic.primary(layout.filledBar) : layout.filledBar;
|
|
180
|
+
const coloredEmpty = theme ? theme.semantic.secondary(layout.emptyBar) : layout.emptyBar;
|
|
181
|
+
parts.push(coloredFilled);
|
|
182
|
+
parts.push(coloredEmpty);
|
|
183
|
+
if (layout.rightBracket) {
|
|
184
|
+
const coloredBracket = theme ? theme.semantic.border(layout.rightBracket) : layout.rightBracket;
|
|
185
|
+
parts.push(coloredBracket);
|
|
186
|
+
}
|
|
187
|
+
const suffix = buildSuffix(layout, input, theme);
|
|
188
|
+
if (suffix) {
|
|
189
|
+
parts.push(" ");
|
|
190
|
+
parts.push(suffix);
|
|
191
|
+
}
|
|
192
|
+
return parts.join("");
|
|
193
|
+
}
|
|
194
|
+
function renderProgressMarkdown(layout, input) {
|
|
195
|
+
const parts = [];
|
|
196
|
+
if (layout.label) {
|
|
197
|
+
parts.push(layout.label);
|
|
198
|
+
parts.push(" ");
|
|
199
|
+
}
|
|
200
|
+
if (layout.leftBracket) {
|
|
201
|
+
parts.push(layout.leftBracket);
|
|
202
|
+
}
|
|
203
|
+
parts.push(layout.filledBar);
|
|
204
|
+
parts.push(layout.emptyBar);
|
|
205
|
+
if (layout.rightBracket) {
|
|
206
|
+
parts.push(layout.rightBracket);
|
|
207
|
+
}
|
|
208
|
+
const suffix = buildSuffix(layout, input);
|
|
209
|
+
if (suffix) {
|
|
210
|
+
parts.push(" ");
|
|
211
|
+
parts.push(suffix);
|
|
212
|
+
}
|
|
213
|
+
return (0, import_core.anchorLine)(parts.join(""), import_core.DEFAULT_ANCHOR);
|
|
214
|
+
}
|
|
215
|
+
function buildSuffix(layout, input, theme) {
|
|
216
|
+
const suffixParts = [];
|
|
217
|
+
if (input.showPercentage) {
|
|
218
|
+
suffixParts.push(layout.percentageStr);
|
|
219
|
+
}
|
|
220
|
+
if (input.showValue) {
|
|
221
|
+
suffixParts.push(layout.valueStr);
|
|
222
|
+
}
|
|
223
|
+
if (suffixParts.length === 0) {
|
|
224
|
+
return "";
|
|
225
|
+
}
|
|
226
|
+
const suffix = suffixParts.join(" ");
|
|
227
|
+
return theme ? theme.semantic.secondary(suffix) : suffix;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// src/progress.ts
|
|
231
|
+
var ProgressComponent = class extends import_core2.BaseTuiComponent {
|
|
232
|
+
metadata = {
|
|
233
|
+
name: "progress",
|
|
234
|
+
description: "Renders horizontal progress bars for task completion",
|
|
235
|
+
version: "0.1.0",
|
|
236
|
+
supportedModes: ["ansi", "markdown"],
|
|
237
|
+
examples: [
|
|
238
|
+
{
|
|
239
|
+
name: "basic",
|
|
240
|
+
description: "Simple progress bar at 50%",
|
|
241
|
+
input: {
|
|
242
|
+
value: 50,
|
|
243
|
+
max: 100
|
|
244
|
+
}
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
name: "with-label",
|
|
248
|
+
description: "Progress bar with label",
|
|
249
|
+
input: {
|
|
250
|
+
value: 75,
|
|
251
|
+
max: 100,
|
|
252
|
+
label: "Loading:"
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
name: "block-style",
|
|
257
|
+
description: "Block style progress bar",
|
|
258
|
+
input: {
|
|
259
|
+
value: 60,
|
|
260
|
+
max: 100,
|
|
261
|
+
style: "block",
|
|
262
|
+
label: "Progress"
|
|
263
|
+
}
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
name: "shaded-style",
|
|
267
|
+
description: "Shaded style progress bar",
|
|
268
|
+
input: {
|
|
269
|
+
value: 40,
|
|
270
|
+
max: 100,
|
|
271
|
+
style: "shaded"
|
|
272
|
+
}
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
name: "bracket-style",
|
|
276
|
+
description: "Bracket style progress bar",
|
|
277
|
+
input: {
|
|
278
|
+
value: 80,
|
|
279
|
+
max: 100,
|
|
280
|
+
style: "bracket"
|
|
281
|
+
}
|
|
282
|
+
},
|
|
283
|
+
{
|
|
284
|
+
name: "arrow-style",
|
|
285
|
+
description: "Arrow style progress bar",
|
|
286
|
+
input: {
|
|
287
|
+
value: 65,
|
|
288
|
+
max: 100,
|
|
289
|
+
style: "arrow"
|
|
290
|
+
}
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
name: "ascii-style",
|
|
294
|
+
description: "ASCII style progress bar",
|
|
295
|
+
input: {
|
|
296
|
+
value: 50,
|
|
297
|
+
max: 100,
|
|
298
|
+
style: "ascii"
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
name: "with-value",
|
|
303
|
+
description: "Progress bar showing current/max value",
|
|
304
|
+
input: {
|
|
305
|
+
value: 12,
|
|
306
|
+
max: 25,
|
|
307
|
+
label: "Downloads",
|
|
308
|
+
showValue: true
|
|
309
|
+
}
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
name: "complete",
|
|
313
|
+
description: "100% complete progress bar",
|
|
314
|
+
input: {
|
|
315
|
+
value: 100,
|
|
316
|
+
max: 100,
|
|
317
|
+
style: "bracket"
|
|
318
|
+
}
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
name: "custom-width",
|
|
322
|
+
description: "Wide progress bar",
|
|
323
|
+
input: {
|
|
324
|
+
value: 45,
|
|
325
|
+
max: 100,
|
|
326
|
+
width: 40,
|
|
327
|
+
label: "Processing:"
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
]
|
|
331
|
+
};
|
|
332
|
+
schema = progressInputSchema;
|
|
333
|
+
/**
|
|
334
|
+
* Override getJsonSchema to use direct schema generation.
|
|
335
|
+
*/
|
|
336
|
+
getJsonSchema() {
|
|
337
|
+
return (0, import_zod_to_json_schema.zodToJsonSchema)(this.schema, {
|
|
338
|
+
name: this.metadata.name,
|
|
339
|
+
$refStrategy: "none"
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
render(input, context) {
|
|
343
|
+
const parsed = this.schema.parse(input);
|
|
344
|
+
const chars = getProgressChars(parsed.style);
|
|
345
|
+
const layout = computeProgressLayout(parsed, chars);
|
|
346
|
+
const output = context.renderMode === "markdown" ? renderProgressMarkdown(layout, parsed) : renderProgressAnsi(layout, parsed, context.theme);
|
|
347
|
+
const measured = (0, import_core2.measureLines)(output);
|
|
348
|
+
return {
|
|
349
|
+
output,
|
|
350
|
+
actualWidth: measured.maxWidth,
|
|
351
|
+
lineCount: measured.lineCount
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
function createProgress() {
|
|
356
|
+
return new ProgressComponent();
|
|
357
|
+
}
|
|
358
|
+
import_core2.registry.register(createProgress);
|
|
359
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
360
|
+
0 && (module.exports = {
|
|
361
|
+
ProgressComponent,
|
|
362
|
+
computeProgressLayout,
|
|
363
|
+
createProgress,
|
|
364
|
+
getProgressChars,
|
|
365
|
+
progressInputSchema,
|
|
366
|
+
progressStyleSchema,
|
|
367
|
+
renderProgressAnsi,
|
|
368
|
+
renderProgressMarkdown
|
|
369
|
+
});
|
|
370
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/progress.ts","../src/schema.ts","../src/chars.ts","../src/layout.ts","../src/renderers.ts"],"sourcesContent":["export { createProgress, ProgressComponent } from \"./progress.js\";\nexport {\n progressInputSchema,\n progressStyleSchema,\n type ProgressInput,\n type ProgressInputWithDefaults,\n type ProgressStyle,\n} from \"./schema.js\";\nexport { type ProgressChars, getProgressChars } from \"./chars.js\";\nexport { type ProgressLayout, computeProgressLayout } from \"./layout.js\";\nexport { renderProgressAnsi, renderProgressMarkdown } from \"./renderers.js\";\n","import {\n BaseTuiComponent,\n type ComponentMetadata,\n type RenderContext,\n type RenderResult,\n measureLines,\n registry,\n} from \"@tuicomponents/core\";\nimport { zodToJsonSchema } from \"zod-to-json-schema\";\nimport { progressInputSchema, type ProgressInput } from \"./schema.js\";\nimport { getProgressChars } from \"./chars.js\";\nimport { computeProgressLayout } from \"./layout.js\";\nimport { renderProgressAnsi, renderProgressMarkdown } from \"./renderers.js\";\n\n/**\n * Progress component for rendering horizontal progress bars.\n */\nclass ProgressComponent extends BaseTuiComponent<\n ProgressInput,\n typeof progressInputSchema\n> {\n readonly metadata: ComponentMetadata<ProgressInput> = {\n name: \"progress\",\n description: \"Renders horizontal progress bars for task completion\",\n version: \"0.1.0\",\n supportedModes: [\"ansi\", \"markdown\"],\n examples: [\n {\n name: \"basic\",\n description: \"Simple progress bar at 50%\",\n input: {\n value: 50,\n max: 100,\n },\n },\n {\n name: \"with-label\",\n description: \"Progress bar with label\",\n input: {\n value: 75,\n max: 100,\n label: \"Loading:\",\n },\n },\n {\n name: \"block-style\",\n description: \"Block style progress bar\",\n input: {\n value: 60,\n max: 100,\n style: \"block\",\n label: \"Progress\",\n },\n },\n {\n name: \"shaded-style\",\n description: \"Shaded style progress bar\",\n input: {\n value: 40,\n max: 100,\n style: \"shaded\",\n },\n },\n {\n name: \"bracket-style\",\n description: \"Bracket style progress bar\",\n input: {\n value: 80,\n max: 100,\n style: \"bracket\",\n },\n },\n {\n name: \"arrow-style\",\n description: \"Arrow style progress bar\",\n input: {\n value: 65,\n max: 100,\n style: \"arrow\",\n },\n },\n {\n name: \"ascii-style\",\n description: \"ASCII style progress bar\",\n input: {\n value: 50,\n max: 100,\n style: \"ascii\",\n },\n },\n {\n name: \"with-value\",\n description: \"Progress bar showing current/max value\",\n input: {\n value: 12,\n max: 25,\n label: \"Downloads\",\n showValue: true,\n },\n },\n {\n name: \"complete\",\n description: \"100% complete progress bar\",\n input: {\n value: 100,\n max: 100,\n style: \"bracket\",\n },\n },\n {\n name: \"custom-width\",\n description: \"Wide progress bar\",\n input: {\n value: 45,\n max: 100,\n width: 40,\n label: \"Processing:\",\n },\n },\n ],\n };\n\n readonly schema = progressInputSchema;\n\n /**\n * Override getJsonSchema to use direct schema generation.\n */\n override getJsonSchema(): object {\n return zodToJsonSchema(this.schema, {\n name: this.metadata.name,\n $refStrategy: \"none\",\n });\n }\n\n render(input: ProgressInput, context: RenderContext): RenderResult {\n const parsed = this.schema.parse(input);\n\n // Get character set based on style\n const chars = getProgressChars(parsed.style);\n\n // Compute layout once, share between renderers\n const layout = computeProgressLayout(parsed, chars);\n\n // Choose renderer based on render mode\n const output =\n context.renderMode === \"markdown\"\n ? renderProgressMarkdown(layout, parsed)\n : renderProgressAnsi(layout, parsed, context.theme);\n\n const measured = measureLines(output);\n\n return {\n output,\n actualWidth: measured.maxWidth,\n lineCount: measured.lineCount,\n };\n }\n}\n\n/**\n * Factory function to create a progress component.\n */\nexport function createProgress(): ProgressComponent {\n return new ProgressComponent();\n}\n\n// Register with global registry\nregistry.register(createProgress);\n\nexport { ProgressComponent };\n","import { z } from \"zod\";\n\n/**\n * Style options for progress bar characters.\n */\nexport const progressStyleSchema = z.enum([\n \"block\",\n \"shaded\",\n \"bracket\",\n \"arrow\",\n \"ascii\",\n]);\n\nexport type ProgressStyle = z.infer<typeof progressStyleSchema>;\n\n/**\n * Schema for progress component input.\n */\nexport const progressInputSchema = z.object({\n /**\n * Current progress value (0 or greater).\n * Required unless indeterminate state is desired.\n */\n value: z.number().nonnegative(),\n\n /**\n * Maximum value (determines 100%).\n * @default 100\n */\n max: z.number().positive().default(100),\n\n /**\n * Width of the progress bar in characters.\n * @default 20\n */\n width: z.number().int().positive().default(20),\n\n /**\n * Style for progress bar characters.\n * @default \"block\"\n */\n style: progressStyleSchema.default(\"block\"),\n\n /**\n * Custom filled character (overrides style default).\n */\n filledChar: z.string().length(1).optional(),\n\n /**\n * Custom empty character (overrides style default).\n */\n emptyChar: z.string().length(1).optional(),\n\n /**\n * Optional label to display before the progress bar.\n */\n label: z.string().optional(),\n\n /**\n * Whether to show percentage after the bar.\n * @default true\n */\n showPercentage: z.boolean().default(true),\n\n /**\n * Whether to show the current/max value (e.g., \"12/25\").\n * @default false\n */\n showValue: z.boolean().default(false),\n});\n\nexport type ProgressInput = z.input<typeof progressInputSchema>;\nexport type ProgressInputWithDefaults = z.output<typeof progressInputSchema>;\n","import type { ProgressStyle } from \"./schema.js\";\n\n/**\n * Characters used for progress bar rendering.\n */\nexport interface ProgressChars {\n /** Filled portion character */\n filled: string;\n /** Empty portion character */\n empty: string;\n /** Left bracket (only for bracket style) */\n leftBracket: string;\n /** Right bracket (only for bracket style) */\n rightBracket: string;\n}\n\n/**\n * Block style: █░\n */\nconst blockChars: ProgressChars = {\n filled: \"█\",\n empty: \"░\",\n leftBracket: \"\",\n rightBracket: \"\",\n};\n\n/**\n * Shaded style: ▓░\n */\nconst shadedChars: ProgressChars = {\n filled: \"▓\",\n empty: \"░\",\n leftBracket: \"\",\n rightBracket: \"\",\n};\n\n/**\n * Bracket style: [█░]\n */\nconst bracketChars: ProgressChars = {\n filled: \"█\",\n empty: \"░\",\n leftBracket: \"[\",\n rightBracket: \"]\",\n};\n\n/**\n * Arrow style: >-\n */\nconst arrowChars: ProgressChars = {\n filled: \">\",\n empty: \"-\",\n leftBracket: \"\",\n rightBracket: \"\",\n};\n\n/**\n * ASCII style: #.\n */\nconst asciiChars: ProgressChars = {\n filled: \"#\",\n empty: \".\",\n leftBracket: \"\",\n rightBracket: \"\",\n};\n\n/**\n * Get progress bar characters for a given style.\n */\nexport function getProgressChars(style: ProgressStyle): ProgressChars {\n switch (style) {\n case \"block\":\n return blockChars;\n case \"shaded\":\n return shadedChars;\n case \"bracket\":\n return bracketChars;\n case \"arrow\":\n return arrowChars;\n case \"ascii\":\n return asciiChars;\n }\n}\n","import type { ProgressInputWithDefaults } from \"./schema.js\";\nimport type { ProgressChars } from \"./chars.js\";\n\n/**\n * Pre-computed layout for the progress bar.\n */\nexport interface ProgressLayout {\n /** Label to display (empty string if none) */\n label: string;\n /** Filled portion of the bar */\n filledBar: string;\n /** Empty portion of the bar */\n emptyBar: string;\n /** Left bracket (empty for non-bracket styles) */\n leftBracket: string;\n /** Right bracket (empty for non-bracket styles) */\n rightBracket: string;\n /** Percentage (0-100) */\n percentage: number;\n /** Formatted percentage string (e.g., \"50%\") */\n percentageStr: string;\n /** Formatted value string (e.g., \"12/25\") */\n valueStr: string;\n /** Number of filled characters */\n filledCount: number;\n /** Number of empty characters */\n emptyCount: number;\n /** Total width of the bar portion */\n barWidth: number;\n}\n\n/**\n * Compute the layout for a progress bar.\n *\n * @param input - Validated progress input with defaults applied\n * @param chars - Character set to use\n * @returns Computed layout ready for rendering\n */\nexport function computeProgressLayout(\n input: ProgressInputWithDefaults,\n chars: ProgressChars\n): ProgressLayout {\n // Calculate percentage (clamped to 0-100)\n const rawPercentage = input.max > 0 ? (input.value / input.max) * 100 : 0;\n const percentage = Math.min(100, Math.max(0, rawPercentage));\n\n // Determine actual bar width (accounting for brackets if present)\n const barWidth = input.width;\n\n // Calculate filled/empty character counts\n const filledCount = Math.round((percentage / 100) * barWidth);\n const emptyCount = barWidth - filledCount;\n\n // Get effective characters (allow override)\n const filledChar = input.filledChar ?? chars.filled;\n const emptyChar = input.emptyChar ?? chars.empty;\n\n // Build bar strings\n const filledBar = filledChar.repeat(filledCount);\n const emptyBar = emptyChar.repeat(emptyCount);\n\n // Format percentage\n const percentageStr = `${String(Math.round(percentage))}%`;\n\n // Format value\n const valueStr = `${String(input.value)}/${String(input.max)}`;\n\n return {\n label: input.label ?? \"\",\n filledBar,\n emptyBar,\n leftBracket: chars.leftBracket,\n rightBracket: chars.rightBracket,\n percentage,\n percentageStr,\n valueStr,\n filledCount,\n emptyCount,\n barWidth,\n };\n}\n","import { type TuiTheme, anchorLine, DEFAULT_ANCHOR } from \"@tuicomponents/core\";\nimport type { ProgressLayout } from \"./layout.js\";\nimport type { ProgressInputWithDefaults } from \"./schema.js\";\n\n/**\n * Render a progress bar using ANSI escape codes for rich terminal output.\n *\n * @param layout - Pre-computed progress layout\n * @param input - Original input with defaults\n * @param theme - Optional theme for colors\n * @returns ANSI-formatted progress bar string\n */\nexport function renderProgressAnsi(\n layout: ProgressLayout,\n input: ProgressInputWithDefaults,\n theme?: TuiTheme\n): string {\n const parts: string[] = [];\n\n // Add label if present\n if (layout.label) {\n const coloredLabel = theme\n ? theme.semantic.header(layout.label)\n : layout.label;\n parts.push(coloredLabel);\n parts.push(\" \");\n }\n\n // Add left bracket\n if (layout.leftBracket) {\n const coloredBracket = theme\n ? theme.semantic.border(layout.leftBracket)\n : layout.leftBracket;\n parts.push(coloredBracket);\n }\n\n // Add bar\n const coloredFilled = theme\n ? theme.semantic.primary(layout.filledBar)\n : layout.filledBar;\n const coloredEmpty = theme\n ? theme.semantic.secondary(layout.emptyBar)\n : layout.emptyBar;\n parts.push(coloredFilled);\n parts.push(coloredEmpty);\n\n // Add right bracket\n if (layout.rightBracket) {\n const coloredBracket = theme\n ? theme.semantic.border(layout.rightBracket)\n : layout.rightBracket;\n parts.push(coloredBracket);\n }\n\n // Add percentage and/or value\n const suffix = buildSuffix(layout, input, theme);\n if (suffix) {\n parts.push(\" \");\n parts.push(suffix);\n }\n\n return parts.join(\"\");\n}\n\n/**\n * Render a progress bar using markdown-friendly output.\n *\n * @param layout - Pre-computed progress layout\n * @param input - Original input with defaults\n * @returns Markdown-friendly progress bar string\n */\nexport function renderProgressMarkdown(\n layout: ProgressLayout,\n input: ProgressInputWithDefaults\n): string {\n const parts: string[] = [];\n\n // Add label if present\n if (layout.label) {\n parts.push(layout.label);\n parts.push(\" \");\n }\n\n // Add left bracket\n if (layout.leftBracket) {\n parts.push(layout.leftBracket);\n }\n\n // Add bar\n parts.push(layout.filledBar);\n parts.push(layout.emptyBar);\n\n // Add right bracket\n if (layout.rightBracket) {\n parts.push(layout.rightBracket);\n }\n\n // Add percentage and/or value\n const suffix = buildSuffix(layout, input);\n if (suffix) {\n parts.push(\" \");\n parts.push(suffix);\n }\n\n return anchorLine(parts.join(\"\"), DEFAULT_ANCHOR);\n}\n\n/**\n * Build the suffix string (percentage and/or value).\n */\nfunction buildSuffix(\n layout: ProgressLayout,\n input: ProgressInputWithDefaults,\n theme?: TuiTheme\n): string {\n const suffixParts: string[] = [];\n\n if (input.showPercentage) {\n suffixParts.push(layout.percentageStr);\n }\n\n if (input.showValue) {\n suffixParts.push(layout.valueStr);\n }\n\n if (suffixParts.length === 0) {\n return \"\";\n }\n\n const suffix = suffixParts.join(\" \");\n return theme ? theme.semantic.secondary(suffix) : suffix;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,eAOO;AACP,gCAAgC;;;ACRhC,iBAAkB;AAKX,IAAM,sBAAsB,aAAE,KAAK;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAOM,IAAM,sBAAsB,aAAE,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA,EAK1C,OAAO,aAAE,OAAO,EAAE,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA,EAM9B,KAAK,aAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,GAAG;AAAA;AAAA;AAAA;AAAA;AAAA,EAMtC,OAAO,aAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE;AAAA;AAAA;AAAA;AAAA;AAAA,EAM7C,OAAO,oBAAoB,QAAQ,OAAO;AAAA;AAAA;AAAA;AAAA,EAK1C,YAAY,aAAE,OAAO,EAAE,OAAO,CAAC,EAAE,SAAS;AAAA;AAAA;AAAA;AAAA,EAK1C,WAAW,aAAE,OAAO,EAAE,OAAO,CAAC,EAAE,SAAS;AAAA;AAAA;AAAA;AAAA,EAKzC,OAAO,aAAE,OAAO,EAAE,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA,EAM3B,gBAAgB,aAAE,QAAQ,EAAE,QAAQ,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA,EAMxC,WAAW,aAAE,QAAQ,EAAE,QAAQ,KAAK;AACtC,CAAC;;;AClDD,IAAM,aAA4B;AAAA,EAChC,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,aAAa;AAAA,EACb,cAAc;AA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Ae,aACnB,uBAAuB,QAAQ,MAAM,IACrC,mBAAmB,QAAQ,QAAQ,QAAQ,KAAK;AAEtD,UAAM,eAAW,2BAAa,MAAM;AAEpC,WAAO;AAAA,MACL;AAAA,MACA,aAAa,SAAS;AAAA,MACtB,WAAW,SAAS;AAAA,IACtB;AAAA,EACF;AACF;AAKO,SAAS,iBAAoC;AAClD,SAAO,IAAI,kBAAkB;AAC/B;AAGA,sBAAS,SAAS,cAAc;","names":["import_core"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import * as zod from 'zod';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { BaseTuiComponent, ComponentMetadata, RenderContext, RenderResult, TuiTheme } from '@tuicomponents/core';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Style options for progress bar characters.
|
|
7
|
+
*/
|
|
8
|
+
declare const progressStyleSchema: z.ZodEnum<["block", "shaded", "bracket", "arrow", "ascii"]>;
|
|
9
|
+
type ProgressStyle = z.infer<typeof progressStyleSchema>;
|
|
10
|
+
/**
|
|
11
|
+
* Schema for progress component input.
|
|
12
|
+
*/
|
|
13
|
+
declare const progressInputSchema: z.ZodObject<{
|
|
14
|
+
/**
|
|
15
|
+
* Current progress value (0 or greater).
|
|
16
|
+
* Required unless indeterminate state is desired.
|
|
17
|
+
*/
|
|
18
|
+
value: z.ZodNumber;
|
|
19
|
+
/**
|
|
20
|
+
* Maximum value (determines 100%).
|
|
21
|
+
* @default 100
|
|
22
|
+
*/
|
|
23
|
+
max: z.ZodDefault<z.ZodNumber>;
|
|
24
|
+
/**
|
|
25
|
+
* Width of the progress bar in characters.
|
|
26
|
+
* @default 20
|
|
27
|
+
*/
|
|
28
|
+
width: z.ZodDefault<z.ZodNumber>;
|
|
29
|
+
/**
|
|
30
|
+
* Style for progress bar characters.
|
|
31
|
+
* @default "block"
|
|
32
|
+
*/
|
|
33
|
+
style: z.ZodDefault<z.ZodEnum<["block", "shaded", "bracket", "arrow", "ascii"]>>;
|
|
34
|
+
/**
|
|
35
|
+
* Custom filled character (overrides style default).
|
|
36
|
+
*/
|
|
37
|
+
filledChar: z.ZodOptional<z.ZodString>;
|
|
38
|
+
/**
|
|
39
|
+
* Custom empty character (overrides style default).
|
|
40
|
+
*/
|
|
41
|
+
emptyChar: z.ZodOptional<z.ZodString>;
|
|
42
|
+
/**
|
|
43
|
+
* Optional label to display before the progress bar.
|
|
44
|
+
*/
|
|
45
|
+
label: z.ZodOptional<z.ZodString>;
|
|
46
|
+
/**
|
|
47
|
+
* Whether to show percentage after the bar.
|
|
48
|
+
* @default true
|
|
49
|
+
*/
|
|
50
|
+
showPercentage: z.ZodDefault<z.ZodBoolean>;
|
|
51
|
+
/**
|
|
52
|
+
* Whether to show the current/max value (e.g., "12/25").
|
|
53
|
+
* @default false
|
|
54
|
+
*/
|
|
55
|
+
showValue: z.ZodDefault<z.ZodBoolean>;
|
|
56
|
+
}, "strip", z.ZodTypeAny, {
|
|
57
|
+
value: number;
|
|
58
|
+
max: number;
|
|
59
|
+
width: number;
|
|
60
|
+
style: "block" | "shaded" | "bracket" | "arrow" | "ascii";
|
|
61
|
+
showPercentage: boolean;
|
|
62
|
+
showValue: boolean;
|
|
63
|
+
filledChar?: string | undefined;
|
|
64
|
+
emptyChar?: string | undefined;
|
|
65
|
+
label?: string | undefined;
|
|
66
|
+
}, {
|
|
67
|
+
value: number;
|
|
68
|
+
max?: number | undefined;
|
|
69
|
+
width?: number | undefined;
|
|
70
|
+
style?: "block" | "shaded" | "bracket" | "arrow" | "ascii" | undefined;
|
|
71
|
+
filledChar?: string | undefined;
|
|
72
|
+
emptyChar?: string | undefined;
|
|
73
|
+
label?: string | undefined;
|
|
74
|
+
showPercentage?: boolean | undefined;
|
|
75
|
+
showValue?: boolean | undefined;
|
|
76
|
+
}>;
|
|
77
|
+
type ProgressInput = z.input<typeof progressInputSchema>;
|
|
78
|
+
type ProgressInputWithDefaults = z.output<typeof progressInputSchema>;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Progress component for rendering horizontal progress bars.
|
|
82
|
+
*/
|
|
83
|
+
declare class ProgressComponent extends BaseTuiComponent<ProgressInput, typeof progressInputSchema> {
|
|
84
|
+
readonly metadata: ComponentMetadata<ProgressInput>;
|
|
85
|
+
readonly schema: zod.ZodObject<{
|
|
86
|
+
value: zod.ZodNumber;
|
|
87
|
+
max: zod.ZodDefault<zod.ZodNumber>;
|
|
88
|
+
width: zod.ZodDefault<zod.ZodNumber>;
|
|
89
|
+
style: zod.ZodDefault<zod.ZodEnum<["block", "shaded", "bracket", "arrow", "ascii"]>>;
|
|
90
|
+
filledChar: zod.ZodOptional<zod.ZodString>;
|
|
91
|
+
emptyChar: zod.ZodOptional<zod.ZodString>;
|
|
92
|
+
label: zod.ZodOptional<zod.ZodString>;
|
|
93
|
+
showPercentage: zod.ZodDefault<zod.ZodBoolean>;
|
|
94
|
+
showValue: zod.ZodDefault<zod.ZodBoolean>;
|
|
95
|
+
}, "strip", zod.ZodTypeAny, {
|
|
96
|
+
value: number;
|
|
97
|
+
max: number;
|
|
98
|
+
width: number;
|
|
99
|
+
style: "block" | "shaded" | "bracket" | "arrow" | "ascii";
|
|
100
|
+
showPercentage: boolean;
|
|
101
|
+
showValue: boolean;
|
|
102
|
+
filledChar?: string | undefined;
|
|
103
|
+
emptyChar?: string | undefined;
|
|
104
|
+
label?: string | undefined;
|
|
105
|
+
}, {
|
|
106
|
+
value: number;
|
|
107
|
+
max?: number | undefined;
|
|
108
|
+
width?: number | undefined;
|
|
109
|
+
style?: "block" | "shaded" | "bracket" | "arrow" | "ascii" | undefined;
|
|
110
|
+
filledChar?: string | undefined;
|
|
111
|
+
emptyChar?: string | undefined;
|
|
112
|
+
label?: string | undefined;
|
|
113
|
+
showPercentage?: boolean | undefined;
|
|
114
|
+
showValue?: boolean | undefined;
|
|
115
|
+
}>;
|
|
116
|
+
/**
|
|
117
|
+
* Override getJsonSchema to use direct schema generation.
|
|
118
|
+
*/
|
|
119
|
+
getJsonSchema(): object;
|
|
120
|
+
render(input: ProgressInput, context: RenderContext): RenderResult;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Factory function to create a progress component.
|
|
124
|
+
*/
|
|
125
|
+
declare function createProgress(): ProgressComponent;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Characters used for progress bar rendering.
|
|
129
|
+
*/
|
|
130
|
+
interface ProgressChars {
|
|
131
|
+
/** Filled portion character */
|
|
132
|
+
filled: string;
|
|
133
|
+
/** Empty portion character */
|
|
134
|
+
empty: string;
|
|
135
|
+
/** Left bracket (only for bracket style) */
|
|
136
|
+
leftBracket: string;
|
|
137
|
+
/** Right bracket (only for bracket style) */
|
|
138
|
+
rightBracket: string;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Get progress bar characters for a given style.
|
|
142
|
+
*/
|
|
143
|
+
declare function getProgressChars(style: ProgressStyle): ProgressChars;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Pre-computed layout for the progress bar.
|
|
147
|
+
*/
|
|
148
|
+
interface ProgressLayout {
|
|
149
|
+
/** Label to display (empty string if none) */
|
|
150
|
+
label: string;
|
|
151
|
+
/** Filled portion of the bar */
|
|
152
|
+
filledBar: string;
|
|
153
|
+
/** Empty portion of the bar */
|
|
154
|
+
emptyBar: string;
|
|
155
|
+
/** Left bracket (empty for non-bracket styles) */
|
|
156
|
+
leftBracket: string;
|
|
157
|
+
/** Right bracket (empty for non-bracket styles) */
|
|
158
|
+
rightBracket: string;
|
|
159
|
+
/** Percentage (0-100) */
|
|
160
|
+
percentage: number;
|
|
161
|
+
/** Formatted percentage string (e.g., "50%") */
|
|
162
|
+
percentageStr: string;
|
|
163
|
+
/** Formatted value string (e.g., "12/25") */
|
|
164
|
+
valueStr: string;
|
|
165
|
+
/** Number of filled characters */
|
|
166
|
+
filledCount: number;
|
|
167
|
+
/** Number of empty characters */
|
|
168
|
+
emptyCount: number;
|
|
169
|
+
/** Total width of the bar portion */
|
|
170
|
+
barWidth: number;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Compute the layout for a progress bar.
|
|
174
|
+
*
|
|
175
|
+
* @param input - Validated progress input with defaults applied
|
|
176
|
+
* @param chars - Character set to use
|
|
177
|
+
* @returns Computed layout ready for rendering
|
|
178
|
+
*/
|
|
179
|
+
declare function computeProgressLayout(input: ProgressInputWithDefaults, chars: ProgressChars): ProgressLayout;
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Render a progress bar using ANSI escape codes for rich terminal output.
|
|
183
|
+
*
|
|
184
|
+
* @param layout - Pre-computed progress layout
|
|
185
|
+
* @param input - Original input with defaults
|
|
186
|
+
* @param theme - Optional theme for colors
|
|
187
|
+
* @returns ANSI-formatted progress bar string
|
|
188
|
+
*/
|
|
189
|
+
declare function renderProgressAnsi(layout: ProgressLayout, input: ProgressInputWithDefaults, theme?: TuiTheme): string;
|
|
190
|
+
/**
|
|
191
|
+
* Render a progress bar using markdown-friendly output.
|
|
192
|
+
*
|
|
193
|
+
* @param layout - Pre-computed progress layout
|
|
194
|
+
* @param input - Original input with defaults
|
|
195
|
+
* @returns Markdown-friendly progress bar string
|
|
196
|
+
*/
|
|
197
|
+
declare function renderProgressMarkdown(layout: ProgressLayout, input: ProgressInputWithDefaults): string;
|
|
198
|
+
|
|
199
|
+
export { type ProgressChars, ProgressComponent, type ProgressInput, type ProgressInputWithDefaults, type ProgressLayout, type ProgressStyle, computeProgressLayout, createProgress, getProgressChars, progressInputSchema, progressStyleSchema, renderProgressAnsi, renderProgressMarkdown };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import * as zod from 'zod';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { BaseTuiComponent, ComponentMetadata, RenderContext, RenderResult, TuiTheme } from '@tuicomponents/core';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Style options for progress bar characters.
|
|
7
|
+
*/
|
|
8
|
+
declare const progressStyleSchema: z.ZodEnum<["block", "shaded", "bracket", "arrow", "ascii"]>;
|
|
9
|
+
type ProgressStyle = z.infer<typeof progressStyleSchema>;
|
|
10
|
+
/**
|
|
11
|
+
* Schema for progress component input.
|
|
12
|
+
*/
|
|
13
|
+
declare const progressInputSchema: z.ZodObject<{
|
|
14
|
+
/**
|
|
15
|
+
* Current progress value (0 or greater).
|
|
16
|
+
* Required unless indeterminate state is desired.
|
|
17
|
+
*/
|
|
18
|
+
value: z.ZodNumber;
|
|
19
|
+
/**
|
|
20
|
+
* Maximum value (determines 100%).
|
|
21
|
+
* @default 100
|
|
22
|
+
*/
|
|
23
|
+
max: z.ZodDefault<z.ZodNumber>;
|
|
24
|
+
/**
|
|
25
|
+
* Width of the progress bar in characters.
|
|
26
|
+
* @default 20
|
|
27
|
+
*/
|
|
28
|
+
width: z.ZodDefault<z.ZodNumber>;
|
|
29
|
+
/**
|
|
30
|
+
* Style for progress bar characters.
|
|
31
|
+
* @default "block"
|
|
32
|
+
*/
|
|
33
|
+
style: z.ZodDefault<z.ZodEnum<["block", "shaded", "bracket", "arrow", "ascii"]>>;
|
|
34
|
+
/**
|
|
35
|
+
* Custom filled character (overrides style default).
|
|
36
|
+
*/
|
|
37
|
+
filledChar: z.ZodOptional<z.ZodString>;
|
|
38
|
+
/**
|
|
39
|
+
* Custom empty character (overrides style default).
|
|
40
|
+
*/
|
|
41
|
+
emptyChar: z.ZodOptional<z.ZodString>;
|
|
42
|
+
/**
|
|
43
|
+
* Optional label to display before the progress bar.
|
|
44
|
+
*/
|
|
45
|
+
label: z.ZodOptional<z.ZodString>;
|
|
46
|
+
/**
|
|
47
|
+
* Whether to show percentage after the bar.
|
|
48
|
+
* @default true
|
|
49
|
+
*/
|
|
50
|
+
showPercentage: z.ZodDefault<z.ZodBoolean>;
|
|
51
|
+
/**
|
|
52
|
+
* Whether to show the current/max value (e.g., "12/25").
|
|
53
|
+
* @default false
|
|
54
|
+
*/
|
|
55
|
+
showValue: z.ZodDefault<z.ZodBoolean>;
|
|
56
|
+
}, "strip", z.ZodTypeAny, {
|
|
57
|
+
value: number;
|
|
58
|
+
max: number;
|
|
59
|
+
width: number;
|
|
60
|
+
style: "block" | "shaded" | "bracket" | "arrow" | "ascii";
|
|
61
|
+
showPercentage: boolean;
|
|
62
|
+
showValue: boolean;
|
|
63
|
+
filledChar?: string | undefined;
|
|
64
|
+
emptyChar?: string | undefined;
|
|
65
|
+
label?: string | undefined;
|
|
66
|
+
}, {
|
|
67
|
+
value: number;
|
|
68
|
+
max?: number | undefined;
|
|
69
|
+
width?: number | undefined;
|
|
70
|
+
style?: "block" | "shaded" | "bracket" | "arrow" | "ascii" | undefined;
|
|
71
|
+
filledChar?: string | undefined;
|
|
72
|
+
emptyChar?: string | undefined;
|
|
73
|
+
label?: string | undefined;
|
|
74
|
+
showPercentage?: boolean | undefined;
|
|
75
|
+
showValue?: boolean | undefined;
|
|
76
|
+
}>;
|
|
77
|
+
type ProgressInput = z.input<typeof progressInputSchema>;
|
|
78
|
+
type ProgressInputWithDefaults = z.output<typeof progressInputSchema>;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Progress component for rendering horizontal progress bars.
|
|
82
|
+
*/
|
|
83
|
+
declare class ProgressComponent extends BaseTuiComponent<ProgressInput, typeof progressInputSchema> {
|
|
84
|
+
readonly metadata: ComponentMetadata<ProgressInput>;
|
|
85
|
+
readonly schema: zod.ZodObject<{
|
|
86
|
+
value: zod.ZodNumber;
|
|
87
|
+
max: zod.ZodDefault<zod.ZodNumber>;
|
|
88
|
+
width: zod.ZodDefault<zod.ZodNumber>;
|
|
89
|
+
style: zod.ZodDefault<zod.ZodEnum<["block", "shaded", "bracket", "arrow", "ascii"]>>;
|
|
90
|
+
filledChar: zod.ZodOptional<zod.ZodString>;
|
|
91
|
+
emptyChar: zod.ZodOptional<zod.ZodString>;
|
|
92
|
+
label: zod.ZodOptional<zod.ZodString>;
|
|
93
|
+
showPercentage: zod.ZodDefault<zod.ZodBoolean>;
|
|
94
|
+
showValue: zod.ZodDefault<zod.ZodBoolean>;
|
|
95
|
+
}, "strip", zod.ZodTypeAny, {
|
|
96
|
+
value: number;
|
|
97
|
+
max: number;
|
|
98
|
+
width: number;
|
|
99
|
+
style: "block" | "shaded" | "bracket" | "arrow" | "ascii";
|
|
100
|
+
showPercentage: boolean;
|
|
101
|
+
showValue: boolean;
|
|
102
|
+
filledChar?: string | undefined;
|
|
103
|
+
emptyChar?: string | undefined;
|
|
104
|
+
label?: string | undefined;
|
|
105
|
+
}, {
|
|
106
|
+
value: number;
|
|
107
|
+
max?: number | undefined;
|
|
108
|
+
width?: number | undefined;
|
|
109
|
+
style?: "block" | "shaded" | "bracket" | "arrow" | "ascii" | undefined;
|
|
110
|
+
filledChar?: string | undefined;
|
|
111
|
+
emptyChar?: string | undefined;
|
|
112
|
+
label?: string | undefined;
|
|
113
|
+
showPercentage?: boolean | undefined;
|
|
114
|
+
showValue?: boolean | undefined;
|
|
115
|
+
}>;
|
|
116
|
+
/**
|
|
117
|
+
* Override getJsonSchema to use direct schema generation.
|
|
118
|
+
*/
|
|
119
|
+
getJsonSchema(): object;
|
|
120
|
+
render(input: ProgressInput, context: RenderContext): RenderResult;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Factory function to create a progress component.
|
|
124
|
+
*/
|
|
125
|
+
declare function createProgress(): ProgressComponent;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Characters used for progress bar rendering.
|
|
129
|
+
*/
|
|
130
|
+
interface ProgressChars {
|
|
131
|
+
/** Filled portion character */
|
|
132
|
+
filled: string;
|
|
133
|
+
/** Empty portion character */
|
|
134
|
+
empty: string;
|
|
135
|
+
/** Left bracket (only for bracket style) */
|
|
136
|
+
leftBracket: string;
|
|
137
|
+
/** Right bracket (only for bracket style) */
|
|
138
|
+
rightBracket: string;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Get progress bar characters for a given style.
|
|
142
|
+
*/
|
|
143
|
+
declare function getProgressChars(style: ProgressStyle): ProgressChars;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Pre-computed layout for the progress bar.
|
|
147
|
+
*/
|
|
148
|
+
interface ProgressLayout {
|
|
149
|
+
/** Label to display (empty string if none) */
|
|
150
|
+
label: string;
|
|
151
|
+
/** Filled portion of the bar */
|
|
152
|
+
filledBar: string;
|
|
153
|
+
/** Empty portion of the bar */
|
|
154
|
+
emptyBar: string;
|
|
155
|
+
/** Left bracket (empty for non-bracket styles) */
|
|
156
|
+
leftBracket: string;
|
|
157
|
+
/** Right bracket (empty for non-bracket styles) */
|
|
158
|
+
rightBracket: string;
|
|
159
|
+
/** Percentage (0-100) */
|
|
160
|
+
percentage: number;
|
|
161
|
+
/** Formatted percentage string (e.g., "50%") */
|
|
162
|
+
percentageStr: string;
|
|
163
|
+
/** Formatted value string (e.g., "12/25") */
|
|
164
|
+
valueStr: string;
|
|
165
|
+
/** Number of filled characters */
|
|
166
|
+
filledCount: number;
|
|
167
|
+
/** Number of empty characters */
|
|
168
|
+
emptyCount: number;
|
|
169
|
+
/** Total width of the bar portion */
|
|
170
|
+
barWidth: number;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Compute the layout for a progress bar.
|
|
174
|
+
*
|
|
175
|
+
* @param input - Validated progress input with defaults applied
|
|
176
|
+
* @param chars - Character set to use
|
|
177
|
+
* @returns Computed layout ready for rendering
|
|
178
|
+
*/
|
|
179
|
+
declare function computeProgressLayout(input: ProgressInputWithDefaults, chars: ProgressChars): ProgressLayout;
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Render a progress bar using ANSI escape codes for rich terminal output.
|
|
183
|
+
*
|
|
184
|
+
* @param layout - Pre-computed progress layout
|
|
185
|
+
* @param input - Original input with defaults
|
|
186
|
+
* @param theme - Optional theme for colors
|
|
187
|
+
* @returns ANSI-formatted progress bar string
|
|
188
|
+
*/
|
|
189
|
+
declare function renderProgressAnsi(layout: ProgressLayout, input: ProgressInputWithDefaults, theme?: TuiTheme): string;
|
|
190
|
+
/**
|
|
191
|
+
* Render a progress bar using markdown-friendly output.
|
|
192
|
+
*
|
|
193
|
+
* @param layout - Pre-computed progress layout
|
|
194
|
+
* @param input - Original input with defaults
|
|
195
|
+
* @returns Markdown-friendly progress bar string
|
|
196
|
+
*/
|
|
197
|
+
declare function renderProgressMarkdown(layout: ProgressLayout, input: ProgressInputWithDefaults): string;
|
|
198
|
+
|
|
199
|
+
export { type ProgressChars, ProgressComponent, type ProgressInput, type ProgressInputWithDefaults, type ProgressLayout, type ProgressStyle, computeProgressLayout, createProgress, getProgressChars, progressInputSchema, progressStyleSchema, renderProgressAnsi, renderProgressMarkdown };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
// src/progress.ts
|
|
2
|
+
import {
|
|
3
|
+
BaseTuiComponent,
|
|
4
|
+
measureLines,
|
|
5
|
+
registry
|
|
6
|
+
} from "@tuicomponents/core";
|
|
7
|
+
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
8
|
+
|
|
9
|
+
// src/schema.ts
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
var progressStyleSchema = z.enum([
|
|
12
|
+
"block",
|
|
13
|
+
"shaded",
|
|
14
|
+
"bracket",
|
|
15
|
+
"arrow",
|
|
16
|
+
"ascii"
|
|
17
|
+
]);
|
|
18
|
+
var progressInputSchema = z.object({
|
|
19
|
+
/**
|
|
20
|
+
* Current progress value (0 or greater).
|
|
21
|
+
* Required unless indeterminate state is desired.
|
|
22
|
+
*/
|
|
23
|
+
value: z.number().nonnegative(),
|
|
24
|
+
/**
|
|
25
|
+
* Maximum value (determines 100%).
|
|
26
|
+
* @default 100
|
|
27
|
+
*/
|
|
28
|
+
max: z.number().positive().default(100),
|
|
29
|
+
/**
|
|
30
|
+
* Width of the progress bar in characters.
|
|
31
|
+
* @default 20
|
|
32
|
+
*/
|
|
33
|
+
width: z.number().int().positive().default(20),
|
|
34
|
+
/**
|
|
35
|
+
* Style for progress bar characters.
|
|
36
|
+
* @default "block"
|
|
37
|
+
*/
|
|
38
|
+
style: progressStyleSchema.default("block"),
|
|
39
|
+
/**
|
|
40
|
+
* Custom filled character (overrides style default).
|
|
41
|
+
*/
|
|
42
|
+
filledChar: z.string().length(1).optional(),
|
|
43
|
+
/**
|
|
44
|
+
* Custom empty character (overrides style default).
|
|
45
|
+
*/
|
|
46
|
+
emptyChar: z.string().length(1).optional(),
|
|
47
|
+
/**
|
|
48
|
+
* Optional label to display before the progress bar.
|
|
49
|
+
*/
|
|
50
|
+
label: z.string().optional(),
|
|
51
|
+
/**
|
|
52
|
+
* Whether to show percentage after the bar.
|
|
53
|
+
* @default true
|
|
54
|
+
*/
|
|
55
|
+
showPercentage: z.boolean().default(true),
|
|
56
|
+
/**
|
|
57
|
+
* Whether to show the current/max value (e.g., "12/25").
|
|
58
|
+
* @default false
|
|
59
|
+
*/
|
|
60
|
+
showValue: z.boolean().default(false)
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// src/chars.ts
|
|
64
|
+
var blockChars = {
|
|
65
|
+
filled: "\u2588",
|
|
66
|
+
empty: "\u2591",
|
|
67
|
+
leftBracket: "",
|
|
68
|
+
rightBracket: ""
|
|
69
|
+
};
|
|
70
|
+
var shadedChars = {
|
|
71
|
+
filled: "\u2593",
|
|
72
|
+
empty: "\u2591",
|
|
73
|
+
leftBracket: "",
|
|
74
|
+
rightBracket: ""
|
|
75
|
+
};
|
|
76
|
+
var bracketChars = {
|
|
77
|
+
filled: "\u2588",
|
|
78
|
+
empty: "\u2591",
|
|
79
|
+
leftBracket: "[",
|
|
80
|
+
rightBracket: "]"
|
|
81
|
+
};
|
|
82
|
+
var arrowChars = {
|
|
83
|
+
filled: ">",
|
|
84
|
+
empty: "-",
|
|
85
|
+
leftBracket: "",
|
|
86
|
+
rightBracket: ""
|
|
87
|
+
};
|
|
88
|
+
var asciiChars = {
|
|
89
|
+
filled: "#",
|
|
90
|
+
empty: ".",
|
|
91
|
+
leftBracket: "",
|
|
92
|
+
rightBracket: ""
|
|
93
|
+
};
|
|
94
|
+
function getProgressChars(style) {
|
|
95
|
+
switch (style) {
|
|
96
|
+
case "block":
|
|
97
|
+
return blockChars;
|
|
98
|
+
case "shaded":
|
|
99
|
+
return shadedChars;
|
|
100
|
+
case "bracket":
|
|
101
|
+
return bracketChars;
|
|
102
|
+
case "arrow":
|
|
103
|
+
return arrowChars;
|
|
104
|
+
case "ascii":
|
|
105
|
+
return asciiChars;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// src/layout.ts
|
|
110
|
+
function computeProgressLayout(input, chars) {
|
|
111
|
+
const rawPercentage = input.max > 0 ? input.value / input.max * 100 : 0;
|
|
112
|
+
const percentage = Math.min(100, Math.max(0, rawPercentage));
|
|
113
|
+
const barWidth = input.width;
|
|
114
|
+
const filledCount = Math.round(percentage / 100 * barWidth);
|
|
115
|
+
const emptyCount = barWidth - filledCount;
|
|
116
|
+
const filledChar = input.filledChar ?? chars.filled;
|
|
117
|
+
const emptyChar = input.emptyChar ?? chars.empty;
|
|
118
|
+
const filledBar = filledChar.repeat(filledCount);
|
|
119
|
+
const emptyBar = emptyChar.repeat(emptyCount);
|
|
120
|
+
const percentageStr = `${String(Math.round(percentage))}%`;
|
|
121
|
+
const valueStr = `${String(input.value)}/${String(input.max)}`;
|
|
122
|
+
return {
|
|
123
|
+
label: input.label ?? "",
|
|
124
|
+
filledBar,
|
|
125
|
+
emptyBar,
|
|
126
|
+
leftBracket: chars.leftBracket,
|
|
127
|
+
rightBracket: chars.rightBracket,
|
|
128
|
+
percentage,
|
|
129
|
+
percentageStr,
|
|
130
|
+
valueStr,
|
|
131
|
+
filledCount,
|
|
132
|
+
emptyCount,
|
|
133
|
+
barWidth
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// src/renderers.ts
|
|
138
|
+
import { anchorLine, DEFAULT_ANCHOR } from "@tuicomponents/core";
|
|
139
|
+
function renderProgressAnsi(layout, input, theme) {
|
|
140
|
+
const parts = [];
|
|
141
|
+
if (layout.label) {
|
|
142
|
+
const coloredLabel = theme ? theme.semantic.header(layout.label) : layout.label;
|
|
143
|
+
parts.push(coloredLabel);
|
|
144
|
+
parts.push(" ");
|
|
145
|
+
}
|
|
146
|
+
if (layout.leftBracket) {
|
|
147
|
+
const coloredBracket = theme ? theme.semantic.border(layout.leftBracket) : layout.leftBracket;
|
|
148
|
+
parts.push(coloredBracket);
|
|
149
|
+
}
|
|
150
|
+
const coloredFilled = theme ? theme.semantic.primary(layout.filledBar) : layout.filledBar;
|
|
151
|
+
const coloredEmpty = theme ? theme.semantic.secondary(layout.emptyBar) : layout.emptyBar;
|
|
152
|
+
parts.push(coloredFilled);
|
|
153
|
+
parts.push(coloredEmpty);
|
|
154
|
+
if (layout.rightBracket) {
|
|
155
|
+
const coloredBracket = theme ? theme.semantic.border(layout.rightBracket) : layout.rightBracket;
|
|
156
|
+
parts.push(coloredBracket);
|
|
157
|
+
}
|
|
158
|
+
const suffix = buildSuffix(layout, input, theme);
|
|
159
|
+
if (suffix) {
|
|
160
|
+
parts.push(" ");
|
|
161
|
+
parts.push(suffix);
|
|
162
|
+
}
|
|
163
|
+
return parts.join("");
|
|
164
|
+
}
|
|
165
|
+
function renderProgressMarkdown(layout, input) {
|
|
166
|
+
const parts = [];
|
|
167
|
+
if (layout.label) {
|
|
168
|
+
parts.push(layout.label);
|
|
169
|
+
parts.push(" ");
|
|
170
|
+
}
|
|
171
|
+
if (layout.leftBracket) {
|
|
172
|
+
parts.push(layout.leftBracket);
|
|
173
|
+
}
|
|
174
|
+
parts.push(layout.filledBar);
|
|
175
|
+
parts.push(layout.emptyBar);
|
|
176
|
+
if (layout.rightBracket) {
|
|
177
|
+
parts.push(layout.rightBracket);
|
|
178
|
+
}
|
|
179
|
+
const suffix = buildSuffix(layout, input);
|
|
180
|
+
if (suffix) {
|
|
181
|
+
parts.push(" ");
|
|
182
|
+
parts.push(suffix);
|
|
183
|
+
}
|
|
184
|
+
return anchorLine(parts.join(""), DEFAULT_ANCHOR);
|
|
185
|
+
}
|
|
186
|
+
function buildSuffix(layout, input, theme) {
|
|
187
|
+
const suffixParts = [];
|
|
188
|
+
if (input.showPercentage) {
|
|
189
|
+
suffixParts.push(layout.percentageStr);
|
|
190
|
+
}
|
|
191
|
+
if (input.showValue) {
|
|
192
|
+
suffixParts.push(layout.valueStr);
|
|
193
|
+
}
|
|
194
|
+
if (suffixParts.length === 0) {
|
|
195
|
+
return "";
|
|
196
|
+
}
|
|
197
|
+
const suffix = suffixParts.join(" ");
|
|
198
|
+
return theme ? theme.semantic.secondary(suffix) : suffix;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// src/progress.ts
|
|
202
|
+
var ProgressComponent = class extends BaseTuiComponent {
|
|
203
|
+
metadata = {
|
|
204
|
+
name: "progress",
|
|
205
|
+
description: "Renders horizontal progress bars for task completion",
|
|
206
|
+
version: "0.1.0",
|
|
207
|
+
supportedModes: ["ansi", "markdown"],
|
|
208
|
+
examples: [
|
|
209
|
+
{
|
|
210
|
+
name: "basic",
|
|
211
|
+
description: "Simple progress bar at 50%",
|
|
212
|
+
input: {
|
|
213
|
+
value: 50,
|
|
214
|
+
max: 100
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
name: "with-label",
|
|
219
|
+
description: "Progress bar with label",
|
|
220
|
+
input: {
|
|
221
|
+
value: 75,
|
|
222
|
+
max: 100,
|
|
223
|
+
label: "Loading:"
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
name: "block-style",
|
|
228
|
+
description: "Block style progress bar",
|
|
229
|
+
input: {
|
|
230
|
+
value: 60,
|
|
231
|
+
max: 100,
|
|
232
|
+
style: "block",
|
|
233
|
+
label: "Progress"
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
name: "shaded-style",
|
|
238
|
+
description: "Shaded style progress bar",
|
|
239
|
+
input: {
|
|
240
|
+
value: 40,
|
|
241
|
+
max: 100,
|
|
242
|
+
style: "shaded"
|
|
243
|
+
}
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
name: "bracket-style",
|
|
247
|
+
description: "Bracket style progress bar",
|
|
248
|
+
input: {
|
|
249
|
+
value: 80,
|
|
250
|
+
max: 100,
|
|
251
|
+
style: "bracket"
|
|
252
|
+
}
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
name: "arrow-style",
|
|
256
|
+
description: "Arrow style progress bar",
|
|
257
|
+
input: {
|
|
258
|
+
value: 65,
|
|
259
|
+
max: 100,
|
|
260
|
+
style: "arrow"
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
name: "ascii-style",
|
|
265
|
+
description: "ASCII style progress bar",
|
|
266
|
+
input: {
|
|
267
|
+
value: 50,
|
|
268
|
+
max: 100,
|
|
269
|
+
style: "ascii"
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
name: "with-value",
|
|
274
|
+
description: "Progress bar showing current/max value",
|
|
275
|
+
input: {
|
|
276
|
+
value: 12,
|
|
277
|
+
max: 25,
|
|
278
|
+
label: "Downloads",
|
|
279
|
+
showValue: true
|
|
280
|
+
}
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
name: "complete",
|
|
284
|
+
description: "100% complete progress bar",
|
|
285
|
+
input: {
|
|
286
|
+
value: 100,
|
|
287
|
+
max: 100,
|
|
288
|
+
style: "bracket"
|
|
289
|
+
}
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
name: "custom-width",
|
|
293
|
+
description: "Wide progress bar",
|
|
294
|
+
input: {
|
|
295
|
+
value: 45,
|
|
296
|
+
max: 100,
|
|
297
|
+
width: 40,
|
|
298
|
+
label: "Processing:"
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
]
|
|
302
|
+
};
|
|
303
|
+
schema = progressInputSchema;
|
|
304
|
+
/**
|
|
305
|
+
* Override getJsonSchema to use direct schema generation.
|
|
306
|
+
*/
|
|
307
|
+
getJsonSchema() {
|
|
308
|
+
return zodToJsonSchema(this.schema, {
|
|
309
|
+
name: this.metadata.name,
|
|
310
|
+
$refStrategy: "none"
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
render(input, context) {
|
|
314
|
+
const parsed = this.schema.parse(input);
|
|
315
|
+
const chars = getProgressChars(parsed.style);
|
|
316
|
+
const layout = computeProgressLayout(parsed, chars);
|
|
317
|
+
const output = context.renderMode === "markdown" ? renderProgressMarkdown(layout, parsed) : renderProgressAnsi(layout, parsed, context.theme);
|
|
318
|
+
const measured = measureLines(output);
|
|
319
|
+
return {
|
|
320
|
+
output,
|
|
321
|
+
actualWidth: measured.maxWidth,
|
|
322
|
+
lineCount: measured.lineCount
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
function createProgress() {
|
|
327
|
+
return new ProgressComponent();
|
|
328
|
+
}
|
|
329
|
+
registry.register(createProgress);
|
|
330
|
+
export {
|
|
331
|
+
ProgressComponent,
|
|
332
|
+
computeProgressLayout,
|
|
333
|
+
createProgress,
|
|
334
|
+
getProgressChars,
|
|
335
|
+
progressInputSchema,
|
|
336
|
+
progressStyleSchema,
|
|
337
|
+
renderProgressAnsi,
|
|
338
|
+
renderProgressMarkdown
|
|
339
|
+
};
|
|
340
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/progress.ts","../src/schema.ts","../src/chars.ts","../src/layout.ts","../src/renderers.ts"],"sourcesContent":["import {\n BaseTuiComponent,\n type ComponentMetadata,\n type RenderContext,\n type RenderResult,\n measureLines,\n registry,\n} from \"@tuicomponents/core\";\nimport { zodToJsonSchema } from \"zod-to-json-schema\";\nimport { progressInputSchema, type ProgressInput } from \"./schema.js\";\nimport { getProgressChars } from \"./chars.js\";\nimport { computeProgressLayout } from \"./layout.js\";\nimport { renderProgressAnsi, renderProgressMarkdown } from \"./renderers.js\";\n\n/**\n * Progress component for rendering horizontal progress bars.\n */\nclass ProgressComponent extends BaseTuiComponent<\n ProgressInput,\n typeof progressInputSchema\n> {\n readonly metadata: ComponentMetadata<ProgressInput> = {\n name: \"progress\",\n description: \"Renders horizontal progress bars for task completion\",\n version: \"0.1.0\",\n supportedModes: [\"ansi\", \"markdown\"],\n examples: [\n {\n name: \"basic\",\n description: \"Simple progress bar at 50%\",\n input: {\n value: 50,\n max: 100,\n },\n },\n {\n name: \"with-label\",\n description: \"Progress bar with label\",\n input: {\n value: 75,\n max: 100,\n label: \"Loading:\",\n },\n },\n {\n name: \"block-style\",\n description: \"Block style progress bar\",\n input: {\n value: 60,\n max: 100,\n style: \"block\",\n label: \"Progress\",\n },\n },\n {\n name: \"shaded-style\",\n description: \"Shaded style progress bar\",\n input: {\n value: 40,\n max: 100,\n style: \"shaded\",\n },\n },\n {\n name: \"bracket-style\",\n description: \"Bracket style progress bar\",\n input: {\n value: 80,\n max: 100,\n style: \"bracket\",\n },\n },\n {\n name: \"arrow-style\",\n description: \"Arrow style progress bar\",\n input: {\n value: 65,\n max: 100,\n style: \"arrow\",\n },\n },\n {\n name: \"ascii-style\",\n description: \"ASCII style progress bar\",\n input: {\n value: 50,\n max: 100,\n style: \"ascii\",\n },\n },\n {\n name: \"with-value\",\n description: \"Progress bar showing current/max value\",\n input: {\n value: 12,\n max: 25,\n label: \"Downloads\",\n showValue: true,\n },\n },\n {\n name: \"complete\",\n description: \"100% complete progress bar\",\n input: {\n value: 100,\n max: 100,\n style: \"bracket\",\n },\n },\n {\n name: \"custom-width\",\n description: \"Wide progress bar\",\n input: {\n value: 45,\n max: 100,\n width: 40,\n label: \"Processing:\",\n },\n },\n ],\n };\n\n readonly schema = progressInputSchema;\n\n /**\n * Override getJsonSchema to use direct schema generation.\n */\n override getJsonSchema(): object {\n return zodToJsonSchema(this.schema, {\n name: this.metadata.name,\n $refStrategy: \"none\",\n });\n }\n\n render(input: ProgressInput, context: RenderContext): RenderResult {\n const parsed = this.schema.parse(input);\n\n // Get character set based on style\n const chars = getProgressChars(parsed.style);\n\n // Compute layout once, share between renderers\n const layout = computeProgressLayout(parsed, chars);\n\n // Choose renderer based on render mode\n const output =\n context.renderMode === \"markdown\"\n ? renderProgressMarkdown(layout, parsed)\n : renderProgressAnsi(layout, parsed, context.theme);\n\n const measured = measureLines(output);\n\n return {\n output,\n actualWidth: measured.maxWidth,\n lineCount: measured.lineCount,\n };\n }\n}\n\n/**\n * Factory function to create a progress component.\n */\nexport function createProgress(): ProgressComponent {\n return new ProgressComponent();\n}\n\n// Register with global registry\nregistry.register(createProgress);\n\nexport { ProgressComponent };\n","import { z } from \"zod\";\n\n/**\n * Style options for progress bar characters.\n */\nexport const progressStyleSchema = z.enum([\n \"block\",\n \"shaded\",\n \"bracket\",\n \"arrow\",\n \"ascii\",\n]);\n\nexport type ProgressStyle = z.infer<typeof progressStyleSchema>;\n\n/**\n * Schema for progress component input.\n */\nexport const progressInputSchema = z.object({\n /**\n * Current progress value (0 or greater).\n * Required unless indeterminate state is desired.\n */\n value: z.number().nonnegative(),\n\n /**\n * Maximum value (determines 100%).\n * @default 100\n */\n max: z.number().positive().default(100),\n\n /**\n * Width of the progress bar in characters.\n * @default 20\n */\n width: z.number().int().positive().default(20),\n\n /**\n * Style for progress bar characters.\n * @default \"block\"\n */\n style: progressStyleSchema.default(\"block\"),\n\n /**\n * Custom filled character (overrides style default).\n */\n filledChar: z.string().length(1).optional(),\n\n /**\n * Custom empty character (overrides style default).\n */\n emptyChar: z.string().length(1).optional(),\n\n /**\n * Optional label to display before the progress bar.\n */\n label: z.string().optional(),\n\n /**\n * Whether to show percentage after the bar.\n * @default true\n */\n showPercentage: z.boolean().default(true),\n\n /**\n * Whether to show the current/max value (e.g., \"12/25\").\n * @default false\n */\n showValue: z.boolean().default(false),\n});\n\nexport type ProgressInput = z.input<typeof progressInputSchema>;\nexport type ProgressInputWithDefaults = z.output<typeof progressInputSchema>;\n","import type { ProgressStyle } from \"./schema.js\";\n\n/**\n * Characters used for progress bar rendering.\n */\nexport interface ProgressChars {\n /** Filled portion character */\n filled: string;\n /** Empty portion character */\n empty: string;\n /** Left bracket (only for bracket style) */\n leftBracket: string;\n /** Right bracket (only for bracket style) */\n rightBracket: string;\n}\n\n/**\n * Block style: █░\n */\nconst blockChars: ProgressChars = {\n filled: \"█\",\n empty: \"░\",\n leftBracket: \"\",\n rightBracket: \"\",\n};\n\n/**\n * Shaded style: ▓░\n */\nconst shadedChars: ProgressChars = {\n filled: \"▓\",\n empty: \"░\",\n leftBracket: \"\",\n rightBracket: \"\",\n};\n\n/**\n * Bracket style: [█░]\n */\nconst bracketChars: ProgressChars = {\n filled: \"█\",\n empty: \"░\",\n leftBracket: \"[\",\n rightBracket: \"]\",\n};\n\n/**\n * Arrow style: >-\n */\nconst arrowChars: ProgressChars = {\n filled: \">\",\n empty: \"-\",\n leftBracket: \"\",\n rightBracket: \"\",\n};\n\n/**\n * ASCII style: #.\n */\nconst asciiChars: ProgressChars = {\n filled: \"#\",\n empty: \".\",\n leftBracket: \"\",\n rightBracket: \"\",\n};\n\n/**\n * Get progress bar characters for a given style.\n */\nexport function getProgressChars(style: ProgressStyle): ProgressChars {\n switch (style) {\n case \"block\":\n return blockChars;\n case \"shaded\":\n return shadedChars;\n case \"bracket\":\n return bracketChars;\n case \"arrow\":\n return arrowChars;\n case \"ascii\":\n return asciiChars;\n }\n}\n","import type { ProgressInputWithDefaults } from \"./schema.js\";\nimport type { ProgressChars } from \"./chars.js\";\n\n/**\n * Pre-computed layout for the progress bar.\n */\nexport interface ProgressLayout {\n /** Label to display (empty string if none) */\n label: string;\n /** Filled portion of the bar */\n filledBar: string;\n /** Empty portion of the bar */\n emptyBar: string;\n /** Left bracket (empty for non-bracket styles) */\n leftBracket: string;\n /** Right bracket (empty for non-bracket styles) */\n rightBracket: string;\n /** Percentage (0-100) */\n percentage: number;\n /** Formatted percentage string (e.g., \"50%\") */\n percentageStr: string;\n /** Formatted value string (e.g., \"12/25\") */\n valueStr: string;\n /** Number of filled characters */\n filledCount: number;\n /** Number of empty characters */\n emptyCount: number;\n /** Total width of the bar portion */\n barWidth: number;\n}\n\n/**\n * Compute the layout for a progress bar.\n *\n * @param input - Validated progress input with defaults applied\n * @param chars - Character set to use\n * @returns Computed layout ready for rendering\n */\nexport function computeProgressLayout(\n input: ProgressInputWithDefaults,\n chars: ProgressChars\n): ProgressLayout {\n // Calculate percentage (clamped to 0-100)\n const rawPercentage = input.max > 0 ? (input.value / input.max) * 100 : 0;\n const percentage = Math.min(100, Math.max(0, rawPercentage));\n\n // Determine actual bar width (accounting for brackets if present)\n const barWidth = input.width;\n\n // Calculate filled/empty character counts\n const filledCount = Math.round((percentage / 100) * barWidth);\n const emptyCount = barWidth - filledCount;\n\n // Get effective characters (allow override)\n const filledChar = input.filledChar ?? chars.filled;\n const emptyChar = input.emptyChar ?? chars.empty;\n\n // Build bar strings\n const filledBar = filledChar.repeat(filledCount);\n const emptyBar = emptyChar.repeat(emptyCount);\n\n // Format percentage\n const percentageStr = `${String(Math.round(percentage))}%`;\n\n // Format value\n const valueStr = `${String(input.value)}/${String(input.max)}`;\n\n return {\n label: input.label ?? \"\",\n filledBar,\n emptyBar,\n leftBracket: chars.leftBracket,\n rightBracket: chars.rightBracket,\n percentage,\n percentageStr,\n valueStr,\n filledCount,\n emptyCount,\n barWidth,\n };\n}\n","import { type TuiTheme, anchorLine, DEFAULT_ANCHOR } from \"@tuicomponents/core\";\nimport type { ProgressLayout } from \"./layout.js\";\nimport type { ProgressInputWithDefaults } from \"./schema.js\";\n\n/**\n * Render a progress bar using ANSI escape codes for rich terminal output.\n *\n * @param layout - Pre-computed progress layout\n * @param input - Original input with defaults\n * @param theme - Optional theme for colors\n * @returns ANSI-formatted progress bar string\n */\nexport function renderProgressAnsi(\n layout: ProgressLayout,\n input: ProgressInputWithDefaults,\n theme?: TuiTheme\n): string {\n const parts: string[] = [];\n\n // Add label if present\n if (layout.label) {\n const coloredLabel = theme\n ? theme.semantic.header(layout.label)\n : layout.label;\n parts.push(coloredLabel);\n parts.push(\" \");\n }\n\n // Add left bracket\n if (layout.leftBracket) {\n const coloredBracket = theme\n ? theme.semantic.border(layout.leftBracket)\n : layout.leftBracket;\n parts.push(coloredBracket);\n }\n\n // Add bar\n const coloredFilled = theme\n ? theme.semantic.primary(layout.filledBar)\n : layout.filledBar;\n const coloredEmpty = theme\n ? theme.semantic.secondary(layout.emptyBar)\n : layout.emptyBar;\n parts.push(coloredFilled);\n parts.push(coloredEmpty);\n\n // Add right bracket\n if (layout.rightBracket) {\n const coloredBracket = theme\n ? theme.semantic.border(layout.rightBracket)\n : layout.rightBracket;\n parts.push(coloredBracket);\n }\n\n // Add percentage and/or value\n const suffix = buildSuffix(layout, input, theme);\n if (suffix) {\n parts.push(\" \");\n parts.push(suffix);\n }\n\n return parts.join(\"\");\n}\n\n/**\n * Render a progress bar using markdown-friendly output.\n *\n * @param layout - Pre-computed progress layout\n * @param input - Original input with defaults\n * @returns Markdown-friendly progress bar string\n */\nexport function renderProgressMarkdown(\n layout: ProgressLayout,\n input: ProgressInputWithDefaults\n): string {\n const parts: string[] = [];\n\n // Add label if present\n if (layout.label) {\n parts.push(layout.label);\n parts.push(\" \");\n }\n\n // Add left bracket\n if (layout.leftBracket) {\n parts.push(layout.leftBracket);\n }\n\n // Add bar\n parts.push(layout.filledBar);\n parts.push(layout.emptyBar);\n\n // Add right bracket\n if (layout.rightBracket) {\n parts.push(layout.rightBracket);\n }\n\n // Add percentage and/or value\n const suffix = buildSuffix(layout, input);\n if (suffix) {\n parts.push(\" \");\n parts.push(suffix);\n }\n\n return anchorLine(parts.join(\"\"), DEFAULT_ANCHOR);\n}\n\n/**\n * Build the suffix string (percentage and/or value).\n */\nfunction buildSuffix(\n layout: ProgressLayout,\n input: ProgressInputWithDefaults,\n theme?: TuiTheme\n): string {\n const suffixParts: string[] = [];\n\n if (input.showPercentage) {\n suffixParts.push(layout.percentageStr);\n }\n\n if (input.showValue) {\n suffixParts.push(layout.valueStr);\n }\n\n if (suffixParts.length === 0) {\n return \"\";\n }\n\n const suffix = suffixParts.join(\" \");\n return theme ? theme.semantic.secondary(suffix) : suffix;\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EAIA;AAAA,EACA;AAAA,OACK;AACP,SAAS,uBAAuB;;;ACRhC,SAAS,SAAS;AAKX,IAAM,sBAAsB,EAAE,KAAK;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAOM,IAAM,sBAAsB,EAAE,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA,EAK1C,OAAO,EAAE,OAAO,EAAE,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA,EAM9B,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,GAAG;AAAA;AAAA;AAAA;AAAA;AAAA,EAMtC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE;AAAA;AAAA;AAAA;AAAA;AAAA,EAM7C,OAAO,oBAAoB,QAAQ,OAAO;AAAA;AAAA;AAAA;AAAA,EAK1C,YAAY,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,SAAS;AAAA;AAAA;AAAA;AAAA,EAK1C,WAAW,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,SAAS;AAAA;AAAA;AAAA;AAAA,EAKzC,OAAO,EAAE,OAAO,EAAE,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA,EAM3B,gBAAgB,EAAE,QAAQ,EAAE,QAAQ,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA,EAMxC,WAAW,EAAE,QAAQ,EAAE,QAAQ,KAAK;AACtC,CAAC;;;AClDD,IAAM,aAA4B;AAAA,EAChC,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,aAAa;A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AAGlD,UAAM,SACJ,QAAQ,eAAe,aACnB,uBAAuB,QAAQ,MAAM,IACrC,mBAAmB,QAAQ,QAAQ,QAAQ,KAAK;AAEtD,UAAM,WAAW,aAAa,MAAM;AAEpC,WAAO;AAAA,MACL;AAAA,MACA,aAAa,SAAS;AAAA,MACtB,WAAW,SAAS;AAAA,IACtB;AAAA,EACF;AACF;AAKO,SAAS,iBAAoC;AAClD,SAAO,IAAI,kBAAkB;AAC/B;AAGA,SAAS,SAAS,cAAc;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tuicomponents/progress",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Horizontal progress bar component for TUI",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"keywords": [
|
|
25
|
+
"tui",
|
|
26
|
+
"terminal",
|
|
27
|
+
"progress",
|
|
28
|
+
"progress-bar",
|
|
29
|
+
"visualization"
|
|
30
|
+
],
|
|
31
|
+
"license": "UNLICENSED",
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"zod": "^3.25.56",
|
|
34
|
+
"zod-to-json-schema": "^3.24.5",
|
|
35
|
+
"@tuicomponents/core": "0.1.1"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/node": "^22.0.0"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "tsup",
|
|
42
|
+
"typecheck": "tsc --noEmit",
|
|
43
|
+
"lint": "eslint src",
|
|
44
|
+
"test": "vitest run",
|
|
45
|
+
"test:watch": "vitest",
|
|
46
|
+
"api-report": "api-extractor run",
|
|
47
|
+
"api-report:update": "api-extractor run --local",
|
|
48
|
+
"clean": "rm -rf dist"
|
|
49
|
+
}
|
|
50
|
+
}
|