snice 3.4.1 → 3.6.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/bin/templates/social/src/styles/global.css +56 -47
- package/dist/components/audio-recorder/snice-audio-recorder.d.ts +14 -4
- package/dist/components/audio-recorder/snice-audio-recorder.js +248 -71
- package/dist/components/audio-recorder/snice-audio-recorder.js.map +1 -1
- package/dist/components/audio-recorder/snice-audio-recorder.types.d.ts +2 -0
- package/dist/components/avatar/snice-avatar.d.ts +2 -2
- package/dist/components/avatar/snice-avatar.js +20 -21
- package/dist/components/avatar/snice-avatar.js.map +1 -1
- package/dist/components/calendar/snice-calendar.d.ts +8 -2
- package/dist/components/calendar/snice-calendar.js +160 -82
- package/dist/components/calendar/snice-calendar.js.map +1 -1
- package/dist/components/chart/snice-chart.js +50 -18
- package/dist/components/chart/snice-chart.js.map +1 -1
- package/dist/components/checkbox/snice-checkbox.d.ts +4 -1
- package/dist/components/checkbox/snice-checkbox.js +46 -17
- package/dist/components/checkbox/snice-checkbox.js.map +1 -1
- package/dist/components/code-block/highlighter.d.ts +5 -0
- package/dist/components/code-block/highlighter.js +137 -0
- package/dist/components/code-block/highlighter.js.map +1 -0
- package/dist/components/code-block/highlighters/highlight.d.ts +64 -0
- package/dist/components/code-block/highlighters/highlight.js +108 -0
- package/dist/components/code-block/highlighters/highlight.js.map +1 -0
- package/dist/components/code-block/highlighters/prism.d.ts +41 -0
- package/dist/components/code-block/highlighters/prism.js +73 -0
- package/dist/components/code-block/highlighters/prism.js.map +1 -0
- package/dist/components/code-block/snice-code-block.d.ts +19 -1
- package/dist/components/code-block/snice-code-block.js +128 -29
- package/dist/components/code-block/snice-code-block.js.map +1 -1
- package/dist/components/code-block/snice-code-block.types.d.ts +15 -1
- package/dist/components/color-picker/snice-color-picker.d.ts +1 -0
- package/dist/components/color-picker/snice-color-picker.js +17 -6
- package/dist/components/color-picker/snice-color-picker.js.map +1 -1
- package/dist/components/date-picker/snice-date-picker.d.ts +1 -0
- package/dist/components/date-picker/snice-date-picker.js +16 -5
- package/dist/components/date-picker/snice-date-picker.js.map +1 -1
- package/dist/components/doc/snice-doc.d.ts +27 -73
- package/dist/components/doc/snice-doc.js +385 -534
- package/dist/components/doc/snice-doc.js.map +1 -1
- package/dist/components/draw/snice-draw.d.ts +4 -0
- package/dist/components/draw/snice-draw.js +134 -14
- package/dist/components/draw/snice-draw.js.map +1 -1
- package/dist/components/draw/snice-draw.types.d.ts +5 -0
- package/dist/components/file-upload/snice-file-upload.js +1 -1
- package/dist/components/input/snice-input.d.ts +2 -0
- package/dist/components/input/snice-input.js +34 -9
- package/dist/components/input/snice-input.js.map +1 -1
- package/dist/components/kanban/snice-kanban.d.ts +13 -1
- package/dist/components/kanban/snice-kanban.js +191 -36
- package/dist/components/kanban/snice-kanban.js.map +1 -1
- package/dist/components/kanban/snice-kanban.types.d.ts +11 -1
- package/dist/components/kpi/snice-kpi.js +5 -1
- package/dist/components/kpi/snice-kpi.js.map +1 -1
- package/dist/components/layout/snice-layout-sidebar.js +1 -1
- package/dist/components/layout/snice-layout-sidebar.js.map +1 -1
- package/dist/components/layout/snice-layout.js +1 -1
- package/dist/components/layout/snice-layout.js.map +1 -1
- package/dist/components/location/snice-location.js +1 -1
- package/dist/components/location/snice-location.js.map +1 -1
- package/dist/components/radio/snice-radio.d.ts +1 -0
- package/dist/components/radio/snice-radio.js +17 -6
- package/dist/components/radio/snice-radio.js.map +1 -1
- package/dist/components/select/snice-select.d.ts +2 -0
- package/dist/components/select/snice-select.js +48 -19
- package/dist/components/select/snice-select.js.map +1 -1
- package/dist/components/slider/snice-slider.d.ts +2 -0
- package/dist/components/slider/snice-slider.js +34 -14
- package/dist/components/slider/snice-slider.js.map +1 -1
- package/dist/components/snice-cell-HZ2iIBIC.js +4 -0
- package/dist/components/snice-cell-HZ2iIBIC.js.map +1 -0
- package/dist/components/split-pane/snice-split-pane.js +1 -1
- package/dist/components/split-pane/snice-split-pane.js.map +1 -1
- package/dist/components/switch/snice-switch.d.ts +1 -0
- package/dist/components/switch/snice-switch.js +16 -6
- package/dist/components/switch/snice-switch.js.map +1 -1
- package/dist/components/table/snice-cell-actions.js +1 -1
- package/dist/components/table/snice-cell-actions.js.map +1 -1
- package/dist/components/table/snice-cell-boolean.js +1 -1
- package/dist/components/table/snice-cell-color.js +1 -1
- package/dist/components/table/snice-cell-color.js.map +1 -1
- package/dist/components/table/snice-cell-currency.js +1 -1
- package/dist/components/table/snice-cell-date.js +1 -1
- package/dist/components/table/snice-cell-duration.js +1 -1
- package/dist/components/table/snice-cell-email.js +1 -1
- package/dist/components/table/snice-cell-email.js.map +1 -1
- package/dist/components/table/snice-cell-filesize.js +1 -1
- package/dist/components/table/snice-cell-image.js +1 -1
- package/dist/components/table/snice-cell-image.js.map +1 -1
- package/dist/components/table/snice-cell-json.js +1 -1
- package/dist/components/table/snice-cell-json.js.map +1 -1
- package/dist/components/table/snice-cell-link.js +1 -1
- package/dist/components/table/snice-cell-link.js.map +1 -1
- package/dist/components/table/snice-cell-location.js +1 -1
- package/dist/components/table/snice-cell-location.js.map +1 -1
- package/dist/components/table/snice-cell-number.js +1 -1
- package/dist/components/table/snice-cell-percentage.js +1 -1
- package/dist/components/table/snice-cell-percentage.js.map +1 -1
- package/dist/components/table/snice-cell-phone.js +1 -1
- package/dist/components/table/snice-cell-phone.js.map +1 -1
- package/dist/components/table/snice-cell-progress.js +3 -3
- package/dist/components/table/snice-cell-progress.js.map +1 -1
- package/dist/components/table/snice-cell-rating.js +2 -2
- package/dist/components/table/snice-cell-rating.js.map +1 -1
- package/dist/components/table/snice-cell-sparkline.js +2 -2
- package/dist/components/table/snice-cell-sparkline.js.map +1 -1
- package/dist/components/table/snice-cell-status.js +1 -1
- package/dist/components/table/snice-cell-status.js.map +1 -1
- package/dist/components/table/snice-cell-tag.js +1 -1
- package/dist/components/table/snice-cell-tag.js.map +1 -1
- package/dist/components/table/snice-cell-text.js +1 -1
- package/dist/components/table/snice-cell.js +15 -10
- package/dist/components/table/snice-cell.js.map +1 -1
- package/dist/components/table/snice-header.js +1 -1
- package/dist/components/table/snice-header.js.map +1 -1
- package/dist/components/table/snice-row.js +2 -2
- package/dist/components/table/snice-row.js.map +1 -1
- package/dist/components/table/snice-table.d.ts +1 -0
- package/dist/components/table/snice-table.js +24 -4
- package/dist/components/table/snice-table.js.map +1 -1
- package/dist/components/terminal/snice-terminal.d.ts +40 -0
- package/dist/components/terminal/snice-terminal.js +371 -0
- package/dist/components/terminal/snice-terminal.js.map +1 -0
- package/dist/components/terminal/snice-terminal.types.d.ts +20 -24
- package/dist/components/textarea/snice-textarea.d.ts +2 -0
- package/dist/components/textarea/snice-textarea.js +25 -6
- package/dist/components/textarea/snice-textarea.js.map +1 -1
- package/dist/components/theme/theme.css +16 -0
- package/dist/components/tree/snice-tree-item.d.ts +18 -4
- package/dist/components/tree/snice-tree-item.js +271 -88
- package/dist/components/tree/snice-tree-item.js.map +1 -1
- package/dist/components/tree/snice-tree-item.types.d.ts +3 -0
- package/dist/components/tree/snice-tree.d.ts +18 -2
- package/dist/components/tree/snice-tree.js +422 -56
- package/dist/components/tree/snice-tree.js.map +1 -1
- package/dist/components/tree/snice-tree.types.d.ts +1 -0
- package/dist/components/virtual-scroller/snice-virtual-scroller.js +4 -2
- package/dist/components/virtual-scroller/snice-virtual-scroller.js.map +1 -1
- package/dist/index.cjs +42 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +42 -23
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +42 -23
- package/dist/index.iife.js.map +1 -1
- package/dist/render-tracker.d.ts +1 -0
- package/dist/symbols.cjs +13 -14
- package/dist/symbols.cjs.map +1 -1
- package/dist/symbols.esm.js +13 -14
- package/dist/symbols.esm.js.map +1 -1
- package/dist/template.d.ts +1 -0
- package/dist/transitions.cjs +1 -1
- package/dist/transitions.esm.js +1 -1
- package/docs/ai/api.md +37 -4
- package/docs/ai/components/doc.md +41 -106
- package/docs/ai/components/kanban.md +31 -9
- package/docs/ai/components/kpi.md +15 -0
- package/docs/ai/components/terminal.md +147 -0
- package/docs/components/doc.md +96 -212
- package/docs/components/kanban.md +119 -4
- package/docs/components/kpi.md +27 -0
- package/docs/components/terminal.md +451 -0
- package/package.json +1 -1
- package/dist/components/actions/snice-actions.d.ts +0 -28
- package/dist/components/actions/snice-actions.js +0 -220
- package/dist/components/actions/snice-actions.js.map +0 -1
- package/dist/components/actions/snice-actions.types.d.ts +0 -27
- package/dist/components/doc/snice-doc.types.d.ts +0 -118
- package/dist/components/gantt/snice-gantt.d.ts +0 -29
- package/dist/components/gantt/snice-gantt.js +0 -268
- package/dist/components/gantt/snice-gantt.js.map +0 -1
- package/dist/components/gantt/snice-gantt.types.d.ts +0 -23
- package/dist/components/snice-cell-C0slgOpe.js +0 -4
- package/dist/components/snice-cell-C0slgOpe.js.map +0 -1
- package/dist/components/stat/snice-stat.d.ts +0 -14
- package/dist/components/stat/snice-stat.js +0 -140
- package/dist/components/stat/snice-stat.js.map +0 -1
- package/dist/components/stat/snice-stat.types.d.ts +0 -12
- package/docs/ai/components/actions.md +0 -81
- package/docs/ai/components/gantt.md +0 -95
- package/docs/ai/components/stat.md +0 -29
- package/docs/components/actions.md +0 -317
- package/docs/components/gantt.md +0 -347
- package/docs/components/stat.md +0 -45
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
# snice-terminal
|
|
2
|
+
|
|
3
|
+
A shell terminal emulator component with command execution, history navigation, ANSI color support, and keyboard shortcuts.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Command execution** - Execute commands with @request/@respond pattern
|
|
8
|
+
- **Command history** - Navigate with arrow keys (↑/↓)
|
|
9
|
+
- **ANSI colors** - Support for ANSI escape sequences
|
|
10
|
+
- **Keyboard shortcuts** - Ctrl+C, Ctrl+L, Tab (planned)
|
|
11
|
+
- **Readonly mode** - Display-only terminal output
|
|
12
|
+
- **Line management** - Auto-scroll and line limit
|
|
13
|
+
- **Timestamps** - Optional timestamp display
|
|
14
|
+
- **Customizable styling** - CSS custom properties for theming
|
|
15
|
+
|
|
16
|
+
## Basic Usage
|
|
17
|
+
|
|
18
|
+
```html
|
|
19
|
+
<snice-terminal id="terminal" prompt="$ " cwd="~"></snice-terminal>
|
|
20
|
+
|
|
21
|
+
<script type="module">
|
|
22
|
+
import 'snice';
|
|
23
|
+
|
|
24
|
+
const terminal = document.getElementById('terminal');
|
|
25
|
+
|
|
26
|
+
// Write to terminal
|
|
27
|
+
terminal.writeln('Welcome to the terminal!', 'info');
|
|
28
|
+
terminal.writeln('Type "help" for commands', 'output');
|
|
29
|
+
</script>
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Properties
|
|
33
|
+
|
|
34
|
+
| Property | Attribute | Type | Default | Description |
|
|
35
|
+
| ----------------- | ------------------ | --------- | ---------- | ------------------------------------- |
|
|
36
|
+
| `prompt` | `prompt` | `string` | `"$ "` | Terminal prompt string |
|
|
37
|
+
| `cwd` | `cwd` | `string` | `"~"` | Current working directory |
|
|
38
|
+
| `readonly` | `readonly` | `boolean` | `false` | Disable input (display only) |
|
|
39
|
+
| `maxLines` | `max-lines` | `number` | `1000` | Maximum lines to keep in history |
|
|
40
|
+
| `showTimestamps` | `show-timestamps` | `boolean` | `false` | Show timestamps on each line |
|
|
41
|
+
|
|
42
|
+
## Methods
|
|
43
|
+
|
|
44
|
+
### `write(content: string, type?: TerminalLineType): void`
|
|
45
|
+
|
|
46
|
+
Write content to terminal without adding a newline.
|
|
47
|
+
|
|
48
|
+
```javascript
|
|
49
|
+
terminal.write('Loading', 'output');
|
|
50
|
+
terminal.write('...', 'output');
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### `writeln(content: string, type?: TerminalLineType): void`
|
|
54
|
+
|
|
55
|
+
Write a line to the terminal with a newline.
|
|
56
|
+
|
|
57
|
+
```javascript
|
|
58
|
+
terminal.writeln('Command completed successfully', 'success');
|
|
59
|
+
terminal.writeln('Warning: Low disk space', 'warning');
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### `writeLines(lines: Array<{ content: string; type?: TerminalLineType }>): void`
|
|
63
|
+
|
|
64
|
+
Write multiple lines at once.
|
|
65
|
+
|
|
66
|
+
```javascript
|
|
67
|
+
terminal.writeLines([
|
|
68
|
+
{ content: 'File listing:', type: 'info' },
|
|
69
|
+
{ content: 'file1.txt', type: 'output' },
|
|
70
|
+
{ content: 'file2.txt', type: 'output' },
|
|
71
|
+
{ content: 'file3.txt', type: 'output' },
|
|
72
|
+
]);
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### `writeError(content: string): void`
|
|
76
|
+
|
|
77
|
+
Write an error message to the terminal.
|
|
78
|
+
|
|
79
|
+
```javascript
|
|
80
|
+
terminal.writeError('Error: File not found');
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### `clear(): void`
|
|
84
|
+
|
|
85
|
+
Clear all terminal output.
|
|
86
|
+
|
|
87
|
+
```javascript
|
|
88
|
+
terminal.clear();
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### `focus(): void`
|
|
92
|
+
|
|
93
|
+
Focus the terminal input.
|
|
94
|
+
|
|
95
|
+
```javascript
|
|
96
|
+
terminal.focus();
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### `getHistory(): string[]`
|
|
100
|
+
|
|
101
|
+
Get the command history.
|
|
102
|
+
|
|
103
|
+
```javascript
|
|
104
|
+
const history = terminal.getHistory();
|
|
105
|
+
console.log('Command history:', history);
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### `clearHistory(): void`
|
|
109
|
+
|
|
110
|
+
Clear the command history.
|
|
111
|
+
|
|
112
|
+
```javascript
|
|
113
|
+
terminal.clearHistory();
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Events
|
|
117
|
+
|
|
118
|
+
### `@snice/terminal-command`
|
|
119
|
+
|
|
120
|
+
Emitted when a command is entered.
|
|
121
|
+
|
|
122
|
+
```javascript
|
|
123
|
+
terminal.addEventListener('@snice/terminal-command', (e) => {
|
|
124
|
+
console.log('Command:', e.detail.command);
|
|
125
|
+
console.log('Args:', e.detail.args);
|
|
126
|
+
});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
**Detail:**
|
|
130
|
+
- `command: string` - The command name
|
|
131
|
+
- `args: string[]` - Command arguments
|
|
132
|
+
|
|
133
|
+
### `@snice/terminal-clear`
|
|
134
|
+
|
|
135
|
+
Emitted when the terminal is cleared.
|
|
136
|
+
|
|
137
|
+
```javascript
|
|
138
|
+
terminal.addEventListener('@snice/terminal-clear', () => {
|
|
139
|
+
console.log('Terminal was cleared');
|
|
140
|
+
});
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### `@snice/terminal-ready`
|
|
144
|
+
|
|
145
|
+
Emitted when the terminal is ready.
|
|
146
|
+
|
|
147
|
+
```javascript
|
|
148
|
+
terminal.addEventListener('@snice/terminal-ready', () => {
|
|
149
|
+
console.log('Terminal is ready');
|
|
150
|
+
});
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Command Execution Pattern
|
|
154
|
+
|
|
155
|
+
The terminal uses Snice's `@request`/`@respond` pattern for command execution:
|
|
156
|
+
|
|
157
|
+
```javascript
|
|
158
|
+
import { element, respond } from 'snice';
|
|
159
|
+
|
|
160
|
+
@element('terminal-controller')
|
|
161
|
+
class TerminalController extends HTMLElement {
|
|
162
|
+
@respond('terminal-command')
|
|
163
|
+
async handleCommand(payload) {
|
|
164
|
+
const { command, args, cwd, history } = payload;
|
|
165
|
+
|
|
166
|
+
// Handle different commands
|
|
167
|
+
switch (command) {
|
|
168
|
+
case 'echo':
|
|
169
|
+
return { output: args.join(' '), exitCode: 0 };
|
|
170
|
+
|
|
171
|
+
case 'pwd':
|
|
172
|
+
return { output: cwd, exitCode: 0 };
|
|
173
|
+
|
|
174
|
+
case 'clear':
|
|
175
|
+
// Special marker to trigger clear
|
|
176
|
+
return { output: '\x1B[CLEAR]' };
|
|
177
|
+
|
|
178
|
+
case 'history':
|
|
179
|
+
return { output: history.join('\n'), exitCode: 0 };
|
|
180
|
+
|
|
181
|
+
default:
|
|
182
|
+
return {
|
|
183
|
+
error: `Command not found: ${command}`,
|
|
184
|
+
exitCode: 127,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## Line Types
|
|
192
|
+
|
|
193
|
+
The terminal supports different line types for styling:
|
|
194
|
+
|
|
195
|
+
- `input` - User input echoed back
|
|
196
|
+
- `output` - Standard command output
|
|
197
|
+
- `error` - Error messages (red)
|
|
198
|
+
- `info` - Information messages (blue)
|
|
199
|
+
- `success` - Success messages (green)
|
|
200
|
+
- `warning` - Warning messages (yellow)
|
|
201
|
+
|
|
202
|
+
```javascript
|
|
203
|
+
terminal.writeln('This is output', 'output');
|
|
204
|
+
terminal.writeln('This is an error', 'error');
|
|
205
|
+
terminal.writeln('This is info', 'info');
|
|
206
|
+
terminal.writeln('This is success', 'success');
|
|
207
|
+
terminal.writeln('This is a warning', 'warning');
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
## Keyboard Shortcuts
|
|
211
|
+
|
|
212
|
+
| Key | Action |
|
|
213
|
+
| ----------- | -------------------------- |
|
|
214
|
+
| `Enter` | Execute command |
|
|
215
|
+
| `↑` | Previous command (history) |
|
|
216
|
+
| `↓` | Next command (history) |
|
|
217
|
+
| `Ctrl+C` | Cancel current input |
|
|
218
|
+
| `Ctrl+L` | Clear terminal |
|
|
219
|
+
| `Tab` | Auto-complete (TODO) |
|
|
220
|
+
|
|
221
|
+
## ANSI Color Support
|
|
222
|
+
|
|
223
|
+
The terminal supports ANSI escape sequences for colored output:
|
|
224
|
+
|
|
225
|
+
```javascript
|
|
226
|
+
// Standard colors (30-37)
|
|
227
|
+
terminal.writeln('\x1b[31mRed text\x1b[0m', 'output');
|
|
228
|
+
terminal.writeln('\x1b[32mGreen text\x1b[0m', 'output');
|
|
229
|
+
terminal.writeln('\x1b[33mYellow text\x1b[0m', 'output');
|
|
230
|
+
terminal.writeln('\x1b[34mBlue text\x1b[0m', 'output');
|
|
231
|
+
terminal.writeln('\x1b[35mMagenta text\x1b[0m', 'output');
|
|
232
|
+
terminal.writeln('\x1b[36mCyan text\x1b[0m', 'output');
|
|
233
|
+
terminal.writeln('\x1b[37mWhite text\x1b[0m', 'output');
|
|
234
|
+
|
|
235
|
+
// Bright colors (90-97)
|
|
236
|
+
terminal.writeln('\x1b[91mBright Red\x1b[0m', 'output');
|
|
237
|
+
terminal.writeln('\x1b[92mBright Green\x1b[0m', 'output');
|
|
238
|
+
terminal.writeln('\x1b[93mBright Yellow\x1b[0m', 'output');
|
|
239
|
+
terminal.writeln('\x1b[94mBright Blue\x1b[0m', 'output');
|
|
240
|
+
|
|
241
|
+
// Reset
|
|
242
|
+
terminal.writeln('\x1b[0mReset to default\x1b[0m', 'output');
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
**ANSI Color Map:**
|
|
246
|
+
- `30` / `90` - Black / Bright Black
|
|
247
|
+
- `31` / `91` - Red / Bright Red
|
|
248
|
+
- `32` / `92` - Green / Bright Green
|
|
249
|
+
- `33` / `93` - Yellow / Bright Yellow
|
|
250
|
+
- `34` / `94` - Blue / Bright Blue
|
|
251
|
+
- `35` / `95` - Magenta / Bright Magenta
|
|
252
|
+
- `36` / `96` - Cyan / Bright Cyan
|
|
253
|
+
- `37` / `97` - White / Bright White
|
|
254
|
+
- `0` - Reset
|
|
255
|
+
|
|
256
|
+
## Styling
|
|
257
|
+
|
|
258
|
+
The component can be styled using CSS custom properties:
|
|
259
|
+
|
|
260
|
+
```css
|
|
261
|
+
snice-terminal {
|
|
262
|
+
/* Container */
|
|
263
|
+
--snice-terminal-background: #1e1e1e;
|
|
264
|
+
--snice-terminal-foreground: #d4d4d4;
|
|
265
|
+
--snice-terminal-border: #3c3c3c;
|
|
266
|
+
|
|
267
|
+
/* Scrollbar */
|
|
268
|
+
--snice-terminal-scrollbar: #424242;
|
|
269
|
+
--snice-terminal-scrollbar-thumb: #686868;
|
|
270
|
+
|
|
271
|
+
/* Line types */
|
|
272
|
+
--snice-terminal-input-color: #d4d4d4;
|
|
273
|
+
--snice-terminal-output-color: #cccccc;
|
|
274
|
+
--snice-terminal-error-color: #ff5555;
|
|
275
|
+
--snice-terminal-info-color: #569cd6;
|
|
276
|
+
--snice-terminal-success-color: #50fa7b;
|
|
277
|
+
--snice-terminal-warning-color: #f1fa8c;
|
|
278
|
+
|
|
279
|
+
/* Prompt */
|
|
280
|
+
--snice-terminal-prompt-color: #569cd6;
|
|
281
|
+
|
|
282
|
+
/* Selection */
|
|
283
|
+
--snice-terminal-selection: rgba(255, 255, 255, 0.2);
|
|
284
|
+
}
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
## Examples
|
|
288
|
+
|
|
289
|
+
### Basic Terminal
|
|
290
|
+
|
|
291
|
+
```html
|
|
292
|
+
<snice-terminal id="terminal"></snice-terminal>
|
|
293
|
+
|
|
294
|
+
<script type="module">
|
|
295
|
+
import 'snice';
|
|
296
|
+
|
|
297
|
+
const terminal = document.getElementById('terminal');
|
|
298
|
+
|
|
299
|
+
terminal.writeln('Welcome to the terminal!', 'info');
|
|
300
|
+
terminal.writeln('Type commands to get started', 'output');
|
|
301
|
+
</script>
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
### With Command Handler
|
|
305
|
+
|
|
306
|
+
```html
|
|
307
|
+
<terminal-controller></terminal-controller>
|
|
308
|
+
<snice-terminal id="terminal" prompt="myapp $ "></snice-terminal>
|
|
309
|
+
|
|
310
|
+
<script type="module">
|
|
311
|
+
import { element, respond } from 'snice';
|
|
312
|
+
|
|
313
|
+
@element('terminal-controller')
|
|
314
|
+
class TerminalController extends HTMLElement {
|
|
315
|
+
@respond('terminal-command')
|
|
316
|
+
async handleCommand(payload) {
|
|
317
|
+
const { command, args } = payload;
|
|
318
|
+
|
|
319
|
+
switch (command) {
|
|
320
|
+
case 'hello':
|
|
321
|
+
return { output: `Hello, ${args[0] || 'World'}!`, exitCode: 0 };
|
|
322
|
+
|
|
323
|
+
case 'date':
|
|
324
|
+
return { output: new Date().toString(), exitCode: 0 };
|
|
325
|
+
|
|
326
|
+
case 'help':
|
|
327
|
+
return {
|
|
328
|
+
output: 'Available commands:\n hello [name]\n date\n help\n clear',
|
|
329
|
+
exitCode: 0,
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
case 'clear':
|
|
333
|
+
return { output: '\x1B[CLEAR]' };
|
|
334
|
+
|
|
335
|
+
default:
|
|
336
|
+
return {
|
|
337
|
+
error: `Unknown command: ${command}`,
|
|
338
|
+
exitCode: 1,
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
const terminal = document.getElementById('terminal');
|
|
345
|
+
terminal.writeln('Type "help" for available commands', 'info');
|
|
346
|
+
</script>
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
### Readonly Terminal
|
|
350
|
+
|
|
351
|
+
```html
|
|
352
|
+
<snice-terminal id="log-viewer" readonly show-timestamps></snice-terminal>
|
|
353
|
+
|
|
354
|
+
<script type="module">
|
|
355
|
+
import 'snice';
|
|
356
|
+
|
|
357
|
+
const logViewer = document.getElementById('log-viewer');
|
|
358
|
+
|
|
359
|
+
// Simulate log streaming
|
|
360
|
+
setInterval(() => {
|
|
361
|
+
const logTypes = ['info', 'warning', 'error', 'success'];
|
|
362
|
+
const type = logTypes[Math.floor(Math.random() * logTypes.length)];
|
|
363
|
+
const message = `Log entry at ${new Date().toISOString()}`;
|
|
364
|
+
logViewer.writeln(message, type);
|
|
365
|
+
}, 2000);
|
|
366
|
+
</script>
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
### With ANSI Colors
|
|
370
|
+
|
|
371
|
+
```html
|
|
372
|
+
<snice-terminal id="terminal"></snice-terminal>
|
|
373
|
+
|
|
374
|
+
<script type="module">
|
|
375
|
+
import 'snice';
|
|
376
|
+
|
|
377
|
+
const terminal = document.getElementById('terminal');
|
|
378
|
+
|
|
379
|
+
terminal.writeln('\x1b[1m\x1b[32mSuccess!\x1b[0m Operation completed', 'output');
|
|
380
|
+
terminal.writeln('\x1b[31mError:\x1b[0m Something went wrong', 'output');
|
|
381
|
+
terminal.writeln('\x1b[33mWarning:\x1b[0m Disk space low', 'output');
|
|
382
|
+
terminal.writeln('\x1b[36mInfo:\x1b[0m Processing...', 'output');
|
|
383
|
+
</script>
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
### Async Command Execution
|
|
387
|
+
|
|
388
|
+
```html
|
|
389
|
+
<terminal-controller></terminal-controller>
|
|
390
|
+
<snice-terminal id="terminal"></snice-terminal>
|
|
391
|
+
|
|
392
|
+
<script type="module">
|
|
393
|
+
import { element, respond } from 'snice';
|
|
394
|
+
|
|
395
|
+
@element('terminal-controller')
|
|
396
|
+
class TerminalController extends HTMLElement {
|
|
397
|
+
@respond('terminal-command')
|
|
398
|
+
async handleCommand(payload) {
|
|
399
|
+
const { command, args } = payload;
|
|
400
|
+
|
|
401
|
+
if (command === 'fetch') {
|
|
402
|
+
const url = args[0];
|
|
403
|
+
if (!url) {
|
|
404
|
+
return { error: 'Usage: fetch <url>', exitCode: 1 };
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
try {
|
|
408
|
+
const response = await fetch(url);
|
|
409
|
+
const data = await response.json();
|
|
410
|
+
return { output: JSON.stringify(data, null, 2), exitCode: 0 };
|
|
411
|
+
} catch (error) {
|
|
412
|
+
return { error: `Fetch failed: ${error.message}`, exitCode: 1 };
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
if (command === 'sleep') {
|
|
417
|
+
const seconds = parseInt(args[0]) || 1;
|
|
418
|
+
await new Promise((resolve) => setTimeout(resolve, seconds * 1000));
|
|
419
|
+
return { output: `Slept for ${seconds} seconds`, exitCode: 0 };
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
return { error: `Unknown command: ${command}`, exitCode: 127 };
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
</script>
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
## Browser Support
|
|
429
|
+
|
|
430
|
+
Works in all modern browsers that support:
|
|
431
|
+
- Custom Elements v1
|
|
432
|
+
- Shadow DOM
|
|
433
|
+
- ES2020+
|
|
434
|
+
|
|
435
|
+
## TypeScript
|
|
436
|
+
|
|
437
|
+
Full TypeScript support with exported types:
|
|
438
|
+
|
|
439
|
+
```typescript
|
|
440
|
+
import type {
|
|
441
|
+
SniceTerminalElement,
|
|
442
|
+
TerminalLine,
|
|
443
|
+
TerminalLineType,
|
|
444
|
+
TerminalCommandRequest,
|
|
445
|
+
TerminalCommandResponse,
|
|
446
|
+
} from 'snice/terminal';
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
## Security Note
|
|
450
|
+
|
|
451
|
+
The terminal uses `unsafeHTML` for rendering ANSI-colored output. Only use trusted content or sanitize user input before displaying.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "snice",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Imperative TypeScript framework for building vanilla web components with decorators, differential rendering, routing, and controllers. No virtual DOM, no build complexity.",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { SniceActionsElement, ActionButton, ActionButtonSize, ActionButtonVariant } from './snice-actions.types';
|
|
2
|
-
export declare class SniceActions extends HTMLElement implements SniceActionsElement {
|
|
3
|
-
actions: ActionButton[];
|
|
4
|
-
size: ActionButtonSize;
|
|
5
|
-
variant: ActionButtonVariant;
|
|
6
|
-
showLabels: boolean;
|
|
7
|
-
maxVisible: number;
|
|
8
|
-
moreLabel: string;
|
|
9
|
-
moreIcon: string;
|
|
10
|
-
private dropdownOpen;
|
|
11
|
-
private dispatchActionTrigger;
|
|
12
|
-
styles(): import("snice").CSSResult;
|
|
13
|
-
triggerAction(id: string): void;
|
|
14
|
-
getAction(id: string): ActionButton | undefined;
|
|
15
|
-
private handleActionClick;
|
|
16
|
-
private toggleDropdown;
|
|
17
|
-
private closeDropdown;
|
|
18
|
-
private renderActionButton;
|
|
19
|
-
template(): import("snice").TemplateResult;
|
|
20
|
-
init(): void;
|
|
21
|
-
cleanup(): void;
|
|
22
|
-
private handleOutsideClick;
|
|
23
|
-
}
|
|
24
|
-
declare global {
|
|
25
|
-
interface HTMLElementTagNameMap {
|
|
26
|
-
'snice-actions': SniceActions;
|
|
27
|
-
}
|
|
28
|
-
}
|