Skip to content

Commit 6fb9e53

Browse files
committed
more terminal improvements
1 parent af4fcd9 commit 6fb9e53

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/packages/frontend/frame-editors/terminal-editor/connected-terminal.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ export class Terminal<T extends CodeEditorState = CodeEditorState> {
572572
};
573573

574574
close_request = (): void => {
575-
this.actions.set_error("You were removed from a terminal.");
575+
this.actions.set_error("Terminal closed by another session.");
576576
// If there is only one frame, we close the
577577
// entire editor -- otherwise, we close only
578578
// this frame.
@@ -690,6 +690,7 @@ export class Terminal<T extends CodeEditorState = CodeEditorState> {
690690
kick_other_users_out(): void {
691691
// @ts-ignore
692692
this.conn?.kick();
693+
this.measureSize({ kick: true });
693694
}
694695

695696
kill = async () => {
@@ -752,7 +753,7 @@ export class Terminal<T extends CodeEditorState = CodeEditorState> {
752753
return this.terminal.options[option];
753754
}
754755

755-
measureSize = (): void => {
756+
measureSize = ({ kick }: { kick?: boolean } = {}): void => {
756757
if (this.ignore_terminal_data) {
757758
// during initial load
758759
return;
@@ -766,7 +767,7 @@ export class Terminal<T extends CodeEditorState = CodeEditorState> {
766767
return;
767768
}
768769
this.last_geom = { rows, cols };
769-
this.conn_write({ cmd: "size", rows, cols });
770+
this.conn_write({ cmd: "size", rows, cols, kick });
770771
};
771772

772773
copy = (): void => {

src/packages/project/nats/terminal.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,12 @@ export async function createTerminalService(path: string) {
119119
}
120120
},
121121

122-
size: async (opts: { rows: number; cols: number; browser_id: string }) => {
122+
size: async (opts: {
123+
rows: number;
124+
cols: number;
125+
browser_id: string;
126+
kick?: boolean;
127+
}) => {
123128
const session = await getSession();
124129
session.setSize(opts);
125130
},
@@ -351,11 +356,16 @@ class Session {
351356
browser_id,
352357
rows,
353358
cols,
359+
kick,
354360
}: {
355361
browser_id: string;
356362
rows: number;
357363
cols: number;
364+
kick?: boolean;
358365
}) => {
366+
if (kick) {
367+
this.clientSizes = {};
368+
}
359369
this.clientSizes[browser_id] = { rows, cols, time: Date.now() };
360370
this.resize();
361371
};
@@ -378,7 +388,7 @@ class Session {
378388
logger.debug("resize", "new size", rows, cols);
379389
try {
380390
this.setSizePty({ rows, cols });
381-
// tell browsers about out new size
391+
// tell browsers about our new size
382392
await this.browserApi.size({ rows, cols });
383393
} catch (err) {
384394
logger.debug(`WARNING: unable to resize term: ${err}`);
@@ -393,6 +403,10 @@ class Session {
393403
}
394404
// logger.debug("setSize", { rows, cols }, "DOING IT!");
395405

406+
// the underlying ptyjs library -- if it thinks the size is already set,
407+
// it will do NOTHING. This ends up being very bad when clients reconnect.
408+
// As a hack, we just change it, then immediately change it back
409+
this.pty.resize(cols, rows + 1);
396410
this.pty.resize(cols, rows);
397411
this.size = { rows, cols };
398412
};

0 commit comments

Comments
 (0)