[terminal] Implement title changing and close-after-exit

This commit is contained in:
Quinten Kock 2025-11-18 01:55:44 +01:00
parent 1330d8f897
commit 4edac451e4
1 changed files with 11 additions and 6 deletions

View File

@ -1,12 +1,12 @@
import { Displayable } from "./editorgrid"; import { Displayable } from "./editorgrid";
import * as xterm from "@xterm/xterm"; import * as xterm from "@xterm/xterm";
import { FitAddon } from "@xterm/addon-fit"; import { FitAddon } from "@xterm/addon-fit";
import van from "vanjs-core"; import van, { State } from "vanjs-core";
const v = van.tags; const v = van.tags;
export class Terminal implements Displayable { export class Terminal implements Displayable {
term: xterm.Terminal; term: xterm.Terminal;
currentTitle: string = "Terminal"; currentTitle: State<string> = van.state("Terminal");
del: () => void; del: () => void;
dom: HTMLElement; dom: HTMLElement;
private terminalId: string | null = null; private terminalId: string | null = null;
@ -20,7 +20,7 @@ export class Terminal implements Displayable {
} }
title(): string { title(): string {
return this.currentTitle; return this.currentTitle.val;
} }
constructor() { constructor() {
@ -59,10 +59,13 @@ export class Terminal implements Displayable {
this.unsubTerminalExit = window.electronAPI.onTerminalExit( this.unsubTerminalExit = window.electronAPI.onTerminalExit(
this.terminalId, this.terminalId,
(exitCode) => (exitCode) => {
this.term.writeln( this.term.writeln(
`\r\n[Process exited with code ${exitCode}]`, `\r\n[Process exited with code ${exitCode}]\n"Press any key to close..."`,
), );
this.term.onData(() => this.close());
},
); );
// Handle user input // Handle user input
@ -72,6 +75,8 @@ export class Terminal implements Displayable {
} }
}); });
this.term.onTitleChange((title) => (this.currentTitle.val = title));
// Set up resize handling // Set up resize handling
this.resizeObserver = new ResizeObserver(() => { this.resizeObserver = new ResizeObserver(() => {
this.handleResize(); this.handleResize();