shell

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 16 Imported by: 1 module, 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 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

View Source
const (
	// MaxSessions bounds how many shells run at once.
	MaxSessions = 24
)

Variables

View Source
var ErrNotFound = errors.New("no such terminal session")

ErrNotFound means the session id is unknown.

View Source
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 NewManager

func NewManager() *Manager

NewManager returns an empty manager.

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

func (m *Manager) Close(id string) error

Close ends a session and forgets it.

func (*Manager) CloseAll

func (m *Manager) CloseAll()

CloseAll ends every session. Call it when the process stops.

func (*Manager) Create

func (m *Manager) Create(o Options) (Info, error)

Create registers a session. The shell starts on the first attach, at that viewer's size.

func (*Manager) List

func (m *Manager) List() []Info

List returns the sessions, oldest first.

func (*Manager) Rename

func (m *Manager) Rename(id, title string) (Info, error)

Rename sets a session's title.

func (*Manager) Status

func (m *Manager) Status(id string) (Status, error)

Status reports a session's foreground program and folder.

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.

Jump to

Keyboard shortcuts

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