Expand description
§Terminal handlers
Two related responsibilities:
Terminal*- operate on PTYs that are already registered via theTerminalProvidertrait. Every method takes a provider-assignedterminal_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 toISerializedTerminalState[]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§
- Attach
ToProcess localPty:attachToProcess- reconnect the workbench to an existing Mountain-owned PTY after a window reload.- Detach
From Process localPty:detachFromProcess- signal that the workbench is detaching from a live PTY (e.g. on window close while keeping the process alive).- LocalPTY
Create Process - Wire method:
localPty:createProcess. VS Code’sIPtyService.createProcessis typedPromise<number>. The workbench doesnew LocalPty(id, …)and keys_ptysby that integer; returning the full{ id, name, pid }object causes every subsequent_ptys.get(<integer>)lookup to returnundefinedand xterm to receive zero bytes. This handler strips down to the integer id. - LocalPTY
Free Port Kill Process - Wire method:
localPty:freePortKillProcess. Kills whatever process is holding a TCP port so a new terminal can bind it. On Unix, useslsof -t -i :<port>to list PIDs thenkill -9each one. No-op on unknown port (0) or non-Unix platforms. - LocalPTY
GetDefault Shell - 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. - LocalPTY
GetEnvironment - Snapshot the Mountain process environment as a
HashMap. Inherited by every PTY spawned throughTerminalCreate. Includes the keys merged in byEnhanceShellEnvironmentat boot, so a Finder-launched.appexposes the user’s interactive shell PATH / NVM_DIR / HOMEBREW_PREFIX / … to terminals it spawns. - LocalPTY
GetProfiles - Discover available terminal profiles. Probes every well-
known shell location plus
/etc/shells(Unix) or known Windows install paths. The first existing match flagsisDefault=true; on Unix the user’s$SHELLwins. - LocalPTY
Resize - Wire method:
localPty:resize. Forwards a resize event to the PTY master (SIGWINCH) viaTerminalProvider::ResizeTerminal. Accepts either positional[id, cols, rows]or object{ id, cols, rows }from the workbench. - Revive
Terminal Processes - Revive serialised terminal processes after a window reload.
- Serialize
Terminal State - Serialise all active terminals to the
ISerializedTerminalState[]shape that VS Code’sILocalPtyService.serializeTerminalProcessescontract requires. - Terminal
Create - Spawn a new PTY through
TerminalProvider::CreateTerminal.Optionscarries shell path, args, cwd, env, name. Returns a provider-assigned terminal id (u64) which Wind uses for every subsequent send/show/dispose call. - Terminal
Dispose - 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.
- Terminal
Hide - Hide a terminal panel without disposing the underlying PTY.
The child process keeps running; subsequent
TerminalShowreopens the same session. Mirrorsvscode.Terminal.hide(). - Terminal
Send Text - 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). - Terminal
Show - Bring a terminal to the foreground in the panel. When
PreserveFocusistrue, the active editor keeps keyboard focus (mirrorsvscode.Terminal.show(preserveFocus)).