Skip to content

feat: Implement true PTY allocation for interactive mode #24

@inureyes

Description

@inureyes

Overview

Implement proper pseudo-terminal (PTY) allocation for interactive SSH sessions, providing full terminal emulation capabilities including terminal resize handling, raw mode support, and proper handling of colors and special keys.

Technical Approach

Enhance the existing interactive mode with true PTY support:

  • Terminal raw mode using crossterm for cross-platform support
  • PTY request through russh's request_pty API
  • Bidirectional I/O bridge between local terminal and SSH channel
  • Signal handling for terminal resize (SIGWINCH)
  • Multi-node support with PTY session switching

Implementation Tasks

Phase 1: PTY Foundation

  • Create PTY module structure (src/pty/mod.rs)
  • Implement terminal raw mode with crossterm
  • Add PTY request to SSH session initialization
  • Create terminal state save/restore mechanism
  • Handle basic terminal input/output

Phase 2: Terminal Bridge

  • Implement bidirectional I/O pump for terminal data
  • Add special key handling (arrows, function keys)
  • Support control sequences (Ctrl+C, Ctrl+D, etc.)
  • Implement proper EOF and signal handling
  • Add terminal echo and line discipline control

Phase 3: Window Resize Support

  • Detect terminal size changes (SIGWINCH)
  • Implement PTY window change protocol
  • Add resize event debouncing
  • Synchronize terminal size on connection
  • Handle resize for multi-node sessions

Phase 4: Enhanced Features

  • Add full ANSI color support
  • Implement cursor positioning and movement
  • Support terminal attributes (bold, italic, etc.)
  • Add mouse event support (if terminal supports)
  • Implement scrollback buffer management

Phase 5: Multi-Node Integration

  • Extend PTY support to multi-node mode
  • Implement PTY session switching
  • Add synchronized terminal state across nodes
  • Create PTY multiplexing for broadcast mode
  • Handle PTY cleanup on node disconnect

Success Criteria

  • Full compatibility with terminal applications (vim, nano, htop, etc.)
  • Input latency < 10ms
  • Window resize handling < 50ms
  • Memory usage < 1MB per PTY session
  • Proper cleanup on disconnect
  • Works on Linux and macOS
  • No terminal corruption on exit

Testing Applications

  • vim/nano - Text editing with special keys
  • htop/top - Terminal UI with colors
  • tmux/screen - Terminal multiplexers
  • bash/zsh - Shell job control
  • less/more - Pagers with scrolling
  • Python/Node REPL - Interactive interpreters

Examples

# Force PTY allocation (like ssh -t)
bssh -t user@host

# Disable PTY allocation (like ssh -T)
bssh -T user@host "command"

# Interactive session with proper PTY
bssh user@host
> vim /etc/config  # Should work with full terminal capabilities

# Multi-node with PTY
bssh -C cluster interactive
> !node1  # Switch to node1 with PTY
> top     # Should display correctly with colors

Dependencies

  • crossterm (already in dependencies)
  • terminal_size (already in dependencies)
  • signal-hook (for SIGWINCH handling)
  • No new external dependencies required

Labels

enhancement, help wanted, ssh-compat, interactive

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions