termbridge

package
v0.20.8 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package termbridge owns the daemon-side PTY lifecycle for one terminal socket (kb:anchor/terminal.ws): spawning `tmux attach-session` under a `creack/pty`-managed pseudo-terminal, streaming raw bytes both directions, and resizing with pty.Setsize then tmux resize-window, never the pane-level primitive (kb:adr/surfaces-shared-attach-single-pty). This package knows nothing about WebSockets or sessions — internal/server is the only caller (its own server.go wires Attach in), and owns the socket-level concerns (auth, takeover, frame shapes).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bridge

type Bridge struct {
	// contains filtered or unexported fields
}

Bridge is one daemon-owned PTY attached to a tmux session.

func Attach

func Attach(ctx context.Context, tmuxClient *tmux.Client, target string) (*Bridge, error)

Attach spawns `tmux attach-session -t target` under a fresh PTY, with TERM/LANG set explicitly — without them tmux falls back to ASCII line-drawing and Claude's boxes render as "qqqq", which looks exactly like a rendering bug rather than a missing env var. ctx is exec.CommandContext's context: if it is canceled, the attach process is killed. In practice ctx is the caller's request context, so the Bridge's lifetime tracks that request for as long as it's live, and Close is what tears it down explicitly and idempotently once the caller is done with it either way.

func (*Bridge) Close

func (b *Bridge) Close() error

Close tears down the PTY and the attach process. Safe to call more than once (the terminal handler's takeover path and its own deferred cleanup both call it).

func (*Bridge) Read

func (b *Bridge) Read(p []byte) (int, error)

Read reads raw PTY output verbatim. A macOS PTY read returns EIO once the other end (the attach process) has exited; treat that as clean EOF, matching what every other EOF-producing reader would report.

func (*Bridge) Resize

func (b *Bridge) Resize(ctx context.Context, cols, rows int) error

Resize applies pty.Setsize (sizes the region the tmux client paints into) and then tmux resize-window (sizes the window the application lays out against) — in that order, always both, never the pane-level primitive (kb:adr/surfaces-shared-attach-single-pty).

func (*Bridge) Write

func (b *Bridge) Write(p []byte) (int, error)

Write sends raw input bytes to the attached pane.

Jump to

Keyboard shortcuts

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