pty

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: Apache-2.0 Imports: 13 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 runs processes in pseudo-terminals, in pure Go: /dev/ptmx on macOS and Linux, ConPTY on Windows.

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("pty: closed")

ErrClosed is returned by Write after Close.

Functions

This section is empty.

Types

type Options

type Options struct {
	// Path is the program; Args its arguments, with Args[0] what the
	// program sees as its name ("-zsh" starts a login shell).
	Path string
	Args []string
	// Dir is the working directory, Env the environment ("KEY=value").
	Dir string
	Env []string
	// Cols and Rows are the size of the terminal in cells, Width and
	// Height in pixels.
	Cols, Rows, Width, Height int
}

Options describe a process to start in a pseudo-terminal.

type PTY

type PTY struct {
	// contains filtered or unexported fields
}

PTY is a process running in a pseudo-terminal: Read returns its output, Write types into it.

func Start

func Start(o Options) (*PTY, error)

Start starts a process in a pseudo-terminal.

func (*PTY) ClearScreen

func (p *PTY) ClearScreen() error

ClearScreen does nothing: the terminal has no screen of its own to clear, unlike ConPTY's console.

func (*PTY) Close

func (p *PTY) Close() error

Close hangs up the terminal and the process groups of its session: the process's and those of the jobs it started. Groups ignoring SIGHUP get SIGTERM after a grace period, then SIGKILL. It does not wait for exit; Wait includes the session's shutdown.

func (*PTY) Exited

func (p *PTY) Exited() <-chan struct{}

Exited is closed when the process exited.

func (*PTY) Kill

func (p *PTY) Kill() error

Kill kills the process and the process groups of its session, which it leads.

func (*PTY) Pid

func (p *PTY) Pid() int

Pid returns the process's ID.

func (*PTY) Read

func (p *PTY) Read(b []byte) (int, error)

Read reads the output of the process; it returns io.EOF once no process has the terminal open any more, or after Close.

func (*PTY) Resize

func (p *PTY) Resize(cols, rows, width, height int) error

Resize sets the size of the terminal, which sends the process SIGWINCH.

func (*PTY) Wait

func (p *PTY) Wait() (int, error)

Wait waits for the process to exit and returns its exit code.

func (*PTY) Write

func (p *PTY) Write(b []byte) (int, error)

Write types b into the terminal.

Jump to

Keyboard shortcuts

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