Documentation
¶
Overview ¶
Package terminal attaches the local TTY to a remote container PTY through the Terminal Proxy. The wire protocol is defined in architecture/architecture/terminal-proxy.md: binary frames carry raw PTY bytes in both directions, text frames carry JSON control messages.
Index ¶
Constants ¶
const DialTimeout = 30 * time.Second
DialTimeout bounds the initial WebSocket handshake.
Variables ¶
var ErrPickCancelled = errors.New("selection cancelled")
ErrPickCancelled reports that the user dismissed the picker rather than choosing. Callers should treat it as "no change", not as a failure.
Functions ¶
func IsTerminal ¶
IsTerminal reports whether the file is an interactive terminal. `sandbox start` and `connect` require one — there is no non-interactive exec mode.
func Pick ¶
Pick shows an arrow-key list and returns the chosen index.
Typing a number works when a list is short and read carefully, and stops working the moment either is untrue: the number has to be found, matched to a row and typed correctly, and a mistake is committed the instant it is typed. Moving a highlight has none of those steps — what is about to happen is on screen until Enter.
Requires a terminal on both sides: the caller is expected to have checked, and to offer a non-interactive command instead when there is none.
Types ¶
type ExitReason ¶
type ExitReason string
ExitReason distinguishes a normal shell exit from a session torn down by the platform, so the CLI can print a notice for the latter.
const ( ReasonCompleted ExitReason = "completed" ReasonCancelled ExitReason = "cancelled" ReasonError ExitReason = "error" )
type Options ¶
type Options struct {
// URL is the Terminal Proxy WebSocket endpoint from CreateTerminalSession.
URL string
// Ticket authenticates the connection. It is single-use and short-lived,
// which is why it travels as a query parameter rather than a bearer token.
Ticket string
// InitialSize seeds the remote PTY before the shell draws anything.
InitialSize Size
// Resize delivers subsequent size changes (SIGWINCH on Unix). May be nil.
Resize <-chan Size
// Stdin/Stdout carry raw bytes. Stdin should already be in raw mode.
Stdin io.Reader
Stdout io.Writer
// HTTPClient dials the WebSocket. Nil uses http.DefaultClient.
HTTPClient *http.Client
}
Options configures a single attach.
type PickItem ¶
type PickItem struct {
// Label is the identifying text — a name, the thing being chosen.
Label string
// Detail is dimmer trailing context: an ID, a status, an endpoint.
Detail string
// Current marks the entry already in effect, so the picker opens on it.
Current bool
}
PickItem is one row of a picker.
type Result ¶
type Result struct {
Code int
Reason ExitReason
}
Result reports how the remote side ended.
type Size ¶
Size is a terminal window size in character cells.
func DefaultSize ¶
func DefaultSize() Size
DefaultSize is the window size to fall back on when the local terminal cannot be measured at all.
type TTY ¶
type TTY struct {
// contains filtered or unexported fields
}
TTY owns the local terminal state for the duration of a session.
func MakeRaw ¶
MakeRaw puts the terminal into raw mode so keystrokes, signals-as-bytes and escape sequences reach the remote PTY untouched. The caller must Restore.
func (*TTY) Restore ¶
func (t *TTY) Restore()
Restore returns the terminal to its previous state. It is safe to call more than once, so it can be deferred and also called on a signal path.
func (*TTY) Size ¶
Size returns the current window size. A terminal whose window size was never set reports zero without erroring, and the proxy rejects a handshake or resize carrying a zero dimension, so a zero is treated as unknown and answered with the default rather than passed on and refused.
func (*TTY) WatchResize ¶
func (t *TTY) WatchResize()
WatchResize forwards SIGWINCH to the resize channel until Restore is called.