Add frontend app with terminal UI, sandbox integration, and asset handling.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
OverlordandClaude Bot committed 2026-10-13 10:36:23 +02:00
1 parent 91049379f7
commit b841c2d1f6
19 files changed
+800 -13

No files matched your search

+95
View File
@@ -0,0 +1,95 @@
import '@fontsource/jetbrains-mono/400.css';
import '@fontsource/jetbrains-mono/700.css';
import '@xterm/xterm/css/xterm.css';
import './style.css';
import { FitAddon } from '@xterm/addon-fit';
import { WebLinksAddon } from '@xterm/addon-web-links';
import { WebglAddon } from '@xterm/addon-webgl';
import { Terminal } from '@xterm/xterm';
import { CONNECTING_MESSAGE, endMessage, playBoot } from './boot.ts';
import { TerminalConnection, terminalUrl } from './connection.ts';
import { createKeybar } from './keybar.ts';
type State = 'booting' | 'idle' | 'connecting' | 'active';
const touch = window.matchMedia('(pointer: coarse)').matches;
const element = document.getElementById('terminal')!;
const terminal = new Terminal({
fontFamily: '"JetBrains Mono", monospace',
fontSize: touch ? 13 : 15,
cursorBlink: true,
scrollback: 5000,
theme: {
background: '#0b0d10',
foreground: '#d6dde6',
cursor: '#7ee787',
selectionBackground: '#2b3a4a',
},
});
// The key bar takes its space before the first fit, so the grid never overflows.
if (touch)
{
createKeybar(document.getElementById('keybar')!, () => terminal.modes.applicationCursorKeysMode, input);
element.addEventListener('click', () => { if (state === 'idle') start(); });
}
const fit = new FitAddon();
terminal.loadAddon(fit);
terminal.loadAddon(new WebLinksAddon());
// Measuring cells before the font is ready would size the grid wrongly.
await Promise.all([document.fonts.load('15px "JetBrains Mono"'), document.fonts.load('bold 15px "JetBrains Mono"')]);
terminal.open(element);
try
{
const webgl = new WebglAddon();
webgl.onContextLoss(() => webgl.dispose());
terminal.loadAddon(webgl);
}
catch { /* The DOM renderer remains as a fallback without WebGL. */ }
fit.fit();
terminal.focus();
let state: State = 'booting';
let connection: TerminalConnection | undefined;
function start(): void
{
state = 'connecting';
terminal.write(CONNECTING_MESSAGE);
connection = new TerminalConnection(terminalUrl(window.location), { cols: terminal.cols, rows: terminal.rows }, {
ready: () =>
{
state = 'active';
terminal.reset();
terminal.focus();
},
output: (data) => terminal.write(data),
ended: (reason) =>
{
state = 'idle';
connection = undefined;
terminal.write(endMessage(reason, touch));
},
});
}
function input(data: string): void
{
if (state === 'active') connection?.input(data);
else if (state === 'idle') start();
}
terminal.onData(input);
terminal.onBinary((data) => { if (state === 'active') connection?.inputBinary(data); });
terminal.onResize(({ cols, rows }) => connection?.resize({ cols, rows }));
new ResizeObserver(() => fit.fit()).observe(element);
await playBoot(terminal, touch);
state = 'idle';