({
ref,
agentId,
operatingSystem,
className,
autoFocus = true,
isVisible = true,
initialCommand,
containerName,
containerUser,
onStatusChange,
onError,
reconnectionToken,
baseUrl,
terminalFontFamily = DEFAULT_TERMINAL_FONT_FAMILY,
renderer,
backgroundColor,
onOpenLink,
loading = false,
errorMessage,
testId,
}: WorkspaceTerminalProps)
| 69 | }; |
| 70 | |
| 71 | export const WorkspaceTerminal = ({ |
| 72 | ref, |
| 73 | agentId, |
| 74 | operatingSystem, |
| 75 | className, |
| 76 | autoFocus = true, |
| 77 | isVisible = true, |
| 78 | initialCommand, |
| 79 | containerName, |
| 80 | containerUser, |
| 81 | onStatusChange, |
| 82 | onError, |
| 83 | reconnectionToken, |
| 84 | baseUrl, |
| 85 | terminalFontFamily = DEFAULT_TERMINAL_FONT_FAMILY, |
| 86 | renderer, |
| 87 | backgroundColor, |
| 88 | onOpenLink, |
| 89 | loading = false, |
| 90 | errorMessage, |
| 91 | testId, |
| 92 | }: WorkspaceTerminalProps) => { |
| 93 | const scopeId = useId(); |
| 94 | const terminalWrapperRef = useRef<HTMLDivElement>(null); |
| 95 | const fitAddonRef = useRef<FitAddon | undefined>(undefined); |
| 96 | const websocketRef = useRef<Websocket | undefined>(undefined); |
| 97 | const handleOpenLink = useEffectEvent((uri: string) => { |
| 98 | onOpenLink ? onOpenLink(uri) : window.open(uri, "_blank", "noopener"); |
| 99 | }); |
| 100 | const handleStatusChange = useEffectEvent((status: ConnectionStatus) => { |
| 101 | onStatusChange?.(status); |
| 102 | }); |
| 103 | const [terminal, setTerminal] = useState<Terminal>(); |
| 104 | const { copyToClipboard, readFromClipboard } = useClipboard(); |
| 105 | |
| 106 | const [hasSelection, setHasSelection] = useState(false); |
| 107 | const handleContextMenuOpenChange = (open: boolean) => { |
| 108 | if (open) { |
| 109 | setHasSelection(Boolean(terminal?.hasSelection())); |
| 110 | } |
| 111 | }; |
| 112 | const copyTerminalSelection = () => { |
| 113 | const selection = terminal?.getSelection(); |
| 114 | if (selection) { |
| 115 | void copyToClipboard(selection); |
| 116 | } |
| 117 | }; |
| 118 | const pasteIntoTerminal = async () => { |
| 119 | if (!terminal) { |
| 120 | return; |
| 121 | } |
| 122 | try { |
| 123 | const text = await readFromClipboard(); |
| 124 | if (text) { |
| 125 | terminal.paste(text); |
| 126 | } |
| 127 | } catch (error) { |
| 128 | toast.error("Failed to paste from clipboard"); |
nothing calls this directly
no test coverage detected