|
|
|
@@ -246,8 +246,6 @@ export const TerminalComponent: React.FC<TerminalProps> = ({
|
|
|
|
|
// Define fitTerminal before connectWebSocket so it's available in onmessage
|
|
|
|
|
const fitTerminal = () => {
|
|
|
|
|
if (!fitAddonRef.current || !termRef.current) return;
|
|
|
|
|
// Ensure terminal is opened and has valid dimensions
|
|
|
|
|
if (termRef.current.cols === 0 || termRef.current.rows === 0) return;
|
|
|
|
|
const oldCols = termRef.current.cols;
|
|
|
|
|
const oldRows = termRef.current.rows;
|
|
|
|
|
try {
|
|
|
|
@@ -257,8 +255,9 @@ export const TerminalComponent: React.FC<TerminalProps> = ({
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const { cols, rows } = termRef.current;
|
|
|
|
|
// Force refresh if dimensions changed and are valid
|
|
|
|
|
if ((cols !== oldCols || rows !== oldRows) && cols > 0 && rows > 0) {
|
|
|
|
|
console.log(`[Terminal] fit() result: ${cols}x${rows} (was ${oldCols}x${oldRows})`);
|
|
|
|
|
// Force refresh if dimensions are valid
|
|
|
|
|
if (cols > 0 && rows > 0) {
|
|
|
|
|
try {
|
|
|
|
|
termRef.current.refresh(0, rows - 1);
|
|
|
|
|
} catch {
|
|
|
|
@@ -266,7 +265,7 @@ export const TerminalComponent: React.FC<TerminalProps> = ({
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const currentWs = wsRef.current;
|
|
|
|
|
if (currentWs?.readyState === WebSocket.OPEN) {
|
|
|
|
|
if (currentWs?.readyState === WebSocket.OPEN && cols > 0 && rows > 0) {
|
|
|
|
|
currentWs.send(JSON.stringify({ type: "resize", cols, rows }));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
@@ -276,14 +275,20 @@ export const TerminalComponent: React.FC<TerminalProps> = ({
|
|
|
|
|
ws = connectWebSocket();
|
|
|
|
|
|
|
|
|
|
// Initial fit after layout settles (terminal must be opened first)
|
|
|
|
|
let fitAttempts = 0;
|
|
|
|
|
const doInitialFit = () => {
|
|
|
|
|
if (!container.isConnected) return;
|
|
|
|
|
fitAttempts++;
|
|
|
|
|
// Ensure container has dimensions before fitting
|
|
|
|
|
if (container.clientWidth > 0 && container.clientHeight > 0) {
|
|
|
|
|
console.log(`[Terminal] Container ready: ${container.clientWidth}x${container.clientHeight} (attempt ${fitAttempts})`);
|
|
|
|
|
fitTerminal();
|
|
|
|
|
} else {
|
|
|
|
|
// Container not ready yet, try again
|
|
|
|
|
} else if (fitAttempts < 50) {
|
|
|
|
|
// Container not ready yet, try again (max 50 attempts ~ 1s)
|
|
|
|
|
console.log(`[Terminal] Container not ready: ${container.clientWidth}x${container.clientHeight} (attempt ${fitAttempts})`);
|
|
|
|
|
requestAnimationFrame(doInitialFit);
|
|
|
|
|
} else {
|
|
|
|
|
console.warn(`[Terminal] Container never got dimensions after ${fitAttempts} attempts`);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
requestAnimationFrame(doInitialFit);
|
|
|
|
|