@termuijs/widgets 0.1.3 → 0.1.4
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 +88 -39
- package/dist/index.cjs +2141 -52
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +800 -1
- package/dist/index.d.ts +800 -1
- package/dist/index.js +2131 -47
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @termuijs/widgets
|
|
2
2
|
|
|
3
|
-
The building blocks for terminal UIs.
|
|
3
|
+
The building blocks for terminal UIs. Display, layout, data, charts, and feedback widgets. Every widget extends the base `Widget` class, manages its own render rectangle, and only repaints when something changes.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -10,29 +10,73 @@ npm install @termuijs/widgets
|
|
|
10
10
|
|
|
11
11
|
Requires `@termuijs/core` as a peer dependency.
|
|
12
12
|
|
|
13
|
-
##
|
|
13
|
+
## All widgets
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
### Display
|
|
16
|
+
|
|
17
|
+
| Widget | What it does |
|
|
18
|
+
|--------|-------------|
|
|
17
19
|
| `Box` | Container with flexbox layout, borders, padding, margin |
|
|
18
20
|
| `Text` | Styled text. Color, bold, italic, underline, strikethrough, dim |
|
|
21
|
+
| `LogView` | Scrollable log panel with auto-scroll and configurable buffer |
|
|
22
|
+
| `StreamingText` | Typewriter effect. Respects `NO_MOTION` for instant output |
|
|
23
|
+
| `ChatMessage` | Chat bubble with role-aware styling (user / assistant / system) |
|
|
24
|
+
| `ToolCall` | AI tool call display with status indicator and collapsible args |
|
|
25
|
+
| `JSONView` | Collapsible, navigable JSON tree viewer |
|
|
26
|
+
| `DiffView` | Unified diff viewer with colored add / remove lines |
|
|
27
|
+
| `BigText` | Large ASCII art banner text. No external dependencies |
|
|
28
|
+
| `Gradient` | Text with per-character 256-color gradient |
|
|
29
|
+
|
|
30
|
+
### Layout
|
|
31
|
+
|
|
32
|
+
| Widget | What it does |
|
|
33
|
+
|--------|-------------|
|
|
34
|
+
| `Card` | Bordered container with optional title in the border |
|
|
35
|
+
| `ScrollView` | Height-bounded scrollable container with arrow-key navigation |
|
|
36
|
+
| `Center` | Centers a single child horizontally, vertically, or both |
|
|
37
|
+
| `Columns` | Evenly-split column layout from an array of widgets |
|
|
38
|
+
| `Sidebar` | Navigable sidebar with items, badges, and active highlight |
|
|
39
|
+
| `KeyValue` | Aligned key: value pairs with configurable separator |
|
|
40
|
+
| `Definition` | Term (bold) and definition (normal) stacked pairs |
|
|
41
|
+
| `Banner` | Full-width alert with title, body, and variant color |
|
|
42
|
+
| `StatusMessage` | Compact icon and message with variant color |
|
|
43
|
+
| `Grid` | CSS-grid-style layout; items flow left-to-right and wrap every N columns |
|
|
44
|
+
|
|
45
|
+
### Data and charts
|
|
46
|
+
|
|
47
|
+
| Widget | What it does |
|
|
48
|
+
|--------|-------------|
|
|
19
49
|
| `Table` | Data table with headers, column alignment, row selection |
|
|
50
|
+
| `Gauge` | Percentage indicator with label and color thresholds |
|
|
51
|
+
| `Sparkline` | Inline bar chart from an array of numbers |
|
|
52
|
+
| `BarChart` | Horizontal or vertical bar chart with grouping |
|
|
53
|
+
| `LineChart` | ASCII line plot with labeled X/Y axes and multi-series support |
|
|
54
|
+
| `HeatMap` | 2D matrix with color-scale shading and row/col labels |
|
|
55
|
+
| `StatusIndicator` | Colored dot with a label (ok / warn / error / unknown) |
|
|
56
|
+
|
|
57
|
+
### Feedback
|
|
58
|
+
|
|
59
|
+
| Widget | What it does |
|
|
60
|
+
|--------|-------------|
|
|
20
61
|
| `ProgressBar` | Horizontal bar with percentage fill and optional label |
|
|
21
|
-
| `Spinner` | Animated loading indicator.
|
|
22
|
-
| `
|
|
62
|
+
| `Spinner` | Animated loading indicator. Static char when `NO_MOTION=1` |
|
|
63
|
+
| `Skeleton` | Animated loading placeholder (pulse or shimmer) |
|
|
64
|
+
| `MultiProgress` | Multiple labeled progress bars in one widget |
|
|
65
|
+
| `CommandPalette` | Searchable, filterable command menu |
|
|
66
|
+
| `Scrollbar` | Standalone scrollbar indicator (vertical or horizontal) |
|
|
67
|
+
|
|
68
|
+
### Input
|
|
69
|
+
|
|
70
|
+
| Widget | What it does |
|
|
71
|
+
|--------|-------------|
|
|
23
72
|
| `TextInput` | Single-line text input with cursor, placeholder, and change callback |
|
|
24
73
|
| `List` | Scrollable list with keyboard selection. Good for small datasets |
|
|
25
|
-
| `VirtualList` | Scroll-virtualized list. Renders only
|
|
26
|
-
| `LogView` | Tailing log viewer with auto-scroll and configurable buffer limit |
|
|
27
|
-
| `Sparkline` | Inline line chart from an array of numbers |
|
|
28
|
-
| `StatusIndicator` | Colored dot with a label (ok / warn / error / unknown) |
|
|
29
|
-
| `BarChart` | Horizontal or vertical bar chart with grouping |
|
|
30
|
-
| `Scrollbar` | Standalone scrollbar indicator |
|
|
74
|
+
| `VirtualList` | Scroll-virtualized list. Renders only visible rows; 1M items costs the same as 10 |
|
|
31
75
|
|
|
32
76
|
## Usage
|
|
33
77
|
|
|
34
78
|
```typescript
|
|
35
|
-
import { Box, Text, ProgressBar,
|
|
79
|
+
import { Box, Text, ProgressBar, StreamingText } from '@termuijs/widgets'
|
|
36
80
|
|
|
37
81
|
const container = new Box({
|
|
38
82
|
flexDirection: 'column',
|
|
@@ -42,51 +86,56 @@ const container = new Box({
|
|
|
42
86
|
|
|
43
87
|
container.addChild(new Text({ content: 'Downloads', bold: true }))
|
|
44
88
|
container.addChild(new ProgressBar({ value: 0.73, width: 30 }))
|
|
45
|
-
|
|
46
|
-
// VirtualList renders only visible rows
|
|
47
|
-
const list = new VirtualList({
|
|
48
|
-
totalItems: 100_000,
|
|
49
|
-
renderItem: (i) => `Row ${i}`,
|
|
50
|
-
onSelect: (i) => console.log('picked', i),
|
|
51
|
-
})
|
|
52
|
-
container.addChild(list)
|
|
89
|
+
container.addChild(new StreamingText({ text: 'Processing...', speed: 40 }))
|
|
53
90
|
```
|
|
54
91
|
|
|
55
92
|
## VirtualList
|
|
56
93
|
|
|
57
|
-
|
|
94
|
+
VirtualList paints only the rows that fit in the viewport plus a small overscan buffer. A list of 1,000,000 items renders the same ~26 rows as a list of 10.
|
|
58
95
|
|
|
59
96
|
```typescript
|
|
60
97
|
const list = new VirtualList({
|
|
61
|
-
totalItems:
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
renderItem: (index) => `${data[index].name} — ${data[index].status}`,
|
|
65
|
-
onSelect: (index) => inspect(data[index]),
|
|
98
|
+
totalItems: 1_000_000,
|
|
99
|
+
renderItem: (index) => `Line ${index}: some content`,
|
|
100
|
+
onSelect: (index) => inspect(index),
|
|
66
101
|
})
|
|
67
102
|
|
|
68
|
-
// Navigation
|
|
69
103
|
list.selectNext()
|
|
70
104
|
list.selectPrev()
|
|
71
105
|
list.pageDown()
|
|
72
106
|
list.selectFirst()
|
|
73
107
|
list.selectLast()
|
|
74
108
|
list.scrollTo(500)
|
|
75
|
-
list.confirm() // fires onSelect with current index
|
|
76
|
-
|
|
77
|
-
// Update data on the fly
|
|
78
|
-
list.setTotalItems(newData.length)
|
|
79
|
-
list.setRenderItem((i) => newData[i].label)
|
|
80
109
|
```
|
|
81
110
|
|
|
82
|
-
##
|
|
111
|
+
## AI widgets
|
|
112
|
+
|
|
113
|
+
Display AI tool usage and streaming output with the purpose-built widgets:
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
import { StreamingText, ChatMessage, ToolCall } from '@termuijs/widgets'
|
|
117
|
+
|
|
118
|
+
const msg = new ChatMessage({
|
|
119
|
+
role: 'assistant',
|
|
120
|
+
content: 'Here is the result...',
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
const call = new ToolCall({
|
|
124
|
+
name: 'read_file',
|
|
125
|
+
status: 'running',
|
|
126
|
+
args: { path: '/etc/hosts' },
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
const stream = new StreamingText({
|
|
130
|
+
text: 'Generating response...',
|
|
131
|
+
speed: 30,
|
|
132
|
+
cursor: '▋',
|
|
133
|
+
})
|
|
134
|
+
```
|
|
83
135
|
|
|
84
|
-
|
|
85
|
-
- `focusable` — whether Tab stops on this widget
|
|
86
|
-
- `style` — colors, borders, padding, margin
|
|
87
|
-
- `markDirty()` — flags the widget for re-render on the next frame
|
|
88
|
-
- Focus ring rendering when focused
|
|
136
|
+
## caps.unicode and caps.motion
|
|
89
137
|
|
|
138
|
+
All widgets check `caps.unicode` and `caps.motion` automatically. Set `NO_UNICODE=1` or `NO_MOTION=1` in your environment to get ASCII fallbacks and static output. This works across Spinner, Skeleton, StreamingText, ProgressBar, LineChart, HeatMap, and every other widget that uses unicode characters or timers.
|
|
90
139
|
|
|
91
140
|
## Documentation
|
|
92
141
|
|