client

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 31 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 client implements `ptyd term attach`, an interactive client for a terminal running in the daemon.

Index

Constants

View Source
const (
	BackKeyWindow = 200 * time.Millisecond
)
View Source
const DetachKeyHelp = "jk (j, then k quickly)"

DetachKeyHelp names the home-row sequence, typed in order rather than held.

Variables

View Source
var ErrDaemonDown = errors.New("ptyd is not running")

ErrDaemonDown means nothing answers at the daemon's address.

View Source
var ErrOverviewCapabilities = errors.New("daemon does not support live-session filtering; restart the updated daemon")

Functions

func Find

func Find(list []terminal.Info, target string) (terminal.Info, error)

Find picks the terminal target names from list (see API.Find).

func FlushInput added in v0.5.0

func FlushInput(in *os.File) error

FlushInput drops keys typed before a newly imported native view is ready. The input reader must be stopped first so it cannot race this handoff.

func IdentityColor added in v0.13.0

func IdentityColor(id string, background phosphor.RGB) phosphor.RGB

IdentityColor varies the hue with the immutable id, so names, navigation and restarts keep the same accent without another stored setting. Light themes use darker accents. Text and icons still identify every state without color.

func IdentityStyle added in v0.13.0

func IdentityStyle(id string, background phosphor.RGB) string

func MouseReportLength added in v0.6.0

func MouseReportLength(p []byte) (int, bool)

MouseReportLength frames legacy X10 and UTF-8 mouse fields conservatively. Invalid UTF-8 bytes remain single legacy fields. In an ambiguous legacy packet this can include a following key; bytes still pass through unchanged rather than interpreting mouse data as a local shortcut.

func NewToken

func NewToken() string

NewToken returns a random token.

func OffsetRowANSI added in v0.13.0

func OffsetRowANSI(data []byte, columns int) []byte

OffsetRowANSI translates absolute horizontal positions in AppendRowANSI's output. Callers paint tiles from left to right: the canonical renderer's temporary inserts can touch the still-unpainted space to their right. Clear that space in default style before painting the next tile or chrome. This accepts rendered rows, never arbitrary program output.

func PersistDir

func PersistDir(addr string) (string, error)

PersistDir is the default --persist-dir of the daemon listening on addr: $XDG_STATE_HOME/ptyd/terminals-<port>.

func ProbeColors added in v0.8.0

func ProbeColors(ctx context.Context, in, out *os.File) (*terminal.TerminalColors, []byte)

ProbeColors asks the actual viewing terminal before starting a frontend. It has exclusive input ownership only during this bounded startup probe; unrelated keys and unfinished frames are returned for the normal reader.

func ProbeKeyboard added in v0.13.0

func ProbeKeyboard(ctx context.Context, in, out *os.File) (bool, []byte)

ProbeKeyboard verifies the viewing terminal rather than inferring support from modes the child asked Phosphor to enable. Unrelated input is preserved.

func TerminalEnvironment added in v0.7.0

func TerminalEnvironment() terminal.TerminalEnvironment

TerminalEnvironment captures absence too: a terminal that has no NO_COLOR must not inherit it from the background daemon.

func Token

func Token(addr string) string

Token returns the token to send to the daemon at addr: $PTYD_TOKEN if set, else the one the daemon saved in TokenFile.

func TokenFile

func TokenFile(addr string) (string, error)

TokenFile is where the daemon listening on addr keeps its token: $XDG_STATE_HOME/ptyd/token-<port>, by default under ~/.local/state.

func UsesTerminalTitle added in v0.13.0

func UsesTerminalTitle(name, provider string) bool

func WithoutANSIColors added in v0.10.0

func WithoutANSIColors(data []byte) []byte

WithoutANSIColors keeps layout and character attributes (including conceal) while removing color changes from a canonical rendered row.

func WriteToken

func WriteToken(addr, token string) (string, error)

WriteToken saves the token of the daemon listening on addr for the CLI, readable only by this user (0600 in a 0700 directory). It returns the file's path.

Types

type API

type API struct {
	Addr  string
	Token string
}

API is a client for the daemon's HTTP API, for the command line.

func (API) Agents added in v0.5.0

func (c API) Agents(ctx context.Context) (native.Listing, error)

func (API) Do

func (c API) Do(method, path string, body, out any) error

Do sends a request and decodes a JSON reply into out (if not nil). Its errors are meant for a person: a daemon that is not running, a token that was refused, or the daemon's own error message.

func (API) DoContext added in v0.4.0

func (c API) DoContext(ctx context.Context, method, path string, body, out any) error

DoContext lets live clients cancel an in-flight refresh when they close.

func (API) Find

func (c API) Find(target string) (terminal.Info, error)

Find returns the terminal target names: its id, its number (3 for term-3-ab12), a unique name, or a unique id prefix.

func (API) FindGroup added in v0.9.0

func (c API) FindGroup(ctx context.Context, target string) (terminal.Group, error)

func (API) Groups added in v0.9.0

func (c API) Groups(ctx context.Context) ([]terminal.GroupSummary, error)

func (API) ImportAgent added in v0.5.0

func (c API) ImportAgent(ctx context.Context, request terminal.ImportRequest) (terminal.ImportResult, error)

func (API) List

func (c API) List() ([]terminal.Info, error)

List returns all terminals, oldest first.

func (API) Overview added in v0.4.0

func (c API) Overview(ctx context.Context, options terminal.OverviewOptions) (terminal.Overview, error)

func (API) Preview added in v0.10.0

func (c API) Preview(ctx context.Context, id terminal.ID) (*phosphor.Terminal, error)

Preview reads one atomic snapshot without attaching, claiming input or resizing.

