Skip to content

Commit 7bbce23

Browse files
committed
terminal: replace some hacks by root cause fixes
- noticed I could reproduce the term control codes problem and fixed it by not sending the request in the first place
1 parent ad3847f commit 7bbce23

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ export class Terminal<T extends CodeEditorState = CodeEditorState> {
307307
});
308308
conn.on("data", this.handleDataFromProject);
309309
conn.once("ready", () => {
310+
this.terminal.clear();
310311
delete this.last_geom;
311312
this.ignore_terminal_data = false;
312313
this.set_connection_status("connected");
@@ -706,6 +707,12 @@ export class Terminal<T extends CodeEditorState = CodeEditorState> {
706707

707708
init_terminal_data(): void {
708709
this.terminal.onData((data) => {
710+
if (data == "\x1B[>0;276;0c") {
711+
// this is a request for term capabilities, sending it just ends up
712+
// not helping and putting "control codes" that users see in the terminal,
713+
// which is very bad. So we ignore them.
714+
return;
715+
}
709716
if (this.ignore_terminal_data && this.conn?.state == "init") {
710717
return;
711718
}
@@ -763,7 +770,11 @@ export class Terminal<T extends CodeEditorState = CodeEditorState> {
763770
return;
764771
}
765772
const { rows, cols } = geom;
766-
if (this.last_geom?.rows === rows && this.last_geom?.cols === cols) {
773+
if (
774+
!kick &&
775+
this.last_geom?.rows === rows &&
776+
this.last_geom?.cols === cols
777+
) {
767778
return;
768779
}
769780
this.last_geom = { rows, cols };

src/packages/frontend/frame-editors/terminal-editor/nats-terminal-connection.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export class NatsTerminalConnection extends EventEmitter {
8282
}
8383
if (typeof data != "string") {
8484
if (data.cmd == "size") {
85-
const { rows, cols } = data;
85+
const { rows, cols, kick } = data;
8686
if (
8787
rows <= 0 ||
8888
cols <= 0 ||
@@ -99,6 +99,7 @@ export class NatsTerminalConnection extends EventEmitter {
9999
rows,
100100
cols,
101101
browser_id: webapp_client.browser_id,
102+
kick,
102103
});
103104
} catch {
104105
// harmless to ignore
@@ -241,9 +242,6 @@ export class NatsTerminalConnection extends EventEmitter {
241242
};
242243

243244
private setReady = async () => {
244-
// wait until after render loop of terminal before allowing writing,
245-
// or we get corruption.
246-
await delay(1);
247245
this.setState("running");
248246
this.emit("ready");
249247
};

src/packages/nats/service/terminal.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ interface TerminalApi {
2929
rows: number;
3030
cols: number;
3131
browser_id: string;
32+
kick?: boolean;
3233
}) => Promise<void>;
3334

3435
// sent from browser to project when this client is leaving.

0 commit comments

Comments
 (0)