import type { RefObject } from "react"; import type { Terminal as XTerm } from "@xterm/xterm"; import type { Host } from "../../../types"; import { markPromptLineBreakCommandPending, type PromptLineBreakState, } from "./promptLineBreak"; type TerminalCommandExecutionContext = { host: Pick; sessionId: string; onCommandExecuted?: ( command: string, hostId: string, hostLabel: string, sessionId: string, ) => void; commandBufferRef: RefObject; promptLineBreakStateRef?: RefObject; }; export const recordTerminalCommandExecution = ( command: string, ctx: TerminalCommandExecutionContext, term?: XTerm | null, ) => { const cmd = command.trim(); if (cmd) { ctx.onCommandExecuted?.(cmd, ctx.host.id, ctx.host.label, ctx.sessionId); } ctx.commandBufferRef.current = ""; markPromptLineBreakCommandPending(ctx.promptLineBreakStateRef, term, command); };