Documentation
¶
Index ¶
- type AdHocOptions
- type Manager
- func (m *Manager) Create(ctx context.Context, name string, force bool) error
- func (m *Manager) CreateAdHoc(ctx context.Context, name string, session *config.Session, opts AdHocOptions) error
- func (m *Manager) CreateAdHocWindow(ctx context.Context, parentSession, windowName string, sess *config.Session) error
- func (m *Manager) CreateOrAttach(ctx context.Context, name string, force bool) error
- func (m *Manager) Kill(name string) error
- func (m *Manager) List() ([]SessionInfo, error)
- type ManagerOption
- type SessionInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AdHocOptions ¶
type AdHocOptions struct {
Force bool // destroy any existing session with the same name first
Detach bool // create without attaching
Temporary bool // set destroy-unattached on the session
}
AdHocOptions tunes CreateAdHoc.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager orchestrates session lifecycle on top of a Tmux implementation.
func NewManager ¶
NewManager wires a Manager backed by a real *tmux.Client, recording recent sessions to the on-disk history. Returns an error if tmux is not on PATH.
func NewManagerWith ¶
func NewManagerWith(cfg *config.Config, tx tmux.Tmux, logger *slog.Logger, opts ...ManagerOption) *Manager
NewManagerWith builds a Manager backed by the given Tmux. Used by tests. History recording defaults to a no-op; pass WithRecorder to enable it.
func (*Manager) CreateAdHoc ¶
func (m *Manager) CreateAdHoc(ctx context.Context, name string, session *config.Session, opts AdHocOptions) error
CreateAdHoc creates a session from an in-memory Session definition (i.e. not loaded from the config file). The Session is validated with the same rules as configured sessions. If temporary is true, the session is set to destroy itself when the last client detaches.
func (*Manager) CreateAdHocWindow ¶
func (m *Manager) CreateAdHocWindow(ctx context.Context, parentSession, windowName string, sess *config.Session) error
CreateAdHocWindow creates a new window inside the named parent session (typically the current $TMUX session) and fills it with one pane per host. It does not change session focus — the caller is presumed to be inside the same tmux client and will see the new window appear.
func (*Manager) CreateOrAttach ¶
CreateOrAttach attaches to an existing tmux session, or builds one from the configuration and attaches. If the session name is not in the config, the caller can still attach to it as long as it already exists in tmux — this lets `mox -a foo` work for hand-rolled tmux sessions too.
On context cancellation during build the partial session is killed.
func (*Manager) Kill ¶
Kill destroys a session. For config-managed sessions, on_stop hooks run afterward (best-effort).
func (*Manager) List ¶
func (m *Manager) List() ([]SessionInfo, error)
List returns information about all configured sessions plus any running tmux sessions that are not in the config, enriched with per-session detail (window count, attached state, last activity) for the running ones.
type ManagerOption ¶ added in v0.2.0
type ManagerOption func(*Manager)
ManagerOption customizes a Manager built with NewManagerWith.
func WithHookRunner ¶ added in v0.2.0
func WithHookRunner(fn func(command string) error) ManagerOption
WithHookRunner injects how on_start/on_stop hook commands execute. Production uses sh -c with the terminal attached; tests inject a recorder, and dry-run mode injects a printer.
func WithRecorder ¶ added in v0.2.0
func WithRecorder(fn func(name, action string) error) ManagerOption
WithRecorder injects the function used to persist recent-session history. Production code uses history.Record (wired by NewManager); tests inject a hook (or leave the default no-op) so they never touch disk.
type SessionInfo ¶
type SessionInfo struct {
Name string
Running bool
Managed bool
Windows int
Attached bool
LastActivity time.Time
Hosts []string
}
SessionInfo describes a session and whether it is currently running. Managed is true if the name appears in the mox config; false if the session exists in tmux but has no config entry. The Windows, Attached, and LastActivity fields are populated from tmux for running sessions only; Hosts is derived from the config for managed sessions only.