terminal

package
v0.18.1 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: AGPL-3.0 Imports: 15 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 IsTerminalWriter added in v0.17.0

func IsTerminalWriter(w io.Writer) bool

IsTerminalWriter reports whether a writer is an interactive terminal. Anything that is not a file — a buffer in a test, a pipe in CI — is not.

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 Step added in v0.17.0

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

Step is one operation in progress. Its methods are safe to call from another goroutine, which is what lets a poller update the detail while the work runs.

func (*Step) Detail added in v0.17.0

func (st *Step) Detail(detail string)

Detail replaces the trailing context of a running step — the bytes so far, the workloads not yet ready. Ignored once the step has finished, so a poller racing the step's completion cannot resurrect its line.

func (*Step) Done added in v0.17.0

func (st *Step) Done(detail string)

Done marks the step complete. detail may be empty.

func (*Step) Fail added in v0.17.0

func (st *Step) Fail(err error) error

Fail marks the step failed and returns the error, so a caller can write `return step.Fail(err)` and be sure the line was closed.

func (*Step) Skip added in v0.17.0

func (st *Step) Skip(detail string)

Skip marks a step that was not run, naming why — and, by convention, the command that would run it later.

type Steps added in v0.17.0

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

Steps renders a sequence of long operations as one line each.

The operations behind `agyn local` take minutes and are driven by tools whose own output answers a different question than the user asked: a Helm release listing, eight identical admission warnings, a byte counter. Those go to a log. What reaches the terminal is what is happening now, and what it cost.

On a terminal the line for the step in progress is animated and carries the detail it is waiting on, so a minute of work is visibly work rather than possibly a hang. Anywhere else — a pipe, a CI log — each step prints once, on completion, with the same content and no control characters.

func NewPlainSteps added in v0.17.0

func NewPlainSteps(out io.Writer) *Steps

NewPlainSteps never animates. For --debug, where the tool output the steps exist to hide is streaming to the same terminal: a spinner redrawing over it would corrupt both.

func NewSteps added in v0.17.0

func NewSteps(out io.Writer) *Steps

NewSteps writes to out, animating only when out is a terminal.

func (*Steps) CallToAction added in v0.17.0

func (s *Steps) CallToAction(label, url string)

CallToAction closes a successful run with the one thing to do next. A finished install owes the reader a next step, and three links are a menu.

func (*Steps) Detail added in v0.17.0

func (s *Steps) Detail(label, value string)

Detail prints a labelled line under the call to action -- what to do once the link is open, which is a different question from what just happened.

func (*Steps) Failed added in v0.17.0

func (s *Steps) Failed(title string, err error) error

Failed prints a step that failed before it started running, and returns the error so a caller can write `return steps.Failed(...)`.

func (*Steps) Note added in v0.17.0

func (s *Steps) Note(text string)

Note prints a line that is not a step: something the user needs to know that no step is responsible for.

func (*Steps) Report added in v0.17.0

func (s *Steps) Report(title, detail string)

Report prints a finished step that had no visible duration, or whose work wrote to the terminal itself — the sudo prompt of a trust-store install is not something to animate over.

func (*Steps) Rule added in v0.17.0

func (s *Steps) Rule()

Rule draws a divider, separating the account of what happened from what to do with it.

func (*Steps) Skipped added in v0.17.0

func (s *Steps) Skipped(title, detail string)

Skipped prints a step that was not run, naming why — and, by convention, the command that would run it later.

func (*Steps) Start added in v0.17.0

func (s *Steps) Start(title string) *Step

Start begins a step. Exactly one step is in progress at a time: a prompt or a sudo password arriving under a spinner is unreadable, so callers finish the step before asking anything.

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