MCPcopy Index your code
hub / github.com/coder/coder / WorkspaceTerminal

Function WorkspaceTerminal

site/src/modules/terminal/WorkspaceTerminal.tsx:71–584  ·  view source on GitHub ↗
({
	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)

Source from the content-addressed store, hash-verified

69};
70
71export 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");

Callers

nothing calls this directly

Calls 15

useClipboardFunction · 0.90
isMacFunction · 0.90
terminalWebsocketUrlFunction · 0.90
cnFunction · 0.90
handleOpenLinkFunction · 0.85
encodeTerminalPayloadFunction · 0.85
copySelectionFunction · 0.85
scheduleTerminalResizeFunction · 0.85
pasteIntoTerminalFunction · 0.85
openMethod · 0.80
disposeMethod · 0.80
clearMethod · 0.80

Tested by

no test coverage detected