Documentation
¶
Overview ¶
Package sandboxconnect opens an interactive terminal to a sandbox over the WebSocket its execution API serves at /terminal/ws. That endpoint is not in the API spec: it takes JSON messages of type input, output, resize, and error, with the token, window size, and session ID in the URL.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DialOptions ¶
type DialOptions struct {
// SandboxURL is the sandbox's URL.
SandboxURL string
// Token is a sandbox token.
Token string
// Input is read and sent to the sandbox's shell.
Input io.Reader
// Output receives the shell's output.
Output io.Writer
// Errors receives the terminal errors the sandbox reports.
Errors io.Writer
// Terminal is the local terminal, or nil for none: an 80 by 24 window,
// with no raw mode and no resizing.
Terminal TerminalControl
}
DialOptions are the options for Dial.
type Message ¶
type Message struct {
Type string `json:"type"` // "input", "output", "resize", "error"
Data string `json:"data,omitempty"`
Cols int `json:"cols,omitempty"`
Rows int `json:"rows,omitempty"`
}
Message is one frame of the terminal protocol.
type Terminal ¶
type Terminal struct {
// contains filtered or unexported fields
}
Terminal is one connected terminal session.
func Dial ¶
func Dial(ctx context.Context, opts DialOptions) (*Terminal, error)
Dial connects a new terminal session. Each session is a new shell: the endpoint's default session is shared, so a random session ID keeps a connect from rejoining a shell an earlier one left.
func (*Terminal) Run ¶
Run relays the session until it ends: the shell exits, the sandbox closes it, or ctx is done. With a local terminal, the terminal is in raw mode for the session, so keys such as Ctrl+C and Ctrl+D reach the shell. It returns an error only for a failure, not for the session ending.
type TerminalControl ¶
type TerminalControl interface {
// Size reports the window size.
Size() (cols, rows int, err error)
// MakeRaw puts the terminal in raw mode, returning how to restore it.
MakeRaw() (restore func() error, err error)
// NotifyResize calls resized whenever the window size changes, until ctx
// is done.
NotifyResize(ctx context.Context, resized func())
}
TerminalControl controls the local terminal a session runs in.
func NewOSTerminal ¶
func NewOSTerminal(input, output *os.File) TerminalControl
NewOSTerminal returns a TerminalControl for a terminal read from input and written to output, such as the process's stdin and stdout.