From 82d896a38ef63d04d29a68cea534005ea1b02641 Mon Sep 17 00:00:00 2001 From: Sir Blob Date: Sat, 29 Nov 2025 03:53:21 +0000 Subject: [PATCH] Terminal UI API Update --- README.md | 114 ++++++- src/lib/components/TerminalTUI.svelte | 348 ++++++-------------- src/lib/components/tui/terminal-api.ts | 245 ++++++++++++++ src/lib/components/tui/terminal-keyboard.ts | 148 +++++++++ src/lib/components/tui/terminal-typing.ts | 222 +++++++++++++ src/lib/components/tui/types.ts | 44 +++ src/lib/config/index.ts | 2 +- src/lib/config/terminal.ts | 16 +- src/lib/index.ts | 3 + src/lib/pages/components.ts | 60 ++++ src/routes/components/+page.svelte | 2 +- src/routes/models/+page.svelte | 2 +- src/routes/projects/+page.svelte | 2 +- 13 files changed, 952 insertions(+), 256 deletions(-) create mode 100644 src/lib/components/tui/terminal-api.ts create mode 100644 src/lib/components/tui/terminal-keyboard.ts create mode 100644 src/lib/components/tui/terminal-typing.ts diff --git a/README.md b/README.md index 22cd113..3c80d66 100644 --- a/README.md +++ b/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 + + + +``` + +### 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 + + + + +``` + ## 3D Model Viewer The `ModelViewer` component provides an interactive Three.js viewer for `.glb` models. diff --git a/src/lib/components/TerminalTUI.svelte b/src/lib/components/TerminalTUI.svelte index 4047da4..8acd06a 100644 --- a/src/lib/components/TerminalTUI.svelte +++ b/src/lib/components/TerminalTUI.svelte @@ -1,17 +1,18 @@ - Components | {user.name} + Components | {user.displayname} diff --git a/src/routes/models/+page.svelte b/src/routes/models/+page.svelte index b752520..2bb7fd3 100644 --- a/src/routes/models/+page.svelte +++ b/src/routes/models/+page.svelte @@ -61,7 +61,7 @@ - 3D Models | {user.name} + 3D Models | {user.displayname} diff --git a/src/routes/projects/+page.svelte b/src/routes/projects/+page.svelte index 419821b..0343289 100644 --- a/src/routes/projects/+page.svelte +++ b/src/routes/projects/+page.svelte @@ -9,7 +9,7 @@ - Projects | {user.name} + Projects | {user.displayname}