ptyproxy

package
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package ptyproxy is the client-side PTY proxy used by `godo attach` (and the in-pane attach inside the TUI). It puts stdin in raw mode, forwards PTY output to stdout, sends SIGWINCH events as resize frames, and watches for a configurable detach key sequence.

Index

Constants

This section is empty.

Variables

View Source
var DefaultDetachSequence = []byte{0x18, 'd'} // Ctrl+X, d

DefaultDetachSequence is the default detach hotkey: Ctrl+X then 'd'. Two bytes so the prefix Ctrl+X alone (an emacs/readline prefix) doesn't fire a detach. Avoids the mode-prefix keys of tmux (Ctrl+B), screen (Ctrl+A), and zellij (Ctrl+G/P/T/N/H/S/O/Q) — Docker's Ctrl+P,Ctrl+Q collides with zellij's pane-mode + quit and tears down the whole session.

Functions

func Banner(target string, seq []byte) string

Banner returns the one-line connection notice printed before raw mode is enabled. Both `godo attach` and the TUI's in-pane attach emit this so users always see the detach shortcut at the moment of entry.

Style: dim ANSI escape so it sits visually below whatever the child process renders. Plain ASCII fallback if the caller's terminal strips escapes (the bytes are still readable).

func FormatDetachSequence

func FormatDetachSequence(seq []byte) string

FormatDetachSequence renders a byte sequence as the human-readable "Ctrl+P Ctrl+Q" form for the banner and docs.

func ParseDetachSequence

func ParseDetachSequence(s string) ([]byte, error)

ParseDetachSequence interprets a comma-separated spec (e.g. "Ctrl+P,Ctrl+Q" or "Ctrl+B,d") into a byte sequence. Whitespace around commas is ignored; the "Ctrl+" prefix is case-insensitive. Single ASCII characters pass through as their byte value.

func Run

func Run(stream Stream, opts ...Option) error

Run takes over the calling process's stdin/stdout to proxy to and from stream. It puts stdin in raw mode (if it's a tty), forwards SIGWINCH events as resize frames, and watches for the configured detach key sequence. Returns nil on detach or clean stream EOF.

Caller does not need to do their own terminal cleanup — Run restores state on every return path.

func RunOn

func RunOn(stream Stream, stdin *os.File, stdout io.Writer, opts ...Option) error

RunOn is the testable form of Run. Passes stdin/stdout explicitly so tests can drive the proxy with pipes.

Types

type Option

type Option func(*config)

Option configures Run / RunOn behaviour.

func WithDetachSequence

func WithDetachSequence(seq []byte) Option

WithDetachSequence overrides the default detach hotkey. nil or empty resets to DefaultDetachSequence.

type Stream

type Stream interface {
	io.Reader
	io.Writer
	Resize(cols, rows uint16) error
	Close() error
}

Stream is the bidirectional channel to the daemon. proto.AttachStream satisfies it; the interface lives here so this package has no upward dependency.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL