Documentation
¶
Index ¶
- Constants
- Variables
- type Shell
- type Shells
- func (s *Shells) AttachStream(rawID, rawCols, rawRows string) (terminal.Attachment, error)
- func (s *Shells) Delete(rawID string) (string, error)
- func (s *Shells) DetachStream(name string)
- func (s *Shells) Invalidate()
- func (s *Shells) List() []Shell
- func (s *Shells) ReapHistory()
- func (s *Shells) RefreshStream(name string, generation int64) (terminal.Attachment, bool)
- func (s *Shells) Rename(rawID, rawName string) (Shell, error)
- func (s *Shells) Resize(rawID, rawCols, rawRows string) error
- func (s *Shells) Resnapshot(name string) (terminal.Attachment, bool)
- func (s *Shells) Resolve(rawID string) error
- func (s *Shells) ResolveRunning(rawID string) (Shell, error)
- func (s *Shells) RunCommandWatch(interval time.Duration, onNews func(shellID string))
- func (s *Shells) RunHistoryReaper(interval time.Duration)
- func (s *Shells) Send(rawID string, items []terminal.Input) error
- func (s *Shells) Start(workdir, name string) (string, error)
- func (s *Shells) StartCommand(workdir, name, command string) (string, error)
- func (s *Shells) StartWithKey(workdir, name, key string) (string, error)
- func (s *Shells) StreamDelta(name string, offset int64) ([]byte, int64, bool)
- func (s *Shells) StreamExited(name string) bool
- func (s *Shells) StreamModes(name string) (tmux.PaneModes, bool)
- func (s *Shells) StreamUpdated(name string) (<-chan struct{}, bool)
Constants ¶
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 ¶
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) DetachStream ¶
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 ¶
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 ¶
RefreshStream returns a new snapshot when another browser reset this stream.
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) ResolveRunning ¶
ResolveRunning validates the identifier and returns the matching shell.
func (*Shells) RunCommandWatch ¶
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 ¶
RunHistoryReaper reaps orphan history files every interval. Never returns, run it on a goroutine.
func (*Shells) Send ¶
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) StartCommand ¶
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 ¶
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 ¶
StreamDelta returns buffered output after offset.
func (*Shells) StreamExited ¶
StreamExited reports whether the underlying control client has ended.
func (*Shells) StreamModes ¶
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 ¶
StreamUpdated returns a channel closed on the next output or exit.