Documentation
¶
Overview ¶
Package client implements `ptyd term attach`, an interactive client for a terminal running in the daemon.
Index ¶
- Constants
- Variables
- func Find(list []terminal.Info, target string) (terminal.Info, error)
- func FlushInput(in *os.File) error
- func IdentityColor(id string, background phosphor.RGB) phosphor.RGB
- func IdentityStyle(id string, background phosphor.RGB) string
- func MouseReportLength(p []byte) (int, bool)
- func NewToken() string
- func OffsetRowANSI(data []byte, columns int) []byte
- func PersistDir(addr string) (string, error)
- func ProbeColors(ctx context.Context, in, out *os.File) (*terminal.TerminalColors, []byte)
- func ProbeKeyboard(ctx context.Context, in, out *os.File) (bool, []byte)
- func TerminalEnvironment() terminal.TerminalEnvironment
- func Token(addr string) string
- func TokenFile(addr string) (string, error)
- func UsesTerminalTitle(name, provider string) bool
- func WithoutANSIColors(data []byte) []byte
- func WriteToken(addr, token string) (string, error)
- type API
- func (c API) Agents(ctx context.Context) (native.Listing, error)
- func (c API) Do(method, path string, body, out any) error
- func (c API) DoContext(ctx context.Context, method, path string, body, out any) error
- func (c API) Find(target string) (terminal.Info, error)
- func (c API) FindGroup(ctx context.Context, target string) (terminal.Group, error)
- func (c API) Groups(ctx context.Context) ([]terminal.GroupSummary, error)
- func (c API) ImportAgent(ctx context.Context, request terminal.ImportRequest) (terminal.ImportResult, error)
- func (c API) List() ([]terminal.Info, error)
- func (c API) Overview(ctx context.Context, options terminal.OverviewOptions) (terminal.Overview, error)
- func (c API) Preview(ctx context.Context, id terminal.ID) (*phosphor.Terminal, error)
- func (c API) SearchContents(ctx context.Context, overview terminal.Overview, query string) ContentSearch
- func (c API) TerminalTitle(ctx context.Context, id terminal.ID) (string, error)
- type AttachResult
- type ContentMatch
- type ContentSearch
- type ContentSearchIssue
- type HTTPError
- type Input
- type MouseEvent
- type Options
- type SessionCaption
Constants ¶
const (
BackKeyWindow = 200 * time.Millisecond
)
const DetachKeyHelp = "jk (j, then k quickly)"
DetachKeyHelp names the home-row sequence, typed in order rather than held.
Variables ¶
var ErrDaemonDown = errors.New("ptyd is not running")
ErrDaemonDown means nothing answers at the daemon's address.
var ErrOverviewCapabilities = errors.New("daemon does not support live-session filtering; restart the updated daemon")
Functions ¶
func FlushInput ¶ added in v0.5.0
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
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 MouseReportLength ¶ added in v0.6.0
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 OffsetRowANSI ¶ added in v0.13.0
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 ¶
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
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
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 ¶
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 ¶
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 WithoutANSIColors ¶ added in v0.10.0
WithoutANSIColors keeps layout and character attributes (including conceal) while removing color changes from a canonical rendered row.
func WriteToken ¶
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 ¶
API is a client for the daemon's HTTP API, for the command line.
func (API) Do ¶
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
DoContext lets live clients cancel an in-flight refresh when they close.
func (API) Find ¶
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) ImportAgent ¶ added in v0.5.0
func (c API) ImportAgent(ctx context.Context, request terminal.ImportRequest) (terminal.ImportResult, error)
func (API) Preview ¶ added in v0.10.0
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.
type AttachResult ¶ added in v0.4.0
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 HTTPError ¶ added in v0.4.0
HTTPError retains the response status for operations that can explain how to recover from an unsupported endpoint.
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
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.
type MouseEvent ¶ added in v0.13.0
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
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