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
- Variables
- func FormatStatus(rec ProgramStatus) string
- func KeepOnExec(f *os.File) error
- func LowFD(f *os.File) *os.File
- func ParseKey(s string) (uv.KeyPressEvent, error)
- func StatusSequence(rec ProgramStatus) string
- type Options
- type Pane
- func (p *Pane) Changed() <-chan struct{}
- func (p *Pane) Close()
- func (p *Pane) Detach() (Snapshot, *os.File, error)
- func (p *Pane) Done() <-chan struct{}
- func (p *Pane) Foreground() (detect.Process, error)
- func (p *Pane) Frame() proto.Frame
- func (p *Pane) FrameAt(offset int) proto.Frame
- func (p *Pane) History() int
- func (p *Pane) ID() string
- func (p *Pane) Info() proto.PaneInfo
- func (p *Pane) PlainLines() []string
- func (p *Pane) ProgramStatus() (ProgramStatus, bool)
- func (p *Pane) ProgramStatusAll() []ProgramStatus
- func (p *Pane) Rename(name string)
- func (p *Pane) Repaint() error
- func (p *Pane) Resize(cols, rows int) error
- func (p *Pane) Resume()
- func (p *Pane) Search(query string, line, col int, backward bool) proto.PaneSearchResult
- func (p *Pane) SendKeys(keys []string) error
- func (p *Pane) SendKeysApart(keys []string, gap time.Duration) error
- func (p *Pane) SendMouse(m proto.PaneSendMouseParams) error
- func (p *Pane) SendText(text string, paste bool) error
- func (p *Pane) SubscribeRaw() (replay string, cols, rows int, sub *RawSub)
- func (p *Pane) Title() string
- func (p *Pane) UnsubscribeRaw(sub *RawSub)
- func (p *Pane) Version() uint64
- type ProgramStatus
- type RawSub
- type Snapshot
Constants ¶
const ( StatusIdle = "idle" StatusWorking = "working" StatusDone = "done" StatusBlocked = "blocked" StatusError = "error" )
The states a report carries. `clear` is not a state: it removes records.
const ( BlockedPermission = "permission" BlockedQuestion = "question" BlockedAuth = "auth" )
The reasons a program can be blocked.
Variables ¶
var ErrFDTooHigh = errors.New("file descriptor is above select's limit")
ErrFDTooHigh is returned for a descriptor select cannot wait on.
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 ¶
KeepOnExec lets a file descriptor survive exec: Go opens files close-on-exec.
func LowFD ¶ added in v0.2.1
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 ¶
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 (*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 ¶
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 ¶
Foreground returns the terminal's foreground process.
func (*Pane) FrameAt ¶
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 ¶
History returns how many lines of history the pane has: scrolled off the main screen, or kept from the alternate one.
func (*Pane) PlainLines ¶
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) Repaint ¶ added in v0.1.1
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) 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
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 ¶
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
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 ¶
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
SubscribeRaw starts raw output: the replay to begin with, the size it is for, and the subscription carrying what follows.
func (*Pane) UnsubscribeRaw ¶ added in v0.1.9
UnsubscribeRaw ends a subscription. Its channel is not closed: the read loop may hold a piece for it, and the subscriber stops reading.
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.
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.