avyos.dev/pkg/pty
package pty
Package Overview
No package-level documentation is provided.
| Export Group | Count |
|---|---|
| Constants | 0 |
| Variables | 1 |
| Functions | 0 |
| Types | 5 |
Variables
var ErrClosed = errors.New("terminal closed")Types
Cell
type Cell struct {
Char rune
Style Style
}Cell represents a single character cell with style.
Color
type Color int32Color represents a terminal color.
Constants
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
Functions
func RGB256(n int) ColorRGB256 creates a 256-color palette color (16-255).
func RGBTrue(r, g, b uint8) ColorRGBTrue creates a true color (24-bit). Encoded as 256 + (r<<16 | g<<8 | b).
PTY
type PTY struct {
Master *os.File
Slave *os.File
Name string
}PTY represents a pseudo-terminal pair.
Functions
func Open() (*PTY, error)Open creates a new pseudo-terminal pair.
Methods
func (p *PTY) Close() errorClose closes both ends of the PTY.
func (p *PTY) Read(b []byte) (int, error)Read reads from the master side.
func (p *PTY) SetSize(rows, cols int) errorSetSize sets the terminal size.
func (p *PTY) StartProcess(name string, args []string, env []string) (*os.Process, error)StartProcess starts a process attached to the PTY.
func (p *PTY) StartShell() (*os.Process, error)StartShell starts the default shell attached to the PTY.
func (p *PTY) Write(b []byte) (int, error)Write writes to the master side.
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.
Functions
func DefaultStyle() StyleDefaultStyle returns the default terminal style.
Terminal
type Terminal struct {
// contains filtered or unexported fields
}Terminal represents a terminal session with a PTY and process.
Functions
func NewTerminal(rows, cols int) (*Terminal, error)NewTerminal creates a new terminal with the given size.
Methods
func (t *Terminal) Close() errorClose closes the terminal and kills the process.
func (t *Terminal) CursorPos() (x, y int)CursorPos returns the cursor position.
func (t *Terminal) GetBuffer() []stringGetBuffer returns the entire buffer as strings (characters only, no styles).
func (t *Terminal) GetBufferCells() [][]CellGetBufferCells returns the entire buffer with styles. This is the preferred method for rendering with color support.
func (t *Terminal) GetBufferRunes() [][]runeGetBufferRunes 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 (t *Terminal) GetLine(y int) stringGetLine returns a line from the buffer as a string (characters only, no styles).
func (t *Terminal) IsRunning() boolIsRunning returns true if the process is still running.
func (t *Terminal) Resize(rows, cols int) errorResize resizes the terminal.
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 (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 (t *Terminal) Write(data []byte) errorWrite sends input to the terminal.
func (t *Terminal) WriteString(s string) errorWriteString sends a string to the terminal.