Skip to main content

Module Terminal

Expand description

§Terminal handlers

Two related responsibilities:

  • Terminal* - operate on PTYs that are already registered via the TerminalProvider trait. Every method takes a provider-assigned terminal_id (u64).
  • LocalPTY* - read-only platform queries that don’t touch any registered PTY: discover available shells, default shell, and the current process environment.

Layout (one export per file, file name = identity):

  • TerminalCreate::TerminalCreate, TerminalSendText::TerminalSendText, TerminalDispose::TerminalDispose, TerminalShow::TerminalShow, TerminalHide::TerminalHide.
  • LocalPTYGetProfiles::LocalPTYGetProfiles, LocalPTYGetDefaultShell::LocalPTYGetDefaultShell, LocalPTYGetEnvironment::LocalPTYGetEnvironment.
  • SerializeTerminalState::SerializeTerminalState - snapshot all active terminals to ISerializedTerminalState[] for window-reload restoration.
  • ReviveTerminalProcesses::ReviveTerminalProcesses - respawn terminals from a previously serialised snapshot.
  • AttachToProcess::AttachToProcess - reconnect the workbench to an existing Mountain PTY after a window reload.
  • DetachFromProcess::DetachFromProcess - detach the workbench; PTY stays alive with output buffering for the next attach.

Modules§

AttachToProcess
localPty:attachToProcess - reconnect the workbench to an existing Mountain-owned PTY after a window reload.
DetachFromProcess
localPty:detachFromProcess - signal that the workbench is detaching from a live PTY (e.g. on window close while keeping the process alive).
LocalPTYCreateProcess
Wire method: localPty:createProcess. VS Code’s IPtyService.createProcess is typed Promise<number>. The workbench does new LocalPty(id, …) and keys _ptys by that integer; returning the full { id, name, pid } object causes every subsequent _ptys.get(<integer>) lookup to return undefined and xterm to receive zero bytes. This handler strips down to the integer id.
LocalPTYFreePortKillProcess
Wire method: localPty:freePortKillProcess. Kills whatever process is holding a TCP port so a new terminal can bind it. On Unix, uses lsof -t -i :<port> to list PIDs then kill -9 each one. No-op on unknown port (0) or non-Unix platforms.
LocalPTYGetDefaultShell
Pick the system default shell. Unix: $SHELL, then probe /bin/{zsh,bash,sh}. Windows: PowerShell 7 if installed, else stock Windows PowerShell. Used by Wind’s “Open Default Terminal” command and by extensions that spawn unparented shells.
LocalPTYGetEnvironment
Snapshot the Mountain process environment as a HashMap. Inherited by every PTY spawned through TerminalCreate. Includes the keys merged in by EnhanceShellEnvironment at boot, so a Finder-launched .app exposes the user’s interactive shell PATH / NVM_DIR / HOMEBREW_PREFIX / … to terminals it spawns.
LocalPTYGetProfiles
Discover available terminal profiles. Probes every well- known shell location plus /etc/shells (Unix) or known Windows install paths. The first existing match flags isDefault=true; on Unix the user’s $SHELL wins.
LocalPTYResize
Wire method: localPty:resize. Forwards a resize event to the PTY master (SIGWINCH) via TerminalProvider::ResizeTerminal. Accepts either positional [id, cols, rows] or object { id, cols, rows } from the workbench.
ReviveTerminalProcesses
Revive serialised terminal processes after a window reload.
SerializeTerminalState
Serialise all active terminals to the ISerializedTerminalState[] shape that VS Code’s ILocalPtyService.serializeTerminalProcesses contract requires.
TerminalCreate
Spawn a new PTY through TerminalProvider::CreateTerminal. Options carries shell path, args, cwd, env, name. Returns a provider-assigned terminal id (u64) which Wind uses for every subsequent send/show/dispose call.
TerminalDispose
Close a PTY, kill its child, and drop the entry from the provider’s terminal registry. Idempotent - disposing an already-disposed id surfaces as a logged warning, not an error.
TerminalHide
Hide a terminal panel without disposing the underlying PTY. The child process keeps running; subsequent TerminalShow reopens the same session. Mirrors vscode.Terminal.hide().
TerminalSendText
Pipe text into a terminal’s PTY stdin. Used both for direct key forwarding (xterm.js → Mountain → PTY) and for programmatic input (vscode.window.terminals[…].sendText).
TerminalShow
Bring a terminal to the foreground in the panel. When PreserveFocus is true, the active editor keeps keyboard focus (mirrors vscode.Terminal.show(preserveFocus)).