pty

package
v0.0.0-...-aa30a3e Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Open

func Open() (master *os.File, slavePath string, err error)

Open allocates a new PTY pair via /dev/ptmx (Linux).

func SetSize

func SetSize(fd uintptr, ws *Winsize) error

SetSize sets the window size on a PTY fd (Linux).

Types

type PTY

type PTY struct {
	Master *os.File
	// contains filtered or unexported fields
}

PTY holds both sides of a pseudo-terminal pair and the child process.

func Start

func Start(argv []string, env []string) (*PTY, error)

Start opens a new PTY, forks the given command onto the slave side with a proper session and controlling terminal, and returns a *PTY whose Master is ready for reading/writing.

argv[0] is the executable path. Pass nil env to inherit.

func StartWithFd

func StartWithFd(argv []string, env []string, extraFds ...uintptr) (*PTY, error)

StartWithFd is like Start but also passes extra file descriptors to the child (mapped starting at fd 3). Use this to pass your socketpair alongside the PTY.

func (*PTY) Close

func (p *PTY) Close() error

Close shuts down the PTY. Sends SIGHUP to the child (same as closing a real terminal) and closes the master fd.

func (*PTY) Done

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

Done returns a channel that is closed when the child process exits.

func (*PTY) Pid

func (p *PTY) Pid() int

Pid returns the child's process id.

func (*PTY) Proxy

func (p *PTY) Proxy() error

Proxy connects the PTY bidirectionally to the outer terminal (os.Stdin/os.Stdout). It puts the outer terminal into raw mode, handles SIGWINCH propagation, and blocks until the child exits. Restores the outer terminal on return.

func (*PTY) Resize

func (p *PTY) Resize(rows, cols uint16) error

Resize sets the PTY window size and sends SIGWINCH to the child.

func (*PTY) Signal

func (p *PTY) Signal(sig syscall.Signal) error

Signal sends a signal to the child process.

type Winsize

type Winsize struct {
	Rows   uint16
	Cols   uint16
	Xpixel uint16
	Ypixel uint16
}

Winsize matches the kernel's struct winsize.

func GetSize

func GetSize(fd uintptr) (*Winsize, error)

GetSize reads the current window size from a terminal fd (Linux).

Jump to

Keyboard shortcuts

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