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