pane

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 30 Imported by: 0 modules, 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 pane runs a program on a pseudo-terminal and keeps an emulated screen of its output, so the server can render it to any number of clients and keep it alive while none are attached.

Index

Constants

View Source
const (
	StatusIdle    = "idle"
	StatusWorking = "working"
	StatusDone    = "done"
	StatusBlocked = "blocked"
	StatusError   = "error"
)

The states a report carries. `clear` is not a state: it removes records.

View Source
const (
	BlockedPermission = "permission"
	BlockedQuestion   = "question"
	BlockedAuth       = "auth"
)

The reasons a program can be blocked.

Variables

View Source
var ErrFDTooHigh = errors.New("file descriptor is above select's limit")

ErrFDTooHigh is returned for a descriptor select cannot wait on.

View Source
var ErrNotRunning = errors.New("pane: not running")

ErrNotRunning means the pane's program has exited, so there is nothing to hand over.

Functions

func FormatStatus added in v0.1.8

func FormatStatus(rec ProgramStatus) string

FormatStatus writes a record the way a program sends one: the body of an OSC 7501, pairs separated by colons, free text base64. It is here beside parseStatus so one file owns the wire format in both directions — conch reads these off a pty as the terminal, and sends them up its own stdout as a program (internal/tui/hoststatus.go), and the two halves drifting apart is the failure nobody would see until a terminal somewhere said nothing.

Zero fields are left out rather than sent empty: a program says what it knows. State is the one required key, so a record without one is formatted as idle rather than as a body the other side must throw away.

func KeepOnExec

func KeepOnExec(f *os.File) error

KeepOnExec lets a file descriptor survive exec: Go opens files close-on-exec.

func LowFD added in v0.2.1

func LowFD(f *os.File) *os.File

LowFD moves f to the lowest free descriptor when it landed at or past fdSetSize, where select cannot wait on it: the read loop gives up at once and the pane looks alive while nothing it prints is ever shown — a Claude that answered for minutes into a blank pane (2026-11-16, with FSEvents holding ~900 descriptors). The table is often only full while something holds it, and a reloaded server takes its panes before it watches anything, so moving the descriptor down rescues the pane. f is closed when it is moved; when nothing lower is free it is returned as it was.

func ParseKey

func ParseKey(s string) (uv.KeyPressEvent, error)

ParseKey parses key notation such as "enter", "ctrl+c", "alt+x", "shift+tab" or "ctrl+shift+left".

func StatusSequence added in v0.1.8

func StatusSequence(rec ProgramStatus) string

StatusSequence is FormatStatus wrapped as the escape itself, ready to write to a terminal.

Types

type Options

type Options struct {
	ID      string
	Name    string
	Command []string
	Cwd     string
	BaseEnv []string // environment to start from; nil means the server's
	Env     []string // extra KEY=VALUE entries appended to BaseEnv
	Cols    int
	Rows    int
}

Options configures a new pane.

type Pane

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

Pane is one program running on a PTY.

func Adopt

func Adopt(snap Snapshot, ptmx *os.File) (*Pane, error)

