terminal

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: AGPL-3.0 Imports: 14 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 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

View Source
const DialTimeout = 30 * time.Second

DialTimeout bounds the initial WebSocket handshake.

Variables

View Source
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

func IsTerminal(file *os.File) bool

IsTerminal reports whether the file is an interactive terminal. `sandbox start` and `connect` require one — there is no non-interactive exec mode.

func Pick

func Pick(in *os.File, out io.Writer, prompt string, items []PickItem) (int, error)

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.

func Attach

func Attach(ctx context.Context, opts Options) (Result, error)

Attach runs the session until the remote side exits, the context is cancelled, or the connection fails. It returns the remote exit result.

type Size

type Size struct {
	Cols uint16
	Rows uint16
}

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

func MakeRaw(file *os.File) (*TTY, error)

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) Resize

func (t *TTY) Resize() <-chan Size

Resize is the channel of window-size changes to forward to the remote PTY.

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

func (t *TTY) Size() (Size, error)

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.

Jump to

Keyboard shortcuts

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