Documentation
¶
Overview ¶
Package tmux is a thin domain client around the tmux CLI.
Index ¶
- Variables
- func Target(name string) string
- type Client
- func (c *Client) ApplyPaneThemes(themes []PaneTheme) error
- func (c *Client) CapturePane(name string, lines int) (string, error)
- func (c *Client) ClearTabGroup(names []string) error
- func (c *Client) Kill(name string) error
- func (c *Client) ListPanes() ([]Pane, error)
- func (c *Client) NewSession(name, workdir, shellCmd string, env map[string]string) error
- func (c *Client) PaneForeground(name string) (PaneForeground, error)
- func (c *Client) PaneForegrounds() map[string]PaneForeground
- func (c *Client) PasteLiteral(name, text string) error
- func (c *Client) Rename(oldName, newName string) error
- func (c *Client) SendKey(name, key string) error
- func (c *Client) SendLiteral(name, text string) error
- func (c *Client) SendRaw(name string, data []byte) error
- func (c *Client) SetHistoryLimit(name string, historyLimit int) error
- func (c *Client) SetOption(name, option, value string) error
- func (c *Client) SetPaneStyle(name, style string) error
- func (c *Client) SetTabGroup(members []TabGroupMember, group, groupName string) error
- func (c *Client) SetTabGroupColumn(name string, col int) error
- func (c *Client) SetTabGroupEntry(name, group string, pos, col int, groupName string) error
- func (c *Client) SetTabGroupName(names []string, groupName string) error
- func (c *Client) SetTabPosition(name string, pos int) error
- func (c *Client) SetTabPositions(names []string) error
- func (c *Client) StopPipe(name string) error
- type Control
- func (c *Control) CaptureWindow(off, height int) ([]byte, int64, error)
- func (c *Control) Close() error
- func (c *Control) Delta(offset int64) ([]byte, int64, bool)
- func (c *Control) Exited() bool
- func (c *Control) HistorySize() (int, error)
- func (c *Control) Modes() PaneModes
- func (c *Control) Notify()
- func (c *Control) PaneForeground(name string) (PaneForeground, error)
- func (c *Control) PaneSize() (Size, error)
- func (c *Control) Resize(cols, rows int) error
- func (c *Control) SendKey(name, key string) error
- func (c *Control) SendLiteral(name, text string) error
- func (c *Control) SendRaw(name string, data []byte) error
- func (c *Control) Settle(startWait, quiet, maxWait time.Duration)
- func (c *Control) Snapshot() ([]byte, int64, error)
- func (c *Control) Updated() <-chan struct{}
- type OSCFilter
- type Pane
- type PaneForeground
- type PaneModes
- type PaneTheme
- type Size
- type TabGroupMember
Constants ¶
This section is empty.
Variables ¶
var RequiredTools = []string{"tmux"}
RequiredTools lists external binaries tmux relies on.
Functions ¶
Types ¶
type Client ¶
type Client struct{}
Client wraps the tmux CLI.
func (*Client) ApplyPaneThemes ¶
ApplyPaneThemes styles panes and injects the optional reports in one tmux invocation, so a theme change costs a single process spawn regardless of session count. tmux aborts the command chain on the first error (e.g. a session that just died), remaining panes keep their old style then; the caller is expected to re-apply on the next occasion.
func (*Client) CapturePane ¶
CapturePane returns what the pane shows plus the last lines of its scrollback. Read only in the strict sense: capture-pane never attaches, so the pane keeps the size the client that owns it gave it. Going through the terminal hub instead would resize the pane to the reader's window.
func (*Client) ClearTabGroup ¶
ClearTabGroup removes the split view group options from the sessions, in one tmux invocation.
func (*Client) NewSession ¶
NewSession spawns a detached tmux session. The command runs under an interactive login bash so the full profile chain including ~/.bashrc applies, matching a command typed into a normal shell. An empty shellCmd starts the interactive bash itself.
func (*Client) PaneForeground ¶
func (c *Client) PaneForeground(name string) (PaneForeground, error)
PaneForeground returns one session's foreground process state.
func (*Client) PaneForegrounds ¶
func (c *Client) PaneForegrounds() map[string]PaneForeground
PaneForegrounds returns every session's foreground process (first pane only), from a single list-panes call.
func (*Client) PasteLiteral ¶
PasteLiteral pastes literal text through a temporary tmux buffer.
func (*Client) SendLiteral ¶
SendLiteral sends literal text without key interpretation.
func (*Client) SendRaw ¶
SendRaw injects an exact byte sequence into a pane via send-keys -H (each byte as a hex key code). Unlike SendKey/SendLiteral it does no interpretation, so it carries whatever a browser terminal's onData emits verbatim: printable UTF-8 (including composed accents), control bytes, and escape sequences.
func (*Client) SetHistoryLimit ¶
SetHistoryLimit configures how much scrollback tmux keeps for snapshots.
func (*Client) SetPaneStyle ¶
SetPaneStyle sets a pane's default colors (style like "bg=#111827,fg=#f9fafb"). tmux answers a pane program's OSC 11 background query from this style, so it is how a session signals light or dark to TUIs while only the control mode client is attached, which never answers such queries itself.
func (*Client) SetTabGroup ¶
func (c *Client) SetTabGroup(members []TabGroupMember, group, groupName string) error
SetTabGroup writes a split view group onto its member sessions, first member is group position 1. The optional display name rides along when non-empty, a column of 0 takes the column option off the session. All assignments go into one tmux invocation.
func (*Client) SetTabGroupColumn ¶
SetTabGroupColumn writes one member's column, used when a pane created into a split names a column that was never written down.
func (*Client) SetTabGroupEntry ¶
SetTabGroupEntry writes one session's group membership: the startup terminal restore re-applies a recorded one, the create-into-a-split path writes a fresh one onto the session it just started.
func (*Client) SetTabGroupName ¶
SetTabGroupName writes the group display name onto every member, empty removes it (the strip falls back to the joined member names).
func (*Client) SetTabPosition ¶
SetTabPosition writes one session's tab strip position, used by the startup terminal restore to re-apply a recorded order onto a recreated session.
func (*Client) SetTabPositions ¶
SetTabPositions writes the tab strip order onto the sessions, first name is position 1. All assignments ride in one tmux invocation, so a reorder costs a single process spawn regardless of session count.
type Control ¶
type Control struct {
// contains filtered or unexported fields
}
Control is a tmux control-mode client (`tmux -C attach-session`) for one session. It feeds raw pane output into an in-memory ring and answers capture requests on the same ordered channel, so a snapshot and the byte offset that follows it are taken atomically — no pipe-pane log and no snapshot/stream seam where output can be lost or duplicated.
func StartControl ¶
StartControl spawns the control-mode client and blocks until it is ready.
func (*Control) CaptureWindow ¶
CaptureWindow captures height lines of the pane starting off lines back in the scrollback (off 0 is the live screen), for history scrolling. It returns the frame and the stream offset that immediately follows it. The frame carries no cursor — a scrolled history view has none.
func (*Control) Delta ¶
Delta returns the buffered bytes after offset and the new offset. reset is true when offset has fallen out of the ring and the caller must re-snapshot.
func (*Control) Exited ¶
Exited reports whether the control client has detached or the session ended.
func (*Control) HistorySize ¶
HistorySize reports how many lines of scrollback sit above the visible pane.
func (*Control) Modes ¶
Modes reads the pane's current terminal modes from tmux. The browser keeps xterm's own mouse reporting disabled (to preserve text selection), so it uses these to synthesize the wheel input each program expects.
func (*Control) Notify ¶
func (c *Control) Notify()
Notify wakes all waiters explicitly (e.g. after a resize changed the pane).
func (*Control) PaneForeground ¶
func (c *Control) PaneForeground(name string) (PaneForeground, error)
PaneForeground reports the pane's foreground process state over the control connection, so per-keystroke decisions (Shift+Enter) fork nothing.
func (*Control) SendLiteral ¶
SendLiteral sends literal text over this connection. It is encoded as hex (like SendRaw) so command-line quoting never enters into it.
func (*Control) SendRaw ¶
SendRaw injects an exact byte sequence over this persistent connection, mirroring Client.SendRaw but with no fork per keystroke. Bytes go as hex key codes (send-keys -H) so control/escape bytes pass through verbatim.
func (*Control) Settle ¶
Settle waits for the repaint a resize triggers to begin and then go quiet, so a following Snapshot captures a finished frame instead of a half-drawn one. Phase one waits (up to startWait) for the program to start repainting; phase two waits for output to fall quiet, bounded by maxWait. A program that does not repaint on resize simply returns after startWait.
type OSCFilter ¶
type OSCFilter struct {
// contains filtered or unexported fields
}
OSCFilter strips OSC escape sequences (e.g. terminal title updates) from a byte stream. Unlike a stateless strip it carries its state across chunks, so sequences split at arbitrary read boundaries cannot leak through.
func (*OSCFilter) Filter ¶
Filter returns chunk with OSC sequences removed, holding back an unterminated sequence (or trailing lone ESC) until the next chunk.
func (*OSCFilter) FilterMarks ¶
FilterMarks behaves like Filter and additionally returns the payloads of every OSC sequence completed within this chunk (state carries across chunks, so split sequences still yield one complete payload).
type Pane ¶
type Pane struct {
Name string
PID string
StartedAt string // unix epoch seconds, raw
ShellName string // @dc_shell_name option; non-empty marks a shell session
Workdir string // @dc_shell_dir option; the shell's start directory, if any
Coder string // @dc_coder option; non-empty marks a coder pane and names its coder
CoderName string // @dc_coder_name option; the coder's display name at launch
CoderDir string // @dc_coder_dir option; the coder's start directory
TabPos string // @dc_tab_pos option; the session's tab strip position, raw
TabGroup string // @dc_tab_group option; non-empty puts the session into a split view group
TabGPos string // @dc_tab_gpos option; the session's position inside its group, raw
TabGName string // @dc_tab_gname option; the group's display name, duplicated on every member
TabGCol string // @dc_tab_gcol option; the column the member's pane renders in, raw
}
Pane is one tmux session entry as reported by `tmux list-panes`.
func (Pane) TabGroupColumn ¶
TabGroupColumn parses the column the member's pane renders in; 0 when unset or invalid, which renders the member as a column of its own.
func (Pane) TabGroupPosition ¶
TabGroupPosition parses the pane's position inside its split view group; 0 when unset or invalid, which sorts the member after every positioned one.
func (Pane) TabPosition ¶
TabPosition parses the pane's tab strip position; 0 when unset or invalid, which sorts the session after every positioned one.
type PaneForeground ¶
PaneForeground describes a session's foreground process state. AltScreen separates a full screen TUI (claude's interactive mode) from plain command runs like `claude -p` that share the process name.
type PaneModes ¶
type PaneModes struct {
MouseTracking bool // mouse reporting on (wheel -> mouse events, e.g. claude)
MouseSGR bool // SGR mouse encoding (mode 1006)
AltScreen bool // alternate screen active (full-screen TUI -> cursor keys)
AppCursor bool // application cursor keys (DECCKM: ESC O A/B vs ESC [ A/B)
}
PaneModes are terminal modes the browser needs to reproduce wheel scrolling the way the program expects. They matter most when attaching to an already running program, whose mode-set sequences are not part of a screen snapshot, so the browser can't learn them by replaying the stream.
type TabGroupMember ¶
TabGroupMember is one session's place in a split view group: the tmux session name and the column its pane renders in, 0 for a column of its own.