status bar

This commit is contained in:
2026-11-04 00:01:11 +01:00
parent d6cfab838f
commit 2a0d54c19e
11 changed files with 460 additions and 208 deletions
+19 -9
View File
@@ -1,17 +1,18 @@
<script lang="ts">
import { petals } from '#lib/stores/petals.ts';
import { onMount } from 'svelte';
let {
value = $bindable(''),
blinkDelay = 250,
autofocus = true,
oninput = () => {}
oninput = () => {},
onsubmit = () => {}
}: {
value?: string;
blinkDelay?: number;
autofocus?: boolean;
oninput?: (value: string) => void;
onsubmit?: (value: string) => void;
} = $props();
let container: HTMLElement;
@@ -46,7 +47,7 @@
e.ctrlKey ? moveTo(nextWordBoundary(cursorPos), e.shiftKey) : moveCursor(1, e.shiftKey),
Backspace: () => deleteCharBefore(),
Delete: () => deleteCharAfter(),
Enter: () => gust()
Enter: () => submit()
};
let selection = $derived.by(() => {
@@ -64,9 +65,16 @@
return selection.active && i >= selection.start && i < selection.end;
}
function submit(): void {
onsubmit?.(value);
value = '';
cursorPos = 0;
anchorPos = null;
}
function gust(): void {
if (!container) return;
petals(container, { duration: 4000, swayAmp: 26, hideOriginals: false });
//petals(container, { duration: 4000, swayAmp: 26, hideOriginals: false });
value = '';
cursorPos = 0;
anchorPos = null;
@@ -237,6 +245,7 @@
function handleMouseDown(e: MouseEvent): void {
e.preventDefault();
container?.focus();
const idx = charIndexFromEvent(e);
const clickPos = idx ?? value.length;
@@ -294,7 +303,7 @@
<div
id="terminal-input"
class="font-terminal relative inline-block whitespace-nowrap outline-none select-none"
class="relative inline-block font-mono whitespace-nowrap outline-none select-none"
bind:this={container}
tabindex="1"
role="textbox"
@@ -306,11 +315,12 @@
onmousedown={handleMouseDown}
style="--cursor-index: {cursorPos};"
>
<span class="prompt inline-block w-[1ch] text-center">$</span>
<!-- <span class="text-fg-dim inline-block">~/Downloads</span> -->
<span class="prompt text-fg inline-block w-[1ch] text-center">$</span>
<span class="inline cursor-text" aria-hidden="true">
{#each value.split('') as char, i}
<span
class="char inline-block w-[1ch] text-center whitespace-pre"
class="char text-glow inline-block w-[1ch] text-center leading-relaxed whitespace-pre-wrap"
class:selected={isSelected(i)}
data-char-index={i}>{char}</span
>
@@ -318,7 +328,7 @@
</span>
<div
id="curs"
class="cursor bg-text-primary absolute bottom-[0.2rem] h-px w-[1ch]"
class="cursor bg-fg absolute bottom-1 h-px w-[1ch]"
class:animate-cursor-blink={!blinkPaused && !selection.active}
></div>
</div>
@@ -334,7 +344,7 @@
.char.selected {
transition: none;
background-color: var(--color-highlight);
background-color: var(--);
border-radius: 2px;
}
+118
View File
@@ -0,0 +1,118 @@
<script lang="ts">
let { username, theme, windowCount, version, hash } = $props();
// Internal clock — ticked every 30s so it doesn't go stale if mounted long.
let now = $state(new Date());
let init = new Date().getTime();
let ms = $state(new Date().getTime());
function formatUptime(ms: number): string {
const totalSec = Math.floor(ms / 1000);
const d = Math.floor(totalSec / 86400);
const h = Math.floor((totalSec % 86400) / 3600);
const m = Math.floor((totalSec % 3600) / 60);
const s = totalSec % 60;
const pad = (n: number) => String(n).padStart(2, '0');
return d > 0 ? `${d}d ${h}:${pad(m)}:${pad(s)}` : `${h}:${pad(m)}:${pad(s)}`;
}
$effect(() => {
const id = setInterval(() => (now = new Date()), 1000);
return () => clearInterval(id);
});
const weekday = $derived(now.toLocaleDateString('en-US', { weekday: 'short' }));
const time = $derived(
`${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}`
);
const uptime = $derived(`up ${formatUptime(now.getTime() - init)}`);
</script>
{#snippet sep(cls: string = '')}
<span
aria-hidden="true"
class="text-bg3 text-[12px] leading-none {cls}"
style="font-family:ui-monospace,monospace">·</span
>
{/snippet}
{#snippet shortcut(keys: string, label: string)}
<span class="text-bg4 inline-flex items-center gap-0.75 whitespace-nowrap">
<kbd
class="border-bg1 text-fg2 inline-flex h-3.25 min-w-3.25 items-center justify-center rounded-[3px] border bg-black/25 px-1 text-[8.5px] leading-none font-medium"
>{keys}</kbd
>
<span class="text-fg4">{label}</span>
</span>
{/snippet}
<div
class="bg-bg-soft text-fg3 border-bg3 grid w-full grid-cols-[auto_1fr_auto_auto_auto] gap-x-2 overflow-hidden rounded-b-lg border-t text-[11px]"
style="font-family:-apple-system,BlinkMacSystemFont,system-ui,sans-serif; box-shadow: inset 0 1px 0 rgba(255,255,255,0.04), 0 -2px 0 0 rgba(0,0,0,0.1), 0 -6px 20px -4px rgba(0,0,0,0.5), 0 -16px 40px -12px rgba(0,0,0,0.65);"
role="region"
aria-label="System status bar"
>
<!-- Top row: user · theme · settings · time -->
<div
class="col-span-full grid h-[22px] grid-cols-subgrid items-center px-4.5 shadow-[inset_0_-1px_0_var(--bg2)]"
>
<div class="flex items-center gap-2 justify-self-end">
<span aria-hidden="true" class="bg-tgreen h-1.25 w-1.25 shrink-0 rounded-full"></span>
<span class="text-fg2 text-[10.5px] font-medium whitespace-nowrap">{username}</span>
</div>
<div class="flex min-w-0 items-center gap-2">
{@render sep()}
<span
class="text-fg3 hover:text-fg2 cursor-pointer text-[9.5px] whitespace-nowrap"
style="font-family:ui-monospace,monospace"
title="switch theme">{theme}</span
>
</div>
<button
type="button"
aria-label="Settings"
class="text-bg4 flex h-5 w-5 shrink-0 items-center justify-center justify-self-end rounded border-0 bg-transparent p-0 text-[12px]"
>⚙</button
>
{@render sep('justify-self-center')}
<time
datetime={now.toISOString()}
class="text-bg4 justify-self-start text-[9.5px] whitespace-nowrap"
style="font-family:ui-monospace,monospace"
>
<span class="text-fg3 font-medium">{weekday}</span>
{time}
</time>
</div>
<!-- Bottom row: windows · shortcuts · build · uptime -->
<div
class="col-span-full grid h-[22px] grid-cols-subgrid items-center rounded-b-lg px-4.5 text-[9.5px] whitespace-nowrap"
style="font-family:ui-monospace,monospace"
>
<span class="text-fg3 justify-self-end whitespace-nowrap"
><span class="font-medium">{windowCount}</span> window{windowCount === 1 ? '' : 's'}</span
>
<div class="flex min-w-0 items-center gap-2">
{@render sep()}
{@render shortcut('⌘N', 'new terminal')}
{@render sep()}
{@render shortcut('⌘,', 'settings')}
</div>
<span class="inline-flex items-center gap-1.25 justify-self-end">
<span class="text-fg3">{version}</span>
{@render sep()}
<span class="text-bg4">{hash}</span>
</span>
{@render sep('justify-self-center')}
<span class="text-bg4 justify-self-start">{uptime}</span>
</div>
</div>