Workspaces and Terminals
This commit is contained in:
@@ -18,6 +18,7 @@ export type TerminalViewProps = {
|
||||
wsPath?: string;
|
||||
sessionId?: string;
|
||||
sandboxed?: boolean;
|
||||
cwd?: string;
|
||||
fontSize?: number;
|
||||
fontFamily?: string;
|
||||
theme?: TerminalTheme;
|
||||
@@ -34,13 +35,14 @@ const DEFAULT_THEME: Required<TerminalTheme> = {
|
||||
selectionBackground: '#3a3a5e',
|
||||
};
|
||||
|
||||
const buildWsUrl = (wsPath: string, sessionId?: string, sandboxed?: boolean) => {
|
||||
const buildWsUrl = (wsPath: string, sessionId?: string, sandboxed?: boolean, cwd?: string) => {
|
||||
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||
const token = localStorage.getItem('BEARER_TOKEN') ?? '';
|
||||
const separator = wsPath.includes('?') ? '&' : '?';
|
||||
let url = `${protocol}//${window.location.host}${wsPath}${separator}token=${encodeURIComponent(token)}`;
|
||||
if (sessionId) url += `&sessionId=${encodeURIComponent(sessionId)}`;
|
||||
if (sandboxed === false) url += '&sandboxed=false';
|
||||
if (cwd) url += `&cwd=${encodeURIComponent(cwd)}`;
|
||||
return url;
|
||||
};
|
||||
|
||||
@@ -50,6 +52,7 @@ export const TerminalView = ({
|
||||
wsPath = '/api/terminal/ws',
|
||||
sessionId,
|
||||
sandboxed = true,
|
||||
cwd,
|
||||
fontSize = 14,
|
||||
fontFamily = 'Menlo, Monaco, "Courier New", monospace',
|
||||
theme,
|
||||
@@ -99,6 +102,13 @@ export const TerminalView = ({
|
||||
const fitAddon = new FitAddon();
|
||||
term.loadAddon(fitAddon);
|
||||
term.open(container);
|
||||
|
||||
const viewport = container.querySelector('.xterm-viewport') as HTMLElement | null;
|
||||
if (viewport) {
|
||||
viewport.style.scrollbarWidth = 'none';
|
||||
viewport.style.overflow = 'hidden';
|
||||
}
|
||||
|
||||
fitAddon.fit();
|
||||
if (autoFocus) term.focus();
|
||||
|
||||
@@ -106,7 +116,7 @@ export const TerminalView = ({
|
||||
fitAddonRef.current = fitAddon;
|
||||
onReadyRef.current?.(term);
|
||||
|
||||
const ws = new WebSocket(buildWsUrl(wsPath, sessionId, sandboxed));
|
||||
const ws = new WebSocket(buildWsUrl(wsPath, sessionId, sandboxed, cwd));
|
||||
wsRef.current = ws;
|
||||
|
||||
const handleOpen = () => {
|
||||
@@ -180,6 +190,7 @@ export const TerminalView = ({
|
||||
wsPath,
|
||||
sessionId,
|
||||
sandboxed,
|
||||
cwd,
|
||||
fontSize,
|
||||
fontFamily,
|
||||
background,
|
||||
@@ -190,10 +201,8 @@ export const TerminalView = ({
|
||||
]);
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={containerRef}
|
||||
className={className}
|
||||
style={{ backgroundColor: background, ...style }}
|
||||
/>
|
||||
<div className={className} style={{ backgroundColor: background, overflow: 'hidden', ...style }}>
|
||||
<div ref={containerRef} style={{ width: '100%', height: '100%' }} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user