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
- Variables
- func IsTerminal(file *os.File) bool
- func IsTerminalWriter(w io.Writer) bool
- func Pick(in *os.File, out io.Writer, prompt string, items []PickItem) (int, error)
- type ExitReason
- type Options
- type PickItem
- type Result
- type Size
- type Step
- type Steps
- func (s *Steps) CallToAction(label, url string)
- func (s *Steps) Detail(label, value string)
- func (s *Steps) Failed(title string, err error) error
- func (s *Steps) Note(text string)
- func (s *Steps) Report(title, detail string)
- func (s *Steps) Rule()
- func (s *Steps) Skipped(title, detail string)
- func (s *Steps) Start(title string) *Step
- type TTY
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 IsTerminalWriter ¶ added in v0.17.0
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 ¶
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 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
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.
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
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 (*Steps) CallToAction ¶ added in v0.17.0
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
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
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
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
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.
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.