tty

package
v1.0.260758 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handle

type Handle struct {
	Cmd  *exec.Cmd
	File *os.File
	// contains filtered or unexported fields
}

Handle wraps a PTY-backed process. File/Cmd are exported for existing callers, but Close can run concurrently with a blocked Read/Write in the PTY read-loop goroutine (that's how "Close unblocks readers immediately" works — closing the fd out from under a blocking Read is intentional), so every access to the fields themselves goes through mu.

Read/Write only hold mu for the pointer capture, then call the os.File method unlocked — safe because os.File's Read/Write/Close are themselves mutually synchronized via the runtime's internal poll.FD refcounting. SetSize is different: it goes through creack/pty's Setsize, which calls File.Fd() — and Fd() explicitly bypasses that poll.FD protection (per the os.File docs), so it's not safe against a concurrent Close at the OS level. SetSize and the Close side that actually closes the fd both hold mu for their whole call, not just the pointer swap, to cover that gap.

func Spawn

func Spawn(command string, args []string, cols, rows int) (*Handle, error)

Spawn starts cmd in a PTY of the given size with truecolor-friendly env.

func (*Handle) Close

func (h *Handle) Close() error

Close unblocks readers immediately, then reaps the child without hanging.

func (*Handle) Read

func (h *Handle) Read(p []byte) (int, error)

func (*Handle) SetSize

func (h *Handle) SetSize(cols, rows int) error

func (*Handle) Write

func (h *Handle) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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