terminal

package
v0.6.76 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: AGPL-3.0, Apache-2.0, MIT Imports: 26 Imported by: ? 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 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

View Source
const DefaultReplayBytes = 2 << 20

DefaultReplayBytes is the retained output per terminal.

Variables

This section is empty.

Functions

This section is empty.

Types

type Job

type Job struct {
	TerminalID string
	Command    string
	Pgid       int
}

Job is a terminal's foreground job.

type Manager

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

Manager owns the instance's terminals.

func New

func New(opts Options) *Manager

New returns a Manager.

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

func (m *Manager) AttachedCount() int

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

Create starts a terminal. Repeating a caller-chosen terminal_id returns the existing terminal.

func (*Manager) Get

func (m *Manager) Get(id string) (*Terminal, error)

Get returns a terminal.

func (*Manager) Jobs

func (m *Manager) Jobs() []Job

Jobs lists foreground jobs (process groups other than the login shell's).

func (*Manager) LastAttachedIO

func (m *Manager) LastAttachedIO() time.Time

LastAttachedIO is the latest input/output time across attached terminals.

func (*Manager) List

func (m *Manager) List() []*devboxv1.TerminalInfo

List returns every terminal.

func (*Manager) Resize

func (m *Manager) Resize(id string, cols, rows int32) (*devboxv1.TerminalInfo, error)

Resize resizes a terminal.

func (*Manager) ServeWS

func (m *Manager) ServeWS(w http.ResponseWriter, r *http.Request)

ServeWS serves GET /terminals/<id>/ws[?offset=N]. The router and KAS handle stream authorization; the daemon only accepts the gateway's upgrade.

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

func (t *Terminal) Attached() bool

Attached reports whether a client is attached.

func (*Terminal) Busy

func (t *Terminal) Busy() (string, bool)

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

func (t *Terminal) LastIO() time.Time

LastIO is the time of the last input or output.

func (*Terminal) Pid

func (t *Terminal) Pid() int

Pid returns the shell's PID.

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].

func (*Terminal) Resize

func (t *Terminal) Resize(cols, rows int32) error

Resize resizes the PTY.

func (*Terminal) Write

func (t *Terminal) Write(p []byte) error

Write sends input to the PTY.

Jump to

Keyboard shortcuts

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