pty

package
v0.0.0-...-d1bef24 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

This section is empty.

Types

type Cell

type Cell struct {
	Char  rune
	Style Style
}

Cell represents a single character cell with style.

type Color

type Color int32

Color represents a terminal color.

const (
	ColorDefault Color = -1
	ColorBlack   Color = 0
	ColorRed     Color = 1
	ColorGreen   Color = 2
	ColorYellow  Color = 3
	ColorBlue    Color = 4
	ColorMagenta Color = 5
	ColorCyan    Color = 6
	ColorWhite   Color = 7

	// Bright colors (8-15)
	ColorBrightBlack   Color = 8
	ColorBrightRed     Color = 9
	ColorBrightGreen   Color = 10
	ColorBrightYellow  Color = 11
	ColorBrightBlue    Color = 12
	ColorBrightMagenta Color = 13
	ColorBrightCyan    Color = 14
	ColorBrightWhite   Color = 15
)

Standard ANSI colors

func RGB256

func RGB256(n int) Color

RGB256 creates a 256-color palette color (16-255).

func RGBTrue

func RGBTrue(r, g, b uint8) Color

RGBTrue creates a true color (24-bit). Encoded as 256 + (r<<16 | g<<8 | b).

type PTY

type PTY struct {
	Master *os.File
	Slave  *os.File
	Name   string
}

PTY represents a pseudo-terminal pair.

func Open

func Open() (*PTY, error)

Open creates a new pseudo-terminal pair.

func (*PTY) Close

func (p *PTY) Close() error

Close closes both ends of the PTY.

func (*PTY) Read

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

Read reads from the master side.

func (*PTY) SetSize

func (p *PTY) SetSize(rows, cols int) error

SetSize sets the terminal size.

func (*PTY) StartProcess

func (p *PTY) StartProcess(name string, args []string, env []string) (*os.Process, error)

StartProcess starts a process attached to the PTY.

func (*PTY) StartShell

func (p *PTY) StartShell() (*os.Process, error)

StartShell starts the default shell attached to the PTY.

func (*PTY) Write

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

Write writes to the master side.

type Style

type Style struct {
	Fg        Color
	Bg        Color
	Bold      bool
	Dim       bool
	Italic    bool
	Underline bool
	Blink     bool
	Reverse   bool
}

Style holds text attributes for a cell.

func DefaultStyle

func DefaultStyle() Style

DefaultStyle returns the default terminal style.

type Terminal

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

Terminal represents a terminal session with a PTY and process.

func NewTerminal

func NewTerminal(rows, cols int) (*Terminal, error)

NewTerminal creates a new terminal with the given size.

func (*Terminal) Close

func (t *Terminal) Close() error

Close closes the terminal and kills the process.

func (*Terminal) CursorPos

func (t *Terminal) CursorPos() (x, y int)

CursorPos returns the cursor position.

func (*Terminal) GetBuffer

func (t *Terminal) GetBuffer() []string

GetBuffer returns the entire buffer as strings (characters only, no styles).

func (*Terminal) GetBufferCells

func (t *Terminal) GetBufferCells() [][]Cell

GetBufferCells returns the entire buffer with styles. This is the preferred method for rendering with color support.

func (*Terminal) GetBufferRunes

func (t *Terminal) GetBufferRunes() [][]rune

GetBufferRunes returns the entire buffer as rune slices (characters only, no styles). This is more efficient for rendering as it avoids UTF-8 encoding/decoding and provides correct column indices.

func (*Terminal) GetLine

func (t *Terminal) GetLine(y int) string

GetLine returns a line from the buffer as a string (characters only, no styles).

func (*Terminal) IsRunning

func (t *Terminal) IsRunning() bool

IsRunning returns true if the process is still running.

func (*Terminal) Resize

func (t *Terminal) Resize(rows, cols int) error

Resize resizes the terminal.

func (*Terminal) SnapshotCells

func (t *Terminal) SnapshotCells() (lines [][]Cell, cursorX, cursorY int)

SnapshotCells returns scrollback + active buffer with styles and absolute cursor position. Cursor Y is relative to the returned lines.

func (*Terminal) SnapshotRunes

func (t *Terminal) SnapshotRunes() (lines [][]rune, cursorX, cursorY int)

SnapshotRunes returns scrollback + active buffer and the absolute cursor position. Cursor Y is relative to the returned lines.

func (*Terminal) Write

func (t *Terminal) Write(data []byte) error

Write sends input to the terminal.

func (*Terminal) WriteString

func (t *Terminal) WriteString(s string) error

WriteString sends a string to the terminal.

Jump to

Keyboard shortcuts

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