Sync CloudShell backend PTY size on terminal resize (#2553)

* Sync CloudShell backend PTY size on terminal resize

Resizing the browser window only re-fit the local xterm; the remote shell kept its original column count, so typed input wrapped/broke at the wrong column. Add resizeTerminal() client call to the CloudShell terminals/{id}/size endpoint and register a debounced terminal.onResize handler that pushes new dimensions to the backend.

* Add unit tests for registerTerminalResizeHandler (debounce, no-op skip, error handling)

* Fix resizeTerminal success test: stub a successful fetch response
This commit is contained in:
Mike Krüger
2026-08-17 10:15:33 +02:00
committed by GitHub
parent 2834bf0fd4
commit 12ad23a061
4 changed files with 252 additions and 2 deletions
@@ -125,3 +125,27 @@ export const connectTerminal = async (
return resp.json();
};
export const resizeTerminal = async (
consoleUri: string,
terminalId: string,
size: { rows: number; cols: number },
): Promise<void> => {
const targetUri = consoleUri + `/terminals/${terminalId}/size?cols=${size.cols}&rows=${size.rows}&version=2019-01-01`;
const resp = await fetch(targetUri, {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
"Content-Length": "2",
Authorization: userContext.authorizationToken,
"x-ms-client-request-id": uuidv4(),
"Accept-Language": getLocale(),
},
body: "{}", // empty body is necessary
});
if (!resp.ok) {
throw new Error(`Failed to resize terminal: ${resp.status} ${resp.statusText}`);
}
};