"use client"; import { useEffect, useRef, useState } from "react"; import { DebugValue } from "mtxuilib/components/devtools/DebugValue"; import { cn } from "mtxuilib/lib/utils"; import { Button } from "mtxuilib/ui/button"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "mtxuilib/ui/tabs"; import { Terminal, type TerminalRef, } from "../workbench/webcontainer_workbench/terminal/Terminal"; import { type MtmaiBotProps, XtermProvider, useXtermStore, } from "./xterm.store"; interface ShellExecViewProps { cmdLine: string; execApiEndpoint: string; label: string; } export function ShellExecView({ cmdLine, execApiEndpoint, label, }: ShellExecViewProps) { const [listItem, setListItem] = useState([]); return ( ); } const ShellExecViewImpl = (props: MtmaiBotProps) => { const { connected, connecting, error, socket } = useXtermStore(); const cmd = useXtermStore((x) => x.cmd); const listItem = useXtermStore((x) => x.listItem); const send = useXtermStore((x) => x.send); const initCmd = useXtermStore((x) => x.initCmd); const terminalRefs = useRef>([]); const terminalRef = useRef(null); const terminal = useXtermStore((x) => x.terminal); const connect = useXtermStore((x) => x.connect); const attachTerminal = useXtermStore((x) => x.attachTerminal); const theme = "light"; // biome-ignore lint/correctness/useExhaustiveDependencies: useEffect(() => { connect(); }, []); return ( <>
{error ? ( {error} ) : connecting ? ( 正在连接... ) : connected ? ( ) : ( )}
终端 消息
{ terminalRefs.current.push(ref); }} onTerminalReady={(terminal) => { console.log("onTerminalReady", terminal); // workbenchStore.attachTerminal(terminal) // terminalRef.current = ref; attachTerminal(terminal); }} onTerminalResize={(cols, rows) => { // workbenchStore.onTerminalResize(cols, rows); }} theme={theme} />
{listItem?.length > 0 ? (
{listItem?.map((item, i) => ( // biome-ignore lint/suspicious/noArrayIndexKey:
{item}
))}
) : null}
); };