func (API) SearchContents added in v0.13.0

func (c API) SearchContents(ctx context.Context, overview terminal.Overview, query string) ContentSearch

SearchContents reads the same exact snapshots used by live panes. Four workers bound transient models and HTTP requests; models are released after matching. It never attaches, resizes, claims input or reads another program's files.

func (API) TerminalTitle added in v0.13.0

func (c API) TerminalTitle(ctx context.Context, id terminal.ID) (string, error)

type AttachResult added in v0.4.0

type AttachResult struct {
	Detached     bool
	PendingInput []byte
}

AttachResult describes the handoff back to the caller. PendingInput contains bytes after an explicit detach gesture and any later bytes the reader had not delivered. Failures and ordinary program exit never return queued input.

func Attach

func Attach(ctx context.Context, opts Options, in, out *os.File, winch <-chan os.Signal) (result AttachResult, err error)

Attach connects in and out (the user's terminal) to a terminal in the daemon until the user detaches (Detached is true) or the attachment ends: the terminal's output ended, or the connection to the daemon broke. winch signals a local window size change.

The local window is handed over cleanly in both directions: on attach what it showed scrolls into its scrollback; on detach the terminal's window does too and the user gets a blank window; when the attachment ends, the last window stays in view with the cursor on a clean line below it. Either way the modes the program switched on are reset.

type ContentMatch added in v0.13.0

type ContentMatch struct {
	TerminalID terminal.ID      `json:"terminal_id"`
	GroupID    terminal.GroupID `json:"group_id"`
	Name       string           `json:"name"`
	Source     string           `json:"source"` // screen, scrollback or session metadata
	Text       string           `json:"text"`
	ScreenRow  int              `json:"screen_row"` // -1 unless the match is on the visible screen
}

func MatchContents added in v0.13.0

func MatchContents(row terminal.SessionSummary, view *phosphor.Terminal, query string) (*ContentMatch, error)

MatchContents prefers a visible hit, then the most recent retained logical history line. Session fields remain searchable as a secondary convenience.

type ContentSearch added in v0.13.0

type ContentSearch struct {
	Matches    []ContentMatch       `json:"matches"`
	Issues     []ContentSearchIssue `json:"issues"`
	Checked    int                  `json:"checked"`
	Candidates int                  `json:"candidates"`
	Complete   bool                 `json:"complete"`
}

type ContentSearchIssue added in v0.13.0

type ContentSearchIssue struct {
	TerminalID terminal.ID `json:"terminal_id"`
	Message    string      `json:"message"`
}

type HTTPError added in v0.4.0

type HTTPError struct {
	Status  int
	Message string
}

HTTPError retains the response status for operations that can explain how to recover from an unsupported endpoint.

func (*HTTPError) Error added in v0.4.0

func (e *HTTPError) Error() string

type Input added in v0.4.0

type Input struct {
	Bytes <-chan []byte
	// contains filtered or unexported fields
}

Input reads from a file until EOF, a read error, or cancellation. The caller owns the file and must give this reader exclusive access until Close returns. Each received byte slice belongs to the receiver.

func NewInput added in v0.4.0

func NewInput(ctx context.Context, in *os.File, initial []byte) (*Input, error)

NewInput starts a reader without changing the file's mode or descriptor flags. Cancellation wakes an idle poll immediately; it does not close the caller's file or wait for another keystroke. Initial bytes are copied and delivered before reading the file.

func (*Input) Close added in v0.4.0

func (in *Input) Close()

Close cancels and joins the reader. It is safe to call more than once or from several goroutines. It discards undelivered bytes; use Remainder instead when handing them to another owner.

func (*Input) Remainder added in v0.4.0

func (in *Input) Remainder() []byte

Remainder stops and joins the reader, then transfers any bytes it read but did not deliver. Call it instead of Close for a handoff. Later calls return no bytes. Once it returns, another owner may read the file.

type MouseEvent added in v0.13.0

type MouseEvent struct {
	Button, X, Y int
	Release      bool
}

MouseEvent uses terminal coordinates (1-based) and the xterm button/modifier encoding. SGR releases use a separate final byte; legacy releases use button3.

func ParseMouseReport added in v0.13.0

func ParseMouseReport(p []byte) (MouseEvent, bool)

ParseMouseReport accepts one complete SGR, legacy X10/UTF-8 or urxvt report. It does not reinterpret partial, malformed or oversized coordinates as keys.

func (MouseEvent) LeftPress added in v0.13.0

func (m MouseEvent) LeftPress() bool

type Options

type Options struct {
	Addr     string // host:port of the daemon
	Token    string
	ID       string
	GroupID  terminal.GroupID
	Human    bool
	ReadOnly bool
	Label    string
	Caption  *SessionCaption
	Hold     bool
	Raw      bool // pass bytes directly; no reserved status row

	// InitialInput precedes bytes read from the local terminal.
	InitialInput   []byte
	ViewerColors   *terminal.TerminalColors // known host theme; used only for status chrome
	ViewerKeyboard *bool                    // nil probes actual host Kitty keyboard support
	// contains filtered or unexported fields
}

Options configure Attach.

type SessionCaption added in v0.13.0

type SessionCaption struct {
	Name, Provider, Group string
	Captain               bool
}

SessionCaption combines agent identity with a useful display name. Titles are presentation metadata; they never identify a conversation for input or resume.

func (SessionCaption) Label added in v0.13.0

func (c SessionCaption) Label(title string) string

func (SessionCaption) Session added in v0.13.0

func (c SessionCaption) Session(title string) string

func (SessionCaption) Title added in v0.13.0

func (c SessionCaption) Title(title string) string

Jump to

Keyboard shortcuts

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