terminal

package
v0.1.0-rc.8 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 13 Imported by: 1 module, 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 terminal implements a streaming VT screen and native shell sessions. It has no dependencies outside the Go standard library.

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("terminal session is closed")
View Source
var ErrInputFull = errors.New("terminal input queue is full")
View Source
var Palette = [16]Color{0x1e1e1e, 0xcd3131, 0x0dbc79, 0xe5e510, 0x2472c8, 0xbc3fbc, 0x11a8cd, 0xe5e5e5, 0x666666, 0xf14c4c, 0x23d18b, 0xf5f543, 0x3b8eea, 0xd670d6, 0x29b8db, 0xffffff}

Functions

func RuneWidth

func RuneWidth(r rune) int

RuneWidth follows terminal columns for combining marks and East Asian text.

Types

type Cell

type Cell struct {
	Rune                     rune
	Foreground, Background   Color
	Bold, Inverse, Underline bool
	Width                    uint8
	Combining                [3]rune
}

type Color

type Color uint32
const Default Color = 1 << 24

func IndexedColor

func IndexedColor(n int) Color

type Process

type Process interface {
	io.ReadWriteCloser
	Resize(cols, rows int) error
	Wait() error
}

func OpenCommand

func OpenCommand(directory string, args []string, env map[string]*string, cols, rows int) (Process, int, error)

OpenCommand starts argv directly in a PTY; no shell parses program arguments. A nil environment value removes the inherited variable, as required by DAP.

func OpenProcess

func OpenProcess(directory string, cols, rows int) (Process, error)

OpenProcess exposes the native PTY only to headless service owners.

type Screen

type Screen struct {
	Title string

	Cells []Cell

	History []historyCell

	MouseTracking int

	Cols, Rows int

	Scrolled uint64
	Revision uint64

	HistoryLimit int

	DefaultForeground, DefaultBackground Color

	CursorVisible, ApplicationCursor, BracketedPaste bool

	MouseSGR bool
	// contains filtered or unexported fields
}

Screen is owned by the foreground. Feed accepts arbitrary byte boundaries.

func NewScreen

func NewScreen(cols, rows int) *Screen

func (*Screen) Alternate

func (s *Screen) Alternate() bool

func (*Screen) Clear

func (s *Screen) Clear()

func (*Screen) ClearOutput

func (s *Screen) ClearOutput()

ClearOutput removes scrollback and all rows except the current input line. Keep the cursor coordinates in sync with applications such as Windows ConPTY, which can continue rendering with absolute cursor positions after a UI clear.

func (*Screen) Cursor

func (s *Screen) Cursor() (int, int)

func (*Screen) Feed

func (s *Screen) Feed(data []byte)

func (*Screen) HistoryRow

func (s *Screen) HistoryRow(index int) []Cell

HistoryRow borrows a decoded chronological row until the next HistoryRow or Resize call. Reading a warm row does not allocate.

func (*Screen) Replies

func (s *Screen) Replies() []byte

func (*Screen) Resize

func (s *Screen) Resize(cols, rows int)

type Session

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

Session bounds both queues. Output applies backpressure instead of dropping bytes (dropping even one byte can corrupt a VT sequence). No worker touches UI.

func Attach

func Attach(cols, rows int, wake func(), open func() (Process, error)) *Session

Attach keeps VT queues local while the process can live on another machine.

func Start

func Start(directory string, cols, rows int, wake func()) *Session

func (*Session) Close

func (s *Session) Close()

Close never waits for a process or pipe on the foreground thread.

func (*Session) Done

func (s *Session) Done() <-chan struct{}

func (*Session) ReadOutput

func (s *Session) ReadOutput(dst []byte) int

func (*Session) Resize

func (s *Session) Resize(cols, rows int)

func (*Session) Status

func (s *Session) Status() (ready, exited bool, err error)

func (*Session) Write

func (s *Session) Write(data []byte) (int, error)

Jump to

Keyboard shortcuts

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