Skip to content

w3cos.pty — Pseudo Terminal API for terminal emulator #36

@wangnaihe

Description

@wangnaihe

Context

Per docs/vscode-compat.md Phase B (P0). VS Code's integrated terminal requires a PTY (pseudo-terminal) backend. This replaces `node-pty` which VS Code uses with Electron.

Requirements

  • `w3cos.pty.create(options)` → `PseudoTerminal`
    • options: `shell` (default: user's shell), `cols`, `rows`, `cwd`, `env`
  • `PseudoTerminal.write(data: string)` — send input to the shell
  • `PseudoTerminal.onData(callback: (data: string) => void)` — receive output
  • `PseudoTerminal.resize(cols, rows)` — resize the terminal
  • `PseudoTerminal.kill()` — terminate the shell process
  • `PseudoTerminal.onExit(callback: (code: number) => void)`

Implementation

Rust side

  • Use `nix::pty::openpty()` or the `portable-pty` crate to create a PTY pair
  • Fork a child process (`/bin/bash` or `$SHELL`) attached to the slave PTY
  • Read from master fd asynchronously (tokio), forward to the application

Application side

  • The terminal UI component (like xterm.js) renders the output via DOM
  • Keyboard input is forwarded to `PseudoTerminal.write()`
  • This pairs with the Canvas 2D API (Canvas 2D API (CanvasRenderingContext2D) #32) or a dedicated terminal rendering component

New crate

Consider a `w3cos-system` or `w3cos-pty` crate that wraps the PTY logic and is linked by the compiler when PTY APIs are detected.

References

  • node-pty — Rust PTY library
  • docs/vscode-compat.md §2.3 — w3cos.pty

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions