Documentation
¶
Overview ¶
Package shell runs local shells in pseudo-terminals and lets browser terminals attach to them. A session outlives its viewers: closing the page or reloading it leaves the shell running, and the next attach replays recent output before going live.
Ported from Basalisk (internal/terminal), which follows Tachyon's chat terminal (internal/chatterminal): a PTY per session, a bounded replay buffer, fan-out to attached viewers. It differs in running a local login shell instead of ssh, in keeping no database rows, and in having no idle timeout.
Index ¶
- Constants
- Variables
- type Attachment
- type Info
- type Manager
- func (m *Manager) Attach(id string, cols, rows uint16) (*Attachment, error)
- func (m *Manager) Close(id string) error
- func (m *Manager) CloseAll()
- func (m *Manager) Create(o Options) (Info, error)
- func (m *Manager) List() []Info
- func (m *Manager) Rename(id, title string) (Info, error)
- func (m *Manager) Status(id string) (Status, error)
- type Options
- type Status
Constants ¶
const (
// MaxSessions bounds how many shells run at once.
MaxSessions = 24
)
Variables ¶
var ErrNotFound = errors.New("no such terminal session")
ErrNotFound means the session id is unknown.
var ErrTooMany = fmt.Errorf("at most %d terminal sessions can be open", MaxSessions)
ErrTooMany means MaxSessions shells are already running.
Functions ¶
This section is empty.
Types ¶
type Attachment ¶
type Attachment struct {
// Replay is the recent output, to be written before anything from Frames.
Replay []byte
// Frames carries live output. It is closed when the shell exits or this viewer fell
// too far behind; Exited tells which.
Frames chan []byte
// contains filtered or unexported fields
}
Attachment is one viewer of a session.
func (*Attachment) Detach ¶
func (a *Attachment) Detach()
Detach removes the viewer. The shell keeps running.
func (*Attachment) Exited ¶
func (a *Attachment) Exited() (bool, int)
Exited reports whether the shell has ended, and its exit code.
func (*Attachment) Input ¶
func (a *Attachment) Input(p []byte) error
Input writes keystrokes to the shell.
func (*Attachment) Resize ¶
func (a *Attachment) Resize(cols, rows uint16)
Resize sets the terminal size. Sizes outside 1..maxDimension are ignored.
type Info ¶
type Info struct {
ID string `json:"id"`
Title string `json:"title"`
Shell string `json:"shell"`
Cwd string `json:"cwd"`
CreatedAt time.Time `json:"created_at"`
Started bool `json:"started"`
Exited bool `json:"exited"`
ExitCode int `json:"exit_code"`
Cols uint16 `json:"cols"`
Rows uint16 `json:"rows"`
Viewers int `json:"viewers"`
}
Info describes a session.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager owns the sessions of one process.
func (*Manager) Attach ¶
func (m *Manager) Attach(id string, cols, rows uint16) (*Attachment, error)
Attach adds a viewer, starting the shell if this is the first one.
func (*Manager) CloseAll ¶
func (m *Manager) CloseAll()
CloseAll ends every session. Call it when the process stops.
func (*Manager) Create ¶
Create registers a session. The shell starts on the first attach, at that viewer's size.
type Options ¶
type Options struct {
// Cwd is the starting directory. Empty means the home directory.
Cwd string
// Title is a label for the tab. Empty means the shell's name.
Title string
}
Options are what a new session may choose.
type Status ¶
type Status struct {
ID string `json:"id"`
Running bool `json:"running"`
Busy bool `json:"busy"`
Program string `json:"program,omitempty"`
Folder string `json:"folder,omitempty"`
}
Status is what a running shell is doing: whether a program holds the foreground (the terminal's foreground process group is not the shell's), which one, and the folder the foreground process is in. Read on demand from the operating system; best effort.