Documentation
¶
Overview ¶
Package terminal runs PTY sessions for the workbench terminal pane and `plural devbox ssh` (DBX-42). Output is kept in a bounded replay buffer addressed by absolute byte offsets, so a reconnecting client replays exactly what it missed.
Index ¶
- Constants
- type Job
- type Manager
- func (m *Manager) Attach(ctx context.Context, recv func() (*devboxv1.TerminalInput, error), ...) error
- func (m *Manager) AttachedCount() int
- func (m *Manager) BusyReasons() []*devboxv1.BusyReason
- func (m *Manager) Close(id, signal string) (*devboxv1.TerminalInfo, error)
- func (m *Manager) CloseAll()
- func (m *Manager) Create(req *devboxv1.CreateTerminalRequest) (*devboxv1.TerminalInfo, error)
- func (m *Manager) Get(id string) (*Terminal, error)
- func (m *Manager) Jobs() []Job
- func (m *Manager) LastAttachedIO() time.Time
- func (m *Manager) List() []*devboxv1.TerminalInfo
- func (m *Manager) Resize(id string, cols, rows int32) (*devboxv1.TerminalInfo, error)
- func (m *Manager) ServeWS(w http.ResponseWriter, r *http.Request)
- type Options
- type Terminal
- func (t *Terminal) Attached() bool
- func (t *Terminal) Busy() (string, bool)
- func (t *Terminal) Info() *devboxv1.TerminalInfo
- func (t *Terminal) LastIO() time.Time
- func (t *Terminal) Pid() int
- func (t *Terminal) Read(ctx context.Context, offset uint64) ([]byte, uint64, *devboxv1.TerminalExit, error)
- func (t *Terminal) Resize(cols, rows int32) error
- func (t *Terminal) Write(p []byte) error
Constants ¶
const DefaultReplayBytes = 2 << 20
DefaultReplayBytes is the retained output per terminal.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager owns the instance's terminals.
func (*Manager) Attach ¶
func (m *Manager) Attach(ctx context.Context, recv func() (*devboxv1.TerminalInput, error), send func(*devboxv1.TerminalOutput) error) error
Attach serves one attached client. recv returns client frames (the first must be `attach`); send writes output. It returns when the client goes away or the terminal exits (after sending `exit`).
func (*Manager) AttachedCount ¶
AttachedCount is the number of attached terminal clients (interactive streams).
func (*Manager) BusyReasons ¶
func (m *Manager) BusyReasons() []*devboxv1.BusyReason
BusyReasons lists terminals with foreground jobs.
func (*Manager) Close ¶
func (m *Manager) Close(id, signal string) (*devboxv1.TerminalInfo, error)
Close signals a terminal's process group (default SIGHUP) and closes the PTY.
func (*Manager) CloseAll ¶
func (m *Manager) CloseAll()
CloseAll hangs up every terminal (daemon shutdown).
func (*Manager) Create ¶
func (m *Manager) Create(req *devboxv1.CreateTerminalRequest) (*devboxv1.TerminalInfo, error)
Create starts a terminal. Repeating a caller-chosen terminal_id returns the existing terminal.
func (*Manager) LastAttachedIO ¶
LastAttachedIO is the latest input/output time across attached terminals.
func (*Manager) List ¶
func (m *Manager) List() []*devboxv1.TerminalInfo
List returns every terminal.
type Options ¶
type Options struct {
Home string
// Shell is the login shell (default $SHELL; /bin/bash when unset or missing).
Shell string
// Env returns the base environment of new terminals.
Env func() []string
ReplayBytes int
Clock clock.Clock
Log *slog.Logger
}
Options configure a Manager.
type Terminal ¶
type Terminal struct {
// contains filtered or unexported fields
}
Terminal is one PTY session.
func (*Terminal) Busy ¶
Busy reports a foreground job (a process group other than the shell's) for idle detection.
func (*Terminal) Info ¶
func (t *Terminal) Info() *devboxv1.TerminalInfo
Info returns the terminal's current info.
func (*Terminal) Read ¶
func (t *Terminal) Read(ctx context.Context, offset uint64) ([]byte, uint64, *devboxv1.TerminalExit, error)
Read returns output at or after offset, blocking until some is available, the terminal exits or ctx ends. Offsets older than the retained buffer start at the oldest retained byte. The returned offset is that of data[0].