feat(electrobun): full UI — terminal tabs, agent pane, settings, palette

Extracted into 6 components:
- ProjectCard.svelte: header with badges, tab bar, content area
- AgentPane.svelte: collapsible tool calls, status strip, prompt input
- TerminalTabs.svelte: add/close shell tabs, active highlighting
- SettingsDrawer.svelte: theme, fonts, providers
- CommandPalette.svelte: Ctrl+K search overlay
- Terminal.svelte: xterm.js with Canvas + Image addons

Status bar: running/idle/stalled counts, attention queue, session
duration, notification bell, Ctrl+K hint. All ARIA labeled.
This commit is contained in:
Hibryda 2026-03-20 01:55:24 +01:00
parent 931bc1b94c
commit b11a856b72
11 changed files with 2001 additions and 220 deletions

View file

@ -0,0 +1,280 @@
<script lang="ts">
import Terminal from './Terminal.svelte';
interface Props {
projectId: string;
accent?: string;
}
let { projectId, accent = 'var(--ctp-mauve)' }: Props = $props();
interface TermTab {
id: string;
title: string;
}
// Capture stable initial value — projectId is a mount-time constant, not reactive
// svelte-ignore state_referenced_locally
const initialId = projectId;
const firstTabId = `${initialId}-t1`;
let tabs = $state<TermTab[]>([{ id: firstTabId, title: 'shell 1' }]);
let activeTabId = $state<string>(firstTabId);
let collapsed = $state(false);
let counter = $state(2);
// Track which tabs have been mounted at least once (for lazy init)
let mounted = $state<Set<string>>(new Set([firstTabId]));
function addTab() {
const id = `${projectId}-t${counter}`;
tabs = [...tabs, { id, title: `shell ${counter}` }];
counter++;
activeTabId = id;
mounted = new Set([...mounted, id]);
}
function closeTab(id: string, e: MouseEvent) {
e.stopPropagation();
const idx = tabs.findIndex(t => t.id === id);
tabs = tabs.filter(t => t.id !== id);
if (activeTabId === id) {
// activate neighbor
const next = tabs[Math.min(idx, tabs.length - 1)];
activeTabId = next?.id ?? '';
}
// Remove from mounted to free resources
const m = new Set(mounted);
m.delete(id);
mounted = m;
}
function activateTab(id: string) {
activeTabId = id;
// Mount on first activation
if (!mounted.has(id)) {
mounted = new Set([...mounted, id]);
}
}
function toggleCollapse() {
collapsed = !collapsed;
}
</script>
<div class="terminal-section" style="--accent: {accent}">
<!-- Section header: collapse toggle + terminal tabs -->
<div class="term-section-header">
<button
class="collapse-btn"
onclick={toggleCollapse}
aria-label={collapsed ? 'Expand terminals' : 'Collapse terminals'}
aria-expanded={!collapsed}
title={collapsed ? 'Expand' : 'Collapse'}
>
<svg
class="chevron"
class:rotated={collapsed}
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<polyline points="6 9 12 15 18 9"/>
</svg>
</button>
<!-- Tab pills -->
<div class="term-tabs" role="tablist" aria-label="Terminal tabs">
{#each tabs as tab (tab.id)}
<button
class="term-tab"
class:active={activeTabId === tab.id}
role="tab"
aria-selected={activeTabId === tab.id}
onclick={() => activateTab(tab.id)}
title={tab.title}
>
<span class="term-tab-title">{tab.title}</span>
{#if tabs.length > 1}
<span
class="term-tab-close"
role="button"
tabindex="0"
aria-label="Close {tab.title}"
onclick={(e) => closeTab(tab.id, e)}
onkeydown={(e) => e.key === 'Enter' && closeTab(tab.id, e as unknown as MouseEvent)}
>×</span>
{/if}
</button>
{/each}
<button
class="term-tab-add"
onclick={addTab}
aria-label="Add terminal tab"
title="New terminal"
>+</button>
</div>
</div>
<!-- Terminal panes: display:flex/none to preserve xterm state -->
{#if !collapsed}
<div class="term-panes">
{#each tabs as tab (tab.id)}
{#if mounted.has(tab.id)}
<div
class="term-pane"
style:display={activeTabId === tab.id ? 'flex' : 'none'}
role="tabpanel"
aria-label={tab.title}
>
<Terminal />
</div>
{/if}
{/each}
</div>
{/if}
</div>
<style>
.terminal-section {
display: flex;
flex-direction: column;
border-top: 1px solid var(--ctp-surface0);
flex-shrink: 0;
background: var(--ctp-crust);
}
/* Section header: collapse + tabs in one row */
.term-section-header {
display: flex;
align-items: stretch;
height: 1.875rem;
background: var(--ctp-mantle);
border-bottom: 1px solid var(--ctp-surface0);
flex-shrink: 0;
}
.collapse-btn {
width: 2rem;
flex-shrink: 0;
background: transparent;
border: none;
border-right: 1px solid var(--ctp-surface0);
color: var(--ctp-overlay1);
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
transition: color 0.12s;
padding: 0;
}
.collapse-btn:hover { color: var(--ctp-text); }
.collapse-btn svg {
width: 0.875rem;
height: 0.875rem;
transition: transform 0.15s;
}
.chevron.rotated {
transform: rotate(-90deg);
}
/* Tab pills */
.term-tabs {
display: flex;
align-items: stretch;
flex: 1;
overflow-x: auto;
scrollbar-width: none;
gap: 0.125rem;
padding: 0 0.25rem;
}
.term-tabs::-webkit-scrollbar { display: none; }
.term-tab {
display: flex;
align-items: center;
gap: 0.25rem;
padding: 0 0.5rem;
background: transparent;
border: none;
border-bottom: 2px solid transparent;
color: var(--ctp-subtext0);
font-family: var(--ui-font-family);
font-size: 0.75rem;
cursor: pointer;
white-space: nowrap;
transition: color 0.1s, border-color 0.1s;
margin-bottom: -1px;
}
.term-tab:hover { color: var(--ctp-text); }
.term-tab.active {
color: var(--ctp-text);
border-bottom-color: var(--accent, var(--ctp-mauve));
}
.term-tab-title { pointer-events: none; }
.term-tab-close {
display: flex;
align-items: center;
justify-content: center;
width: 1rem;
height: 1rem;
border-radius: 0.2rem;
font-size: 0.75rem;
color: var(--ctp-overlay0);
transition: background 0.1s, color 0.1s;
cursor: pointer;
}
.term-tab-close:hover {
background: var(--ctp-surface1);
color: var(--ctp-red);
}
.term-tab-add {
align-self: center;
width: 1.375rem;
height: 1.375rem;
flex-shrink: 0;
background: transparent;
border: 1px solid var(--ctp-surface1);
border-radius: 0.25rem;
color: var(--ctp-overlay1);
font-size: 0.875rem;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
transition: background 0.1s, color 0.1s;
margin-left: 0.125rem;
}
.term-tab-add:hover {
background: var(--ctp-surface0);
color: var(--ctp-text);
}
/* Terminal pane container */
.term-panes {
height: 12rem;
min-height: 8rem;
position: relative;
}
.term-pane {
position: absolute;
inset: 0;
flex-direction: column;
}
</style>