Adopt takes over a pane another server process detached: the program is still running (and still this process's child after exec) on ptmx.

func Start

func Start(opts Options) (*Pane, error)

Start launches the program and begins mirroring its output.

func (*Pane) Changed

func (p *Pane) Changed() <-chan struct{}

Changed returns a channel that is closed at the next screen change.

func (*Pane) Close

func (p *Pane) Close()

Close terminates the program (SIGHUP to its process group, then SIGKILL) and waits for it to exit.

func (*Pane) Detach

func (p *Pane) Detach() (Snapshot, *os.File, error)

Detach stops reading the program's output and returns a snapshot and the terminal. Output written meanwhile waits in the kernel for whoever reads next. Resume undoes it if the handover fails.

func (*Pane) Done

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

Done is closed when the process has exited.

func (*Pane) Foreground

func (p *Pane) Foreground() (detect.Process, error)

Foreground returns the terminal's foreground process.

func (*Pane) Frame

func (p *Pane) Frame() proto.Frame

Frame renders the visible screen with the cursor drawn in.

func (*Pane) FrameAt

func (p *Pane) FrameAt(offset int) proto.Frame

FrameAt renders the view scrolled offset lines back into history; 0 is the live screen. The offset is clamped to the history available.

func (*Pane) History

func (p *Pane) History() int

History returns how many lines of history the pane has: scrolled off the main screen, or kept from the alternate one.

func (*Pane) ID

func (p *Pane) ID() string

ID returns the pane ID.

func (*Pane) Info

func (p *Pane) Info() proto.PaneInfo

Info returns the pane's metadata.

func (*Pane) PlainLines

func (p *Pane) PlainLines() []string

PlainLines returns the visible screen as unstyled text.

func (*Pane) ProgramStatus added in v0.1.7

func (p *Pane) ProgramStatus() (ProgramStatus, bool)

ProgramStatus is what the program in this pane last said about itself, if it speaks the Program Status Protocol.

func (*Pane) ProgramStatusAll added in v0.1.7

func (p *Pane) ProgramStatusAll() []ProgramStatus

ProgramStatusAll is every record the program is keeping.

func (*Pane) Rename

func (p *Pane) Rename(name string)

Rename sets the pane's name; "" restores the default.

func (*Pane) Repaint added in v0.1.1

func (p *Pane) Repaint() error

Repaint clears the screen conch keeps for the pane and asks the program to draw it again, for when a program left stale text behind — a partial redraw after the pane changed size, say. The program is told the size changed (briefly one column narrower) rather than sent a keystroke, which would land in whatever it is typing.

func (*Pane) Resize

func (p *Pane) Resize(cols, rows int) error

Resize changes the terminal size seen by the program.

func (*Pane) Resume

func (p *Pane) Resume()

Resume restarts reading after a Detach whose handover failed, as soon as the stopped reader has finished.

func (*Pane) Search added in v0.1.4

func (p *Pane) Search(query string, line, col int, backward bool) proto.PaneSearchResult

Search looks for query in the pane's history and screen, from just after (or, backward, just before) line and col, going round once when it reaches either end. Lines count from the oldest line of history, so the screen starts at History; col is in cells. A query without capitals matches either case, as in less and vim's smartcase.

func (*Pane) SendKeys

func (p *Pane) SendKeys(keys []string) error

SendKeys sends named keys, encoded for the program's current terminal modes (e.g. application cursor keys).

func (*Pane) SendKeysApart added in v0.2.1

func (p *Pane) SendKeysApart(keys []string, gap time.Duration) error

SendKeysApart sends keys one at a time with gap after each, and nothing else typed into the pane in between: a lone escape is held by a terminal program for a moment to tell it from the start of an escape sequence, and one followed closely by another key is read with it — escape then x is alt+x, and two escapes are one alt+escape. This is how an agent's interrupt key is sent.

func (*Pane) SendMouse

func (p *Pane) SendMouse(m proto.PaneSendMouseParams) error

SendMouse forwards a mouse event. It does nothing unless the program enabled mouse reporting.

func (*Pane) SendText

func (p *Pane) SendText(text string, paste bool) error

SendText types text into the program. With paste set, the text is wrapped in bracketed-paste markers if the program enabled that mode.

func (*Pane) SubscribeRaw added in v0.1.9

func (p *Pane) SubscribeRaw() (replay string, cols, rows int, sub *RawSub)

SubscribeRaw starts raw output: the replay to begin with, the size it is for, and the subscription carrying what follows.

func (*Pane) Title

func (p *Pane) Title() string

Title returns the last window title the program set.

func (*Pane) UnsubscribeRaw added in v0.1.9

func (p *Pane) UnsubscribeRaw(sub *RawSub)

UnsubscribeRaw ends a subscription. Its channel is not closed: the read loop may hold a piece for it, and the subscriber stops reading.

func (*Pane) Version

func (p *Pane) Version() uint64

Version increases with every screen change.

type ProgramStatus added in v0.1.7

type ProgramStatus struct {
	ID       string    `json:"id,omitempty"`
	State    string    `json:"state"`
	Kind     string    `json:"kind,omitempty"`     // blocked: permission, question, auth
	App      string    `json:"app,omitempty"`      // e.g. claude-code
	Title    string    `json:"title,omitempty"`    // short label
	Msg      string    `json:"msg,omitempty"`      // one line
	Progress int       `json:"progress,omitempty"` // 0..100; -1 when absent
	At       time.Time `json:"at"`
}

ProgramStatus is one record: what a program said about itself, and when. ID is the record's path ("" is the root, "build/test" a child of "build").

func StatusClear added in v0.1.8

func StatusClear(id string) ProgramStatus

StatusClear is the record that removes id and everything under it; with "" it takes conch's own report away entirely, which is what leaving the screen owes the terminal.

type RawSub added in v0.1.9

type RawSub struct {
	C chan []byte
	// contains filtered or unexported fields
}

RawSub is one client's raw output. C carries each piece; once Lost says so, pieces stopped being sent and the client is to start again.

func (*RawSub) Lost added in v0.1.9

func (s *RawSub) Lost() bool

Lost reports whether the subscriber fell behind and missed output.

func (*RawSub) LostC added in v0.1.9

func (s *RawSub) LostC() <-chan struct{}

LostC is closed once the subscriber has fallen behind, so whoever reads C, which will carry nothing more, is woken to start again.

type Snapshot

type Snapshot struct {
	ID         string    `json:"id"`
	Name       string    `json:"name"`
	CustomName string    `json:"custom_name,omitempty"`
	Command    []string  `json:"command"`
	Cwd        string    `json:"cwd"`
	Created    time.Time `json:"created"`
	PID        int       `json:"pid"`
	Cols       int       `json:"cols"`
	Rows       int       `json:"rows"`
	Title      string    `json:"title,omitempty"`
	// Replay is terminal output that rebuilds the history, the screen, the
	// cursor and the modes in a fresh emulator.
	Replay string `json:"replay"`
	// AltHistory is what conch kept as it scrolled off the alternate screen
	// (altscroll.go): text read off the screen, which no replay can rebuild.
	// Empty on the main screen, and in a snapshot from an older server.
	AltHistory []string `json:"alt_history,omitempty"`
	// Status is what the program said about itself through the Program
	// Status Protocol (status.go). It has to travel: a program reports
	// when its state changes, so one that said "blocked" an hour ago and
	// is still waiting will not say it again for the new server. Empty in
	// a snapshot from an older server, and for the programs that do not
	// speak it.
	Status []ProgramStatus `json:"status,omitempty"`
}

Snapshot is what a new server process needs to adopt a running pane: its metadata and a replay of its screen. The terminal itself is handed over as an open file descriptor.

Jump to

Keyboard shortcuts

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