blessed-components 0.0.1 → 1.0.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/README.md +16 -43
- package/ROADMAP.md +695 -302
- package/dist/index.cjs +57 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +51 -0
- package/dist/index.js.map +1 -1
- package/dist/progress-bar/blessed.cjs +60 -0
- package/dist/progress-bar/blessed.cjs.map +1 -0
- package/dist/progress-bar/blessed.d.cts +129 -0
- package/dist/progress-bar/blessed.d.ts +129 -0
- package/dist/progress-bar/blessed.js +54 -0
- package/dist/progress-bar/blessed.js.map +1 -0
- package/dist/progress-bar/index.cjs +33 -0
- package/dist/progress-bar/index.cjs.map +1 -0
- package/dist/progress-bar/index.d.cts +181 -0
- package/dist/progress-bar/index.d.ts +181 -0
- package/dist/progress-bar/index.js +31 -0
- package/dist/progress-bar/index.js.map +1 -0
- package/package.json +28 -12
- package/src/components/progress-bar/README.md +193 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
# ProgressBar
|
|
2
|
+
|
|
3
|
+
Render a bounded numeric value as a fixed-width terminal progress track.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Pure renderer usable without a live terminal.
|
|
8
|
+
- Blessed adapter with explicit update and destroy methods.
|
|
9
|
+
- Custom numeric ranges.
|
|
10
|
+
- Automatic clamping.
|
|
11
|
+
- Unicode defaults and custom ASCII characters.
|
|
12
|
+
- Custom labels and value formatting.
|
|
13
|
+
- Dedicated subpath exports for tree shaking.
|
|
14
|
+
- No automatic `screen.render()` calls.
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
npm install blessed blessed-components
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
`blessed` is a peer dependency.
|
|
23
|
+
|
|
24
|
+
## Pure renderer
|
|
25
|
+
|
|
26
|
+
Importing this entry does not load Blessed:
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { renderProgressBar } from 'blessed-components/progress-bar';
|
|
30
|
+
|
|
31
|
+
const output = renderProgressBar({
|
|
32
|
+
label: 'Quality',
|
|
33
|
+
value: 78,
|
|
34
|
+
width: 16,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// Quality ████████████░░░░ 78%
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Custom range
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
renderProgressBar({
|
|
44
|
+
min: 10,
|
|
45
|
+
max: 20,
|
|
46
|
+
value: 15,
|
|
47
|
+
width: 10,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// █████░░░░░ 50%
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### ASCII mode
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
renderProgressBar({
|
|
57
|
+
characters: {
|
|
58
|
+
filled: '#',
|
|
59
|
+
empty: '-',
|
|
60
|
+
},
|
|
61
|
+
value: 50,
|
|
62
|
+
width: 10,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// #####----- 50%
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Custom value
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
renderProgressBar({
|
|
72
|
+
formatValue: ({ value }) => `${value} files`,
|
|
73
|
+
label: 'Uploaded',
|
|
74
|
+
value: 25,
|
|
75
|
+
width: 8,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// Uploaded ██░░░░░░ 25 files
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Blessed adapter
|
|
82
|
+
|
|
83
|
+
Use the separate Blessed entry when an element is needed:
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
import blessed from 'blessed';
|
|
87
|
+
import { progressBar } from 'blessed-components/progress-bar/blessed';
|
|
88
|
+
|
|
89
|
+
const screen = blessed.screen({ smartCSR: true });
|
|
90
|
+
|
|
91
|
+
const upload = progressBar({
|
|
92
|
+
parent: screen,
|
|
93
|
+
box: {
|
|
94
|
+
top: 0,
|
|
95
|
+
left: 0,
|
|
96
|
+
width: 40,
|
|
97
|
+
height: 1,
|
|
98
|
+
},
|
|
99
|
+
data: {
|
|
100
|
+
label: 'Uploaded',
|
|
101
|
+
value: 25,
|
|
102
|
+
width: 20,
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
screen.render();
|
|
107
|
+
|
|
108
|
+
upload.setData({
|
|
109
|
+
label: 'Uploaded',
|
|
110
|
+
value: 75,
|
|
111
|
+
width: 20,
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
screen.render();
|
|
115
|
+
|
|
116
|
+
upload.destroy();
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
The adapter owns only its `BoxElement`. It updates content through `setData`
|
|
120
|
+
and detaches the element through `destroy`. Rendering remains the caller's
|
|
121
|
+
responsibility, allowing multiple updates to be batched.
|
|
122
|
+
|
|
123
|
+
## Renderer API
|
|
124
|
+
|
|
125
|
+
### `renderProgressBar(options)`
|
|
126
|
+
|
|
127
|
+
Returns a plain string.
|
|
128
|
+
|
|
129
|
+
| Option | Type | Default | Description |
|
|
130
|
+
| --- | --- | --- | --- |
|
|
131
|
+
| `value` | `number` | Required | Current numeric value. |
|
|
132
|
+
| `width` | `number` | Required | Positive integer track width in characters. |
|
|
133
|
+
| `min` | `number` | `0` | Lower bound. |
|
|
134
|
+
| `max` | `number` | `100` | Upper bound. |
|
|
135
|
+
| `label` | `string` | — | Text rendered before the track. |
|
|
136
|
+
| `characters` | `{ filled: string; empty: string }` | `█`, `░` | Single-cell track characters. |
|
|
137
|
+
| `formatValue` | `(context) => string` | Percentage | Formats trailing value text. |
|
|
138
|
+
|
|
139
|
+
`value` is clamped to `[min, max]`. `max` must be greater than `min`.
|
|
140
|
+
|
|
141
|
+
`formatValue` receives:
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
interface ProgressBarValueContext {
|
|
145
|
+
percentage: number;
|
|
146
|
+
value: number;
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
`value` in this context is the clamped value.
|
|
151
|
+
|
|
152
|
+
## Adapter API
|
|
153
|
+
|
|
154
|
+
### `progressBar(options)`
|
|
155
|
+
|
|
156
|
+
| Option | Type | Description |
|
|
157
|
+
| --- | --- | --- |
|
|
158
|
+
| `parent` | `blessed.Widgets.Node` | Parent Blessed node. |
|
|
159
|
+
| `data` | `RenderProgressBarOptions` | Renderer data. |
|
|
160
|
+
| `box` | `ProgressBarBoxOptions` | Blessed box options except `parent`, `content`, and `tags`. |
|
|
161
|
+
|
|
162
|
+
Returns:
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
interface ProgressBarHandle {
|
|
166
|
+
readonly element: blessed.Widgets.BoxElement;
|
|
167
|
+
setData(data: RenderProgressBarOptions): void;
|
|
168
|
+
destroy(): void;
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## Accessibility and terminal compatibility
|
|
173
|
+
|
|
174
|
+
- Do not communicate state through color alone; percentage text is enabled by
|
|
175
|
+
default.
|
|
176
|
+
- Use ASCII characters when Unicode block glyphs are unavailable.
|
|
177
|
+
- Keep labels concise for narrow terminals.
|
|
178
|
+
- The component is display-only and does not receive focus or keyboard input.
|
|
179
|
+
- Call `screen.render()` after updates when visible output should be flushed.
|
|
180
|
+
|
|
181
|
+
## Tree shaking
|
|
182
|
+
|
|
183
|
+
Prefer the narrowest import:
|
|
184
|
+
|
|
185
|
+
```ts
|
|
186
|
+
import { renderProgressBar } from 'blessed-components/progress-bar';
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
The pure entry contains no Blessed import. Import the adapter only when needed:
|
|
190
|
+
|
|
191
|
+
```ts
|
|
192
|
+
import { progressBar } from 'blessed-components/progress-bar/blessed';
|
|
193
|
+
```
|