Terminal UI API Update
This commit is contained in:
114
README.md
114
README.md
@@ -405,8 +405,11 @@ Then link to it with `/portfolio#skills` - the page will scroll to that section
|
||||
src/lib/components/
|
||||
├── TerminalTUI.svelte # Main terminal container
|
||||
└── tui/
|
||||
├── types.ts # TypeScript types
|
||||
├── types.ts # TypeScript types (TerminalLine, TerminalAPI, etc.)
|
||||
├── utils.ts # Parsing & styling utilities
|
||||
├── terminal-api.ts # Terminal API factory for reactive control
|
||||
├── terminal-typing.ts # Typing animation engine
|
||||
├── terminal-keyboard.ts# Keyboard navigation handler
|
||||
├── TuiHeader.svelte # Top status bar
|
||||
├── TuiBody.svelte # Scrollable content area
|
||||
├── TuiFooter.svelte # Bottom status bar
|
||||
@@ -419,6 +422,115 @@ src/lib/components/
|
||||
└── TuiTooltip.svelte # Hover tooltip
|
||||
```
|
||||
|
||||
## Terminal API
|
||||
|
||||
The `TerminalTUI` component exposes a reactive API for programmatic control via the `terminal` bindable prop.
|
||||
|
||||
### Setup
|
||||
|
||||
```svelte
|
||||
<script lang="ts">
|
||||
import TerminalTUI from '$lib/components/TerminalTUI.svelte';
|
||||
import type { TerminalAPI, TerminalLine } from '$lib';
|
||||
|
||||
let terminal = $state<TerminalAPI>();
|
||||
let lines = $state<TerminalLine[]>([
|
||||
{ type: 'output', content: 'Hello world!' }
|
||||
]);
|
||||
</script>
|
||||
|
||||
<TerminalTUI bind:terminal bind:lines title="~/demo" />
|
||||
```
|
||||
|
||||
### API Methods
|
||||
|
||||
#### Writing Lines
|
||||
| Method | Description |
|
||||
|--------|-------------|
|
||||
| `terminal.write(line)` | Append a single line |
|
||||
| `terminal.writeLines(lines)` | Append multiple lines |
|
||||
| `terminal.clear()` | Remove all lines |
|
||||
| `terminal.setLines(lines)` | Replace all lines |
|
||||
|
||||
#### Updating Lines
|
||||
| Method | Description |
|
||||
|--------|-------------|
|
||||
| `terminal.update(index, updates)` | Update line by index with partial changes |
|
||||
| `terminal.updateContent(index, content)` | Update just the content of a line |
|
||||
| `terminal.updateById(id, updates)` | Update line by its `id` property |
|
||||
|
||||
#### Removing Lines
|
||||
| Method | Description |
|
||||
|--------|-------------|
|
||||
| `terminal.remove(index)` | Remove line at index |
|
||||
| `terminal.removeRange(start, count)` | Remove a range of lines |
|
||||
| `terminal.removeById(id)` | Remove line by its `id` property |
|
||||
|
||||
#### Inserting Lines
|
||||
| Method | Description |
|
||||
|--------|-------------|
|
||||
| `terminal.insert(index, line)` | Insert line at a specific index |
|
||||
|
||||
#### Reading State
|
||||
| Method | Description |
|
||||
|--------|-------------|
|
||||
| `terminal.getLine(index)` | Get line at index |
|
||||
| `terminal.getLines()` | Get all lines (copy) |
|
||||
| `terminal.getLineCount()` | Get number of lines |
|
||||
| `terminal.findById(id)` | Find index of line by id |
|
||||
| `terminal.isAnimating()` | Check if typing animation is active |
|
||||
|
||||
#### Navigation & Control
|
||||
| Method | Description |
|
||||
|--------|-------------|
|
||||
| `terminal.scrollToBottom()` | Scroll to bottom of terminal |
|
||||
| `terminal.scrollToLine(index)` | Scroll to specific line |
|
||||
| `terminal.skip()` | Skip current typing animation |
|
||||
| `terminal.restart()` | Restart typing animation from beginning |
|
||||
|
||||
### Example: Dynamic Updates
|
||||
|
||||
```svelte
|
||||
<script lang="ts">
|
||||
import TerminalTUI from '$lib/components/TerminalTUI.svelte';
|
||||
import type { TerminalAPI } from '$lib';
|
||||
|
||||
let terminal = $state<TerminalAPI>();
|
||||
let lines = $state([
|
||||
{ type: 'output', content: 'Initializing...', id: 'status' }
|
||||
]);
|
||||
|
||||
async function runProcess() {
|
||||
// Update existing line
|
||||
terminal?.updateById('status', {
|
||||
type: 'info',
|
||||
content: 'Processing...'
|
||||
});
|
||||
|
||||
await delay(1000);
|
||||
|
||||
// Add progress
|
||||
terminal?.write({
|
||||
type: 'progress',
|
||||
content: '',
|
||||
progress: 50,
|
||||
progressLabel: '50%'
|
||||
});
|
||||
|
||||
await delay(1000);
|
||||
|
||||
// Complete
|
||||
terminal?.updateById('status', {
|
||||
type: 'success',
|
||||
content: 'Complete!'
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<TerminalTUI bind:terminal bind:lines />
|
||||
<button onclick={runProcess}>Start</button>
|
||||
```
|
||||
|
||||
## 3D Model Viewer
|
||||
|
||||
The `ModelViewer` component provides an interactive Three.js viewer for `.glb` models.
|
||||
|
||||
Reference in New Issue
Block a user