Documentation ¶
Index ¶
- Constants
- Variables
- type DefaultRunner
- func (c *DefaultRunner) Debug(msg string, args ...any)
- func (c *DefaultRunner) Execve(args ...string) error
- func (c *DefaultRunner) IsDryRun() bool
- func (c *DefaultRunner) Log(msg string, args ...any)
- func (c *DefaultRunner) Run(ctx context.Context, args ...string) ([]byte, error)
- func (c *DefaultRunner) SetLogger(logger *slog.Logger)
- type OSCommandRunner
- type Pane
- func (p *Pane) Apply(ctx context.Context) error
- func (p *Pane) IsActive() bool
- func (p *Pane) IsApplied() bool
- func (p *Pane) IsClosed() bool
- func (p *Pane) Name() string
- func (p *Pane) NumPanes() int
- func (p *Pane) RunCommands(ctx context.Context, cmds ...string) error
- func (p *Pane) Select(ctx context.Context) error
- func (p *Pane) String() string
- type PaneOption
- type Runner
- type RunnerOption
- func WithDryRunMode(enable bool) RunnerOption
- func WithLogger(logger *slog.Logger) RunnerOption
- func WithOSCommandRunner(runner OSCommandRunner) RunnerOption
- func WithSyscallExecRunner(runner SyscallExecRunner) RunnerOption
- func WithTmux(name string) RunnerOption
- func WithTmuxOptions(opts ...string) RunnerOption
- type Session
- func (s *Session) Apply(ctx context.Context) error
- func (s *Session) Attach(ctx context.Context) error
- func (s *Session) Close() error
- func (s *Session) IsApplied() bool
- func (s *Session) IsClosed() bool
- func (s *Session) Name() string
- func (s *Session) NumPanes() int
- func (s *Session) NumWindows() int
- func (s *Session) SelectActive(ctx context.Context) error
- func (s *Session) String() string
- type SessionOption
- func SessionWithEnv(env map[string]string) SessionOption
- func SessionWithName(name string) SessionOption
- func SessionWithOnAnyCommand(cmd string) SessionOption
- func SessionWithOnPaneCommand(cmd string) SessionOption
- func SessionWithOnWindowCommand(cmd string) SessionOption
- func SessionWithPath(path string) SessionOption
- type SyscallExecRunner
- type Window
- func (w *Window) Apply(ctx context.Context) error
- func (w *Window) IsActive() bool
- func (w *Window) IsApplied() bool
- func (w *Window) IsClosed() bool
- func (w *Window) Name() string
- func (w *Window) NumPanes() int
- func (w *Window) RunCommands(ctx context.Context, cmds ...string) error
- func (w *Window) Select(ctx context.Context) error
- func (w *Window) String() string
- type WindowOption
Constants ¶
const DefaultTmux = "tmux"
DefaultTmux is the default name of the tmux executable.
Variables ¶
var ( // ErrNilRunner is returned when a nil [Runner] argument is passed. ErrNilRunner = errors.New("runner is nil") // ErrNilSession is returned when a nil [Session] argument is passed. ErrNilSession = errors.New("session is nil") // ErrNilWindow is returned when a nil [Window] argument is passed. ErrNilWindow = errors.New("window is nil") // ErrNilPane is returned when a nil [Pane] argument is passed. ErrSessionClosed = errors.New("session is closed") // ErrSessionNotApplied is returned when an unapplied [Session] is used. ErrSessionNotApplied = errors.New("session is not applied") // ErrWindowNotApplied is returned when an unapplied [Window] is used. ErrWindowNotApplied = errors.New("window is not applied") // ErrPaneNotApplied is returned when an unapplied [Pane] is used. ErrPaneNotApplied = errors.New("pane is not applied") )
Functions ¶
This section is empty.
Types ¶
type DefaultRunner ¶
type DefaultRunner struct {
// contains filtered or unexported fields
}
DefaultRunner is the default Runner implementation.
func NewRunner ¶
func NewRunner(opts ...RunnerOption) (*DefaultRunner, error)
NewRunner creates a new Runner with the provided options.
func (*DefaultRunner) Debug ¶
func (c *DefaultRunner) Debug(msg string, args ...any)
Debug logs a debug message using a slog.Logger.
func (*DefaultRunner) Execve ¶
func (c *DefaultRunner) Execve(args ...string) error
Execve runs the tmux command with the provided arguments using the execve syscall (syscall.Exec) to replace the current process with the tmux process.
func (*DefaultRunner) IsDryRun ¶
func (c *DefaultRunner) IsDryRun() bool
IsDryRun returns true if the runner is in dry-run mode.
Dry-run mode means that the runner will not actually run any tmux commands but only log the commands that would have been run and return empty output.
func (*DefaultRunner) Log ¶
func (c *DefaultRunner) Log(msg string, args ...any)
Log logs an info message using a slog.Logger.
func (*DefaultRunner) Run ¶
Run runs the tmux command in a context-aware manner with the provided arguments and returns the output.
func (*DefaultRunner) SetLogger ¶
func (c *DefaultRunner) SetLogger(logger *slog.Logger)
SetLogger sets the logger used by the runner.
type OSCommandRunner ¶
type OSCommandRunner func(ctx context.Context, name string, args ...string) (output []byte, err error)
OSCommandRunner runs a command with the provided name and arguments and returns the output.
type Pane ¶
type Pane struct {
// contains filtered or unexported fields
}
Pane represents a tmux window pane.
func NewPane ¶
NewPane creates a new Pane instance configured with the provided options and belonging to the provided window and optional parent pane.
The window must be applied before being passed to this function. If a parent pane is provided, it must be applied before being passed to this function.
NOTE: The pane is not created until Pane.Apply is called.
func (*Pane) Apply ¶
Apply creates the tmux pane by invoking the split-window command using its internal Runner instance.
If the pane is already applied, this method is a no-op.
func (*Pane) IsActive ¶
IsActive returns true if the pane is configured as the active pane of its window.
func (*Pane) IsApplied ¶
IsApplied returns true if the pane has been applied with Pane.Apply.
func (*Pane) Name ¶
Name returns the pane's fully qualified name.
The name is composed of the session name, the window name separated by a colon, followed by a dot and the pane index.
func (*Pane) RunCommands ¶
RunCommands runs the provided commands inside the pane by invoking the send-keys tmux command using its internal Runner instance.
The commands are automatically followed by a carriage return.
If the pane is not applied, the method returns ErrPaneNotApplied.
If no commands are provided, the method is a no-op.
func (*Pane) Select ¶
Select selects the pane by invoking the select-pane command using its internal Runner instance.
If the pane is not applied, the method returns ErrPaneNotApplied.
type PaneOption ¶
PaneOption configures a Pane.
func PaneAsActive ¶
func PaneAsActive() PaneOption
PaneAsActive configures the Pane to be the active pane of its window.
func PaneWithCommands ¶
func PaneWithCommands(cmds ...string) PaneOption
PaneWithCommands configures the Pane with an initial shell commands.
The commands will run in the pane after it has been created.
NOTE: Commands are appended to the list of commands, so applying this option multiple times will add to the list of commands.
func PaneWithEnv ¶
func PaneWithEnv(env map[string]string) PaneOption
PaneWithEnv configures the Pane with environment variables.
Environment variables are inherited from session to window to pane. If a an environment variable is is named the same as an inherited variable, it will take precedence.
func PaneWithHorizontalDirection ¶
func PaneWithHorizontalDirection() PaneOption
PaneWithHorizontalDirection configures the Pane to be horizontal instead of vertical.
func PaneWithPath ¶
func PaneWithPath(s string) PaneOption
PaneWithPath configures the Pane working directory.
If a pane is not configured with a working directory, the window's working directory is used instead.
func PaneWithSize ¶
func PaneWithSize(size string) PaneOption
PaneWithSize configures the Pane size.
The size can be specified as a percentage of the available space or as a number of lines or columns.
type Runner ¶
type Runner interface { // Run runs the tmux command in a context-aware manner with the provided // arguments and return the output. Run(ctx context.Context, args ...string) ([]byte, error) // Execve runs the tmux command with the provided arguments using the execve // syscall ([syscall.Exec]) to replace the current process with the tmux // process. Execve(args ...string) error // IsDryRun returns true if the runner is in dry-run mode. // // Dry-run mode means that the runner will not actually run any tmux commands // but only log the commands that would have been run and return empty output. IsDryRun() bool // Debug writes a debug message using a [slog.Logger]. Debug(msg string, args ...any) // Log writes an info message using a [slog.Logger]. Log(msg string, args ...any) // SetLogger sets the logger used by the runner. SetLogger(logger *slog.Logger) }
Runner runs tmux commands and provide logging functionality.
type RunnerOption ¶
type RunnerOption func(*DefaultRunner) error
RunnerOption configures a DefaultRunner.
func WithDryRunMode ¶
func WithDryRunMode(enable bool) RunnerOption
WithDryRunMode configures the runner to run in dry-run mode.
Dry-run mode means that the runner will not actually run any tmux commands but only log the commands that would have been run and return empty output.
The default is false.
func WithLogger ¶
func WithLogger(logger *slog.Logger) RunnerOption
WithLogger configures the runner to use the provided slog.Logger for logging.
The default is a no-op logger writing to os.Discard.
func WithOSCommandRunner ¶
func WithOSCommandRunner(runner OSCommandRunner) RunnerOption
WithOSCommandRunner configures the runner to use the provided OSCommandRunner for running tmux commands.
This option is intended for testing purposes only.
func WithSyscallExecRunner ¶
func WithSyscallExecRunner(runner SyscallExecRunner) RunnerOption
WithSyscallExecRunner configures the runner to use the provided SyscallExecRunner for running tmux commands.
This option is intended for testing purposes only.
func WithTmux ¶
func WithTmux(name string) RunnerOption
WithTmux configures the runner to use provided name as the tmux executable.
The default is "tmux".
func WithTmuxOptions ¶
func WithTmuxOptions(opts ...string) RunnerOption
WithTmuxOptions configures the runner with additional tmux options to be added to all tmux command invocations.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session represents a tmux session.
func GetSessions ¶
GetSessions returns a list of current tmux sessions by invoking the list-sessions command using the provided Runner instance.
func NewSession ¶
func NewSession(runner Runner, opts ...SessionOption) (*Session, error)
NewSession creates a new Session instance configured with the provided options.
NOTE: The session is not created until Session.Apply is called.
func (*Session) Apply ¶
Apply creates the tmux session by invoking the new-session command using its internal Runner instance.
If the session is already applied, this method is a no-op.
func (*Session) Attach ¶
Attach attaches the current client to the session by invoking a tmux command using its internal Runner instance.
NOTE: syscall.Exec is used to replace the current process with the tmux client process. This means that this method will never return if it succeeds.
If the TMUX environment variable is set, it is assumed that the current process is already attached to a tmux session. In this case, the switch-client command is used instead of the attach-session command.
https://man.archlinux.org/man/tmux.1#attach-session https://man.archlinux.org/man/tmux.1#switch-client
func (*Session) Close ¶
Close closes the session by invoking the kill-session command using its internal Runner instance.
If the session is already closed or not applied, this method is a no-op.
Any subsequent calls to command-invoking methods on the session or any of its windows or panes will return an ErrSessionClosed error.
func (*Session) IsApplied ¶
IsApplied returns true if the session has been applied with Session.Apply.
func (*Session) IsClosed ¶
IsClosed returns true if the session has been closed with Session.Close.
func (*Session) NumWindows ¶
NumWindows returns the number of windows in the session.
func (*Session) SelectActive ¶
SelectActive selects the window configured as the active window by invoking the select-window command using its internal Runner instance.
If no window is configured as active, the first window is selected.
type SessionOption ¶
SessionOption configures a Session.
func SessionWithEnv ¶
func SessionWithEnv(env map[string]string) SessionOption
SessionWithEnv configures the Session environment variables.
Environment variables are inherited from session to window to pane. If a window or pane is confiured with a similarly named environment variable, it will take precedence over the session environment variable.
func SessionWithName ¶
func SessionWithName(name string) SessionOption
SessionWithName configures the Session name.
func SessionWithOnAnyCommand ¶
func SessionWithOnAnyCommand(cmd string) SessionOption
SessionWithOnAnyCommand configures a Session with a shell command that will be run in all created windows and panes.
If a command is also configured with SessionWithOnWindowCommand or SessionWithOnPaneCommand, the any command will be run first.
func SessionWithOnPaneCommand ¶
func SessionWithOnPaneCommand(cmd string) SessionOption
SessionWithOnPaneCommand configures a Session with a shell command that will be run in all created panes.
If a command is also configured with SessionWithOnAnyCommand, the pane command will be run after the any command.
func SessionWithOnWindowCommand ¶
func SessionWithOnWindowCommand(cmd string) SessionOption
SessionWithOnWindowCommand configures a Session with a shell command that will be run in all created windows.
If a command is also configured with SessionWithOnAnyCommand, the window command will be run after the any command.
func SessionWithPath ¶
func SessionWithPath(path string) SessionOption
SessionWithPath configures the Session working directory.
type SyscallExecRunner ¶
SyscallExecRunner runs a command with the provided arguments using the execve syscall (syscall.Exec) to replace the current process with the new process.
type Window ¶
type Window struct {
// contains filtered or unexported fields
}
Window represents a tmux window.
func NewWindow ¶
func NewWindow(runner Runner, session *Session, opts ...WindowOption) (*Window, error)
NewWindow creates a new Window instance configured with the provided options and belonging to the provided session.
The session must be applied before being passed to this function.
NOTE: The window is not created until Window.Apply is called.
func (*Window) Apply ¶
Apply creates the tmux window by invoking the new-window command using its internal Runner instance.
If the window is already applied, this method is a no-op.
If the window is the first window in the session, it is created with the -k flag to override the default initial window created by the new-session command.
func (*Window) IsActive ¶
IsActive returns true if the window is configured as the active window of its session.
func (*Window) IsApplied ¶
IsApplied returns true if the window has been applied with Window.Apply.
func (*Window) Name ¶
Name returns the window's fully qualified name.
The name is composed of the session name and the window name separated by a colon.
func (*Window) RunCommands ¶
RunCommands runs the provided commands inside the window by invoking the send-keys tmux command using its internal Runner instance.
The commands are automatically followed by a carriage return.
If the window is not applied, the method returns ErrWindowNotApplied.
If no commands are provided, the method is a no-op.
func (*Window) Select ¶
Select selects the window by invoking the select-window command using its internal Runner instance.
If the window is not applied, the method returns ErrWindowNotApplied.
If the window has a pane configured to be the active pane, the pane is also selected.
type WindowOption ¶
WindowOption configures a Window.
func WindowAsActive ¶
func WindowAsActive() WindowOption
WindowAsActive configures the Window to be the active window of its session.
func WindowWithCommands ¶
func WindowWithCommands(cmds ...string) WindowOption
WindowWithCommands configures the Window with an initial shell commands.
The commands will run in the window after it has been created.
NOTE: Commands are appended to the list of commands, so applying this option multiple times will add to the list of commands.
func WindowWithEnv ¶
func WindowWithEnv(env map[string]string) WindowOption
WindowWithEnv configures the Window with environment variables.
Environment variables are inherited from session to window to pane. If a an environment variable is is named the same as an inherited variable, it will take precedence.
func WindowWithName ¶
func WindowWithName(name string) WindowOption
WindowWithName configures the Window with a name.
func WindowWithPath ¶
func WindowWithPath(p string) WindowOption
WindowWithPath configures the Window with a working directory.
If a window is not configured with a working directory, the session's working directory is used instead.