| ... | ... | @@ -26,6 +26,8 @@ import { runProcess } from "./processRunner"; |
| 26 | 26 | const DEFAULT_HISTORY_LINE_LIMIT = 5_000; |
| 27 | 27 | const DEFAULT_PERSIST_DEBOUNCE_MS = 40; |
| 28 | 28 | const DEFAULT_SUBPROCESS_POLL_INTERVAL_MS = 1_000; |
| 29 | const DEFAULT_OPEN_COLS = 120; |
| 30 | const DEFAULT_OPEN_ROWS = 30; |
| 29 | 31 | const TERMINAL_ENV_BLOCKLIST = new Set(["PORT", "ELECTRON_RENDERER_PORT", "ELECTRON_RUN_AS_NODE"]); |
| 30 | 32 | |
| 31 | 33 | type TerminalSubprocessChecker = (terminalPid: number) => Promise<boolean>; |
| ... | ... | @@ -67,6 +69,8 @@ interface ShellCandidate { |
| 67 | 69 | args?: string[]; |
| 68 | 70 | } |
| 69 | 71 | |
| 72 | type TerminalStartInput = TerminalOpenInput & { cols: number; rows: number }; |
| 73 | |
| 70 | 74 | function defaultShellResolver(): string { |
| 71 | 75 | if (process.platform === "win32") { |
| 72 | 76 | return process.env.ComSpec ?? "cmd.exe"; |
| ... | ... | @@ -334,6 +338,8 @@ export class TerminalManager extends EventEmitter<TerminalManagerEvents> { |
| 334 | 338 | if (!existing) { |
| 335 | 339 | await this.flushPersistQueue(input.threadId, input.terminalId); |
| 336 | 340 | const history = await this.readHistory(input.threadId, input.terminalId); |
| 341 | const cols = input.cols ?? DEFAULT_OPEN_COLS; |
| 342 | const rows = input.rows ?? DEFAULT_OPEN_ROWS; |
| 337 | 343 | const session: TerminalSessionState = { |
| 338 | 344 | threadId: input.threadId, |
| 339 | 345 | terminalId: input.terminalId, |
| ... | ... | @@ -344,8 +350,8 @@ export class TerminalManager extends EventEmitter<TerminalManagerEvents> { |
| 344 | 350 | exitCode: null, |
| 345 | 351 | exitSignal: null, |
| 346 | 352 | updatedAt: new Date().toISOString(), |
| 347 | | cols: input.cols, |
| 348 | | rows: input.rows, |
| 353 | cols, |
| 354 | rows, |
| 349 | 355 | process: null, |
| 350 | 356 | unsubscribeData: null, |
| 351 | 357 | unsubscribeExit: null, |
| ... | ... | @@ -353,12 +359,14 @@ export class TerminalManager extends EventEmitter<TerminalManagerEvents> { |
| 353 | 359 | runtimeEnv: normalizedRuntimeEnv(input.env), |
| 354 | 360 | }; |
| 355 | 361 | this.sessions.set(sessionKey, session); |
| 356 | | this.startSession(session, input, "started"); |
| 362 | this.startSession(session, { ...input, cols, rows }, "started"); |
| 357 | 363 | return this.snapshot(session); |
| 358 | 364 | } |
| 359 | 365 | |
| 360 | 366 | const nextRuntimeEnv = normalizedRuntimeEnv(input.env); |
| 361 | 367 | const currentRuntimeEnv = existing.runtimeEnv; |
| 368 | const targetCols = input.cols ?? existing.cols; |
| 369 | const targetRows = input.rows ?? existing.rows; |
| 362 | 370 | const runtimeEnvChanged = |
| 363 | 371 | JSON.stringify(currentRuntimeEnv) !== JSON.stringify(nextRuntimeEnv); |
| 364 | 372 | |
| ... | ... | @@ -377,14 +385,14 @@ export class TerminalManager extends EventEmitter<TerminalManagerEvents> { |
| 377 | 385 | } |
| 378 | 386 | |
| 379 | 387 | if (!existing.process) { |
| 380 | | this.startSession(existing, input, "started"); |
| 388 | this.startSession(existing, { ...input, cols: targetCols, rows: targetRows }, "started"); |
| 381 | 389 | return this.snapshot(existing); |
| 382 | 390 | } |
| 383 | 391 | |
| 384 | | if (existing.cols !== input.cols || existing.rows !== input.rows) { |
| 385 | | existing.cols = input.cols; |
| 386 | | existing.rows = input.rows; |
| 387 | | existing.process.resize(input.cols, input.rows); |
| 392 | if (existing.cols !== targetCols || existing.rows !== targetRows) { |
| 393 | existing.cols = targetCols; |
| 394 | existing.rows = targetRows; |
| 395 | existing.process.resize(targetCols, targetRows); |
| 388 | 396 | existing.updatedAt = new Date().toISOString(); |
| 389 | 397 | } |
| 390 | 398 | |
| ... | ... | @@ -441,6 +449,8 @@ export class TerminalManager extends EventEmitter<TerminalManagerEvents> { |
| 441 | 449 | const sessionKey = toSessionKey(input.threadId, input.terminalId); |
| 442 | 450 | let session = this.sessions.get(sessionKey); |
| 443 | 451 | if (!session) { |
| 452 | const cols = input.cols ?? DEFAULT_OPEN_COLS; |
| 453 | const rows = input.rows ?? DEFAULT_OPEN_ROWS; |
| 444 | 454 | session = { |
| 445 | 455 | threadId: input.threadId, |
| 446 | 456 | terminalId: input.terminalId, |
| ... | ... | @@ -451,8 +461,8 @@ export class TerminalManager extends EventEmitter<TerminalManagerEvents> { |
| 451 | 461 | exitCode: null, |
| 452 | 462 | exitSignal: null, |
| 453 | 463 | updatedAt: new Date().toISOString(), |
| 454 | | cols: input.cols, |
| 455 | | rows: input.rows, |
| 464 | cols, |
| 465 | rows, |
| 456 | 466 | process: null, |
| 457 | 467 | unsubscribeData: null, |
| 458 | 468 | unsubscribeExit: null, |
| ... | ... | @@ -466,9 +476,12 @@ export class TerminalManager extends EventEmitter<TerminalManagerEvents> { |
| 466 | 476 | session.runtimeEnv = normalizedRuntimeEnv(input.env); |
| 467 | 477 | } |
| 468 | 478 | |
| 479 | const cols = input.cols ?? session.cols; |
| 480 | const rows = input.rows ?? session.rows; |
| 481 | |
| 469 | 482 | session.history = ""; |
| 470 | 483 | await this.persistHistory(input.threadId, input.terminalId, session.history); |
| 471 | | this.startSession(session, input, "restarted"); |
| 484 | this.startSession(session, { ...input, cols, rows }, "restarted"); |
| 472 | 485 | return this.snapshot(session); |
| 473 | 486 | }); |
| 474 | 487 | } |
| ... | ... | @@ -517,7 +530,7 @@ export class TerminalManager extends EventEmitter<TerminalManagerEvents> { |
| 517 | 530 | |
| 518 | 531 | private startSession( |
| 519 | 532 | session: TerminalSessionState, |
| 520 | | input: TerminalOpenInput, |
| 533 | input: TerminalStartInput, |
| 521 | 534 | eventType: "started" | "restarted", |
| 522 | 535 | ): void { |
| 523 | 536 | this.stopProcess(session); |