pty

package
v0.145.2 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pty is the platform-neutral pty (pseudo terminal) backend for interactive jobs (WEB-03 design §6, §13). It abstracts starting a child process attached to a pty master so callers get a raw bidirectional byte stream + resize + exit-code wait, without importing a platform pty library directly.

The interface is implemented per-platform (see pty_unix.go / pty_windows.go):

  • unix: github.com/creack/pty (pty.Start(*exec.Cmd) → ptmx *os.File)
  • windows: the vendored UserExistsError/conpty (internal/pty/conpty), which takes a single command-line string, so Start adapts (Command,Args) into a safely-quoted command line there.

This makes serve's own local pty a cross-platform drop-in (v0.7): the same Pty contract works on a Windows serve and on a Linux worker.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAvailable

func IsAvailable() bool

IsAvailable is always true on unix: creack/pty opens /dev/ptmx at Start time and a failure surfaces there (probing here would just duplicate that).

Types

type Pty

type Pty interface {
	io.ReadWriteCloser
	// Resize sets the pty window size in character cells.
	Resize(cols, rows int) error
	// Wait blocks until the child exits (or ctx is cancelled) and returns the
	// process exit code. A ctx cancellation returns a non-nil error without
	// reaping; the caller kills via Close and calls Wait once.
	Wait(ctx context.Context) (exitCode int, err error)
}

Pty is a running child attached to a pty master. Read/Write carry the raw byte stream to/from the child (stdout+stderr multiplexed on Read, stdin on Write); Resize sets the terminal window size; Wait blocks for the child to exit and returns its exit code. Close releases the master fd (and, on unix, kills the child) — teardown ORDER is owned by the caller's state machine (design §5), this type only provides the primitives.

func Start

func Start(spec Spec) (Pty, error)

Start runs spec under a freshly allocated pty (unix: creack/pty).

Unlike creack.Start, the parent keeps its own slave fd until the child has been reaped (gofer-auat). On darwin the child's exit would otherwise be the LAST close of the slave, and the BSD tty layer flushes output the master has not read yet on that close — a job that printed and exited before the reader caught up lost its output, all of it for a short-lived one. Holding the slave makes the reaper's close the last one; it runs only after the exit is known, and the reader drains the buffer to EOF before Close tears the master down (see Close).

type Spec

type Spec struct {
	Command string   // executable to run
	Args    []string // args (not including argv[0])
	Env     []string // full process env (KEY=VALUE); nil = inherit os.Environ
	Dir     string   // working directory; "" = inherit
	Cols    int      // initial terminal width (columns); 0 = platform default
	Rows    int      // initial terminal height (rows); 0 = platform default
}

Spec is a platform-neutral request to start a child under a pty.

Directories

Path Synopsis
Package conpty is the vendored Windows ConPTY backend (see conpty.go, which carries the //go:build windows constraint).
Package conpty is the vendored Windows ConPTY backend (see conpty.go, which carries the //go:build windows constraint).

Jump to

Keyboard shortcuts

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