feat(web): add xterm terminal panel (#5)
Use @xterm/xterm for terminal emulation and its official @xterm/addon-fit for container sizing. Lazy-load both on first open to keep them out of the main bundle. Preserve the mounted terminal on collapse and offer explicit reconnect; provide an echo transport for demos.
This commit is contained in:
+13
-3
@@ -29,7 +29,9 @@ import type { Api } from "./api";
|
||||
import { emptySession, eventReducer, stepKey } from "./events";
|
||||
import { ParamsForm } from "./ParamsForm";
|
||||
import { StepCard } from "./StepCard";
|
||||
import { TerminalSlot } from "./TerminalSlot";
|
||||
const TerminalSlot = lazy(() =>
|
||||
import("./TerminalSlot").then((module) => ({ default: module.TerminalSlot })),
|
||||
);
|
||||
const Editor = lazy(() =>
|
||||
import("./Editor").then((module) => ({ default: module.Editor })),
|
||||
);
|
||||
@@ -53,6 +55,7 @@ export function App({ api }: { api: Api }) {
|
||||
const [values, setValues] = useState<ParamValues>({});
|
||||
const [edit, setEdit] = useState(false);
|
||||
const [terminal, setTerminal] = useState(false);
|
||||
const [terminalOpened, setTerminalOpened] = useState(false);
|
||||
const [conflict, setConflict] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
const [connected, setConnected] = useState(false);
|
||||
@@ -348,7 +351,10 @@ export function App({ api }: { api: Api }) {
|
||||
</button>
|
||||
<button
|
||||
aria-expanded={terminal}
|
||||
onClick={() => setTerminal(!terminal)}
|
||||
onClick={() => {
|
||||
setTerminalOpened(true);
|
||||
setTerminal(!terminal);
|
||||
}}
|
||||
>
|
||||
Terminal {terminal ? "→" : "←"}
|
||||
</button>
|
||||
@@ -460,7 +466,11 @@ export function App({ api }: { api: Api }) {
|
||||
</>
|
||||
)}
|
||||
</main>
|
||||
{terminal && <TerminalSlot />}
|
||||
{terminalOpened && (
|
||||
<Suspense fallback={<p>Loading terminal...</p>}>
|
||||
<TerminalSlot collapsed={!terminal} />
|
||||
</Suspense>
|
||||
)}
|
||||
{confirm && (
|
||||
<div className="modal-backdrop">
|
||||
<section
|
||||
|
||||
Reference in New Issue
Block a user