shell

package
v1.54.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const HistorySettingKey = "shell-history"

HistorySettingKey is the settings store key that switches per-shell command history on (value "on"). Unset or anything else means off: shells then share the login shell's default history file. It only affects newly started shells, like the terminal restore setting.

Variables

View Source
var ErrNotRunning = errors.New("No active shell")

ErrNotRunning marks lookups for identifiers without a live shell.

Functions

This section is empty.

Types

type Shell

type Shell struct {
	Identifier   string
	TmuxSession  string
	PID          string
	Name         string
	StartedAt    time.Time
	CWD          string
	TabPos       int    // tab strip position from @dc_tab_pos, 0 when unset
	TabGroup     string // split view group id from @dc_tab_group, empty when ungrouped
	TabGroupPos  int    // position inside the group from @dc_tab_gpos, 0 when unset
	TabGroupName string // group display name from @dc_tab_gname, may be empty
	TabGroupCol  int    // column inside the group from @dc_tab_gcol, 0 for a column of its own
}

Shell is one live tmux session running a plain interactive login shell.

type Shells

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

Shells orchestrates plain shell sessions. It reuses the tmux client and the streaming machinery that back coder sessions, but carries no provider state.

func NewShells

func NewShells(cfg config.Config, t *tmux.Client, projects *project.Repository, historyEnabled func() bool) *Shells

NewShells wires up Shells with its dependencies. historyEnabled reads the per-shell history setting on every call; a nil func means the feature is off.

func (*Shells) AttachStream

func (s *Shells) AttachStream(rawID, rawCols, rawRows string) (terminal.Attachment, error)

AttachStream opens the control client and returns the initial snapshot.

func (*Shells) Delete

func (s *Shells) Delete(rawID string) (string, error)

Delete kills the shell's tmux session and closes its control client.

func (*Shells) DetachStream

func (s *Shells) DetachStream(name string)

DetachStream releases one browser stream and closes the control client after the last one.

func (*Shells) Invalidate

func (s *Shells) Invalidate()

Invalidate drops the cached shell list so the next List re-scans tmux.

func (*Shells) List

func (s *Shells) List() []Shell

List returns every live shell session, sorted by tmux's pane order. The result is cached for a short TTL; mutations invalidate it.

func (*Shells) ReapHistory

func (s *Shells) ReapHistory()

ReapHistory deletes per-shell history files that no live shell owns. Files are keyed by shell id and ids are never reused, so a file without a live shell is dead weight: a shell closed outside the cockpit, or a reboot without restore. Restore recreates shells under their old id before the startup reap runs, so a restored shell's file is kept. Runs regardless of the setting, so files left over from a former on-phase clean up too. Best effort, a missing directory is a no-op.

func (*Shells) RefreshStream

func (s *Shells) RefreshStream(name string, generation int64) (terminal.Attachment, bool)

RefreshStream returns a new snapshot when another browser reset this stream.

func (*Shells) Rename

func (s *Shells) Rename(rawID, rawName string) (Shell, error)

Rename changes a shell's display name.

func (*Shells) Resize

func (s *Shells) Resize(rawID, rawCols, rawRows string) error

Resize sets the shell's rendered terminal size.

func (*Shells) Resnapshot

func (s *Shells) Resnapshot(name string) (terminal.Attachment, bool)

Resnapshot recaptures the screen for a stream that fell out of the ring.

func (*Shells) Resolve

func (s *Shells) Resolve(rawID string) error

Resolve reports whether a shell with the given identifier is live.

func (*Shells) ResolveRunning

func (s *Shells) ResolveRunning(rawID string) (Shell, error)

ResolveRunning validates the identifier and returns the matching shell.

func (*Shells) RunCommandWatch

func (s *Shells) RunCommandWatch(interval time.Duration, onNews func(shellID string))

RunCommandWatch watches every live shell and reports news: a foreground command finished after running at least minCommandDuration (a prompt-return mark preceded by a command-start mark, so bare prompt redraws and quick commands stay silent), or the shell rang a terminal bell. Blocks; run it in a goroutine.

func (*Shells) RunHistoryReaper

func (s *Shells) RunHistoryReaper(interval time.Duration)

RunHistoryReaper reaps orphan history files every interval. Never returns, run it on a goroutine.

func (*Shells) Send

func (s *Shells) Send(rawID string, items []terminal.Input) error

Send dispatches a batch of user inputs to a shell, in order. Scroll controls drive the tmux history view; everything else is forwarded to the program.

func (*Shells) Start

func (s *Shells) Start(workdir, name string) (string, error)

Start launches a new shell session in workdir, labelled name.

func (*Shells) StartCommand

func (s *Shells) StartCommand(workdir, name, command string) (string, error)

StartCommand launches a shell that types its first command itself: the session runs command under the usual interactive login bash, so the full profile applies and the pane behaves like a shell somebody typed it into. The command should end in an exec of a shell when the pane is to survive it; a restored shell always comes back as a plain bash, commands are not part of the snapshot.

func (*Shells) StartWithKey

func (s *Shells) StartWithKey(workdir, name, key string) (string, error)

StartWithKey launches a shell under a caller-provided session key. The terminal restore uses it to bring a shell back under its recorded id, so links, open tabs, and notification entries keep resolving.

func (*Shells) StreamDelta

func (s *Shells) StreamDelta(name string, offset int64) ([]byte, int64, bool)

StreamDelta returns buffered output after offset.

func (*Shells) StreamExited

func (s *Shells) StreamExited(name string) bool

StreamExited reports whether the underlying control client has ended.

func (*Shells) StreamModes

func (s *Shells) StreamModes(name string) (tmux.PaneModes, bool)

StreamModes reads the pane's current terminal modes, so a stream can tell the browser when a program switched into or out of its full screen UI.

func (*Shells) StreamUpdated

func (s *Shells) StreamUpdated(name string) (<-chan struct{}, bool)

StreamUpdated returns a channel closed on the next output or exit.

Jump to

Keyboard shortcuts

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