ttywatch

package
v0.0.45 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsScreenSnapshotFrame

func IsScreenSnapshotFrame(data []byte) bool

IsScreenSnapshotFrame reports ptywrap screen snapshot binary frames.

func IsServeSubcommand

func IsServeSubcommand(arg string) bool

IsServeSubcommand reports whether arg is a slug-based serve reexec token.

func PrepareSessionInjectMode

func PrepareSessionInjectMode(listenAddr, sessionID string) error

PrepareSessionInjectMode disables canonical mode before injecting input.

func ProcessAlive

func ProcessAlive(pid int) bool

ProcessAlive reports whether pid responds to signal 0.

func ReadSnapshot

func ReadSnapshot(listenAddr, sessionID string) (frame string, scrollback string, cols, rows int, err error)

ReadSnapshot fetches the current screen frame and scrollback for a live session.

func RemoveRegistry

func RemoveRegistry(home, sessionID string)

RemoveRegistry deletes the registry file for a session.

func RemoveRegistryIfMatch

func RemoveRegistryIfMatch(home, sessionID, listenAddr string, pid int)

RemoveRegistryIfMatch deletes the registry file only when the on-disk entry still belongs to the caller (same listen address and pid). Stale __serve__ cleanup can otherwise delete a newer session that reused the same session id.

func RenderObserverFrame

func RenderObserverFrame(data []byte, cols, rows int) []byte

RenderObserverFrame converts observer-mode PTY bytes to visible text without CSI/C0 leaks.

func RenderSnapshotOutput

func RenderSnapshotOutput(frame, scrollback string, cols, rows int) string

RenderSnapshotOutput converts a ptywrap screen snapshot frame and/or raw scrollback into printable snapshot text, matching the screen attach pipeline used by run.

func RenderSnapshotScrollback

func RenderSnapshotScrollback(raw string, cols, rows int) string

RenderSnapshotScrollback converts accumulated scrollback to printable snapshot text.

func RenderVTStateToText

func RenderVTStateToText(vt vt10x.Terminal, cols, rows int) ([]byte, bool)

RenderVTStateToText extracts printable lines from a vt10x terminal state.

func ReserveCustomSessionID

func ReserveCustomSessionID(home, sessionID string) (func(), error)

ReserveCustomSessionID validates id and ensures it is not held by a live session. Stale registry entries are pruned so the id can be reused.

func ReserveRegistrySessionID

func ReserveRegistrySessionID(home string) (string, func(), error)

ReserveRegistrySessionID returns the next session-N id under flock.

func SanitizeForPrint

func SanitizeForPrint(data string) string

SanitizeForPrint strips CSI, OSC, and C0 control sequences except \n \r \t.

func ScreenSnapshotToText

func ScreenSnapshotToText(data []byte, cols, rows int) ([]byte, bool)

ScreenSnapshotToText renders a screen snapshot frame to plain text.

func ServeSession

func ServeSession(ctx context.Context, opts ServeOptions) error

ServeSession runs the embedded ptywrap HTTP server until the command exits.

func ServeSubcommand

func ServeSubcommand(argv []string) string

ServeSubcommand wraps SlugifyCommandLine as the internal reexec argv token.

func SlugifyCommandLine

func SlugifyCommandLine(argv []string) string

SlugifyCommandLine produces a stable slug from a session command argv.

func SnapshotText

func SnapshotText(listenAddr, sessionID string) (string, error)

SnapshotText returns rendered printable snapshot text for a live session.

func TCPReachable

func TCPReachable(addr string) bool

TCPReachable reports whether a TCP listen address accepts connections.

func TTYWatchHome

func TTYWatchHome() (string, error)

TTYWatchHome returns the tty-watch data directory.

func WriteRegistry

func WriteRegistry(home string, entry RegistryEntry) error

WriteRegistry creates the registry file for a live session.

Types

type EphemeralSession

type EphemeralSession struct {
	Home       string
	SessionID  string
	Command    []string
	ExtraPaths []string
	// contains filtered or unexported fields
}

EphemeralSession manages a short-lived tty-watch session without CLI subprocesses.

func NewEphemeralSession

func NewEphemeralSession(home, sessionID string, command []string) *EphemeralSession

NewEphemeralSession returns a session scoped to home, id, and command argv.

func (*EphemeralSession) Entry

func (s *EphemeralSession) Entry() *RegistryEntry

Entry returns the current registry entry when available.

func (*EphemeralSession) Kill

func (s *EphemeralSession) Kill() error

Kill terminates the session and removes its registry entry.

func (*EphemeralSession) Send

func (s *EphemeralSession) Send(message string) error

Send injects follow-up text into the live session.

func (*EphemeralSession) Snapshot

func (s *EphemeralSession) Snapshot() (string, error)

Snapshot returns rendered printable snapshot text.

func (*EphemeralSession) StartDetached

func (s *EphemeralSession) StartDetached(ctx context.Context, binaryPath string) error

StartDetached re-executes binaryPath with a slug-based serve token.

func (*EphemeralSession) StartInProcess

func (s *EphemeralSession) StartInProcess(ctx context.Context) error

StartInProcess launches ServeSession in the current process.

func (*EphemeralSession) WaitWritable

func (s *EphemeralSession) WaitWritable(provider ttyrunner.Provider, timeout time.Duration) ttyrunner.WritableStatus

WaitWritable polls provider readiness against live scrollback.

type RegistryEntry

type RegistryEntry struct {
	SessionID  string   `json:"session_id"`
	ListenAddr string   `json:"listen_addr"`
	PID        int      `json:"pid"`
	CreatedAt  string   `json:"created_at"`
	Command    []string `json:"command"`
	Cwd        string   `json:"cwd,omitempty"`
}

RegistryEntry maps a tty-watch session id to the embedded ptywrap listen address.

func ListRegistryEntries

func ListRegistryEntries(home string, prune bool) ([]RegistryEntry, error)

ListRegistryEntries returns all registry entries, optionally pruning unreachable ones.

func ReadRegistry

func ReadRegistry(home, sessionID string) (*RegistryEntry, error)

ReadRegistry loads a session registry entry.

func WaitForRegistryEntry

func WaitForRegistryEntry(home, sessionID string, timeout time.Duration) (*RegistryEntry, error)

WaitForRegistryEntry polls until a session registry entry is available.

type ServeOptions

type ServeOptions struct {
	SessionID  string
	Command    []string
	Home       string
	Cwd        string
	ExtraPaths []string
}

ServeOptions configures an embedded PTY server session.

Jump to

Keyboard shortcuts

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