stack

package
v0.29.1 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EnvStackMode stores whether stack mode is active ("on" or "off").
	EnvStackMode = "TMUX_STACK_MODE"

	// EnvPreviousLayout stores the window layout before entering stack mode.
	EnvPreviousLayout = "TMUX_STACK_LAYOUT"

	// CollapsedHeight is the height of collapsed panes (1 line).
	CollapsedHeight = "1"

	// ExpandedHeight is the percentage height of the expanded pane.
	ExpandedHeight = "95%"

	// StackModeOn indicates stack mode is active.
	StackModeOn = "on"

	// StackModeOff indicates stack mode is inactive.
	StackModeOff = "off"
)

Variables

View Source
var ErrStackModeOff = errors.New("stack mode off")

ErrStackModeOff is returned when stack mode is off and a quiet check is requested. Used by the status -q command to return exit code 1 without printing an error.

Functions

This section is empty.

Types

type Manager

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

Manager handles stack operations.

func New

func New() *Manager

New creates a new stack Manager with a real tmux client.

func NewWithClient

func NewWithClient(tmux TmuxClient) *Manager

NewWithClient creates a new stack Manager with a custom tmux client. Useful for testing.

func (*Manager) Collapse

func (m *Manager) Collapse(pane int, noSelect bool) error

Collapse collapses the specified pane to 1 line. If pane is -1, collapses the current pane. If noSelect is false, selects the pane before collapsing.

func (*Manager) Enter added in v0.25.0

func (m *Manager) Enter(minPanes int) error

Enter enters stack mode. If minPanes > 0, ensures at least that many panes exist. Does nothing if already in stack mode.

func (*Manager) Exit

func (m *Manager) Exit() error

Exit exits stack mode and restores the previous layout. Does nothing if not in stack mode.

func (*Manager) Expand

func (m *Manager) Expand(pane int, noSelect bool) error

Expand expands the specified pane. If pane is -1, expands the current pane. If noSelect is false, selects the pane before expanding. In stack mode, collapses all other panes. Outside stack mode, just resizes the pane to 95%.

func (*Manager) GetStatus

func (m *Manager) GetStatus() (*Status, error)

GetStatus returns the current stack status.

func (*Manager) IsStackMode

func (m *Manager) IsStackMode() (bool, error)

IsStackMode returns true if stack mode is currently active.

func (*Manager) JumpTo added in v0.25.0

func (m *Manager) JumpTo(pane int, tmuxArgs []string) error

JumpTo jumps to the specified pane. tmuxArgs are passed to the select-pane command (e.g., "-Z" to keep zoom). In stack mode, also applies the stack layout. If the pane doesn't exist, warns and jumps to the last pane.

func (*Manager) Move

func (m *Manager) Move(direction string) error

Move moves the current pane up or down in the stack. Direction should be "up" or "down". Does nothing silently if at boundary. In stack mode, re-applies the stack layout after moving.

func (*Manager) New added in v0.25.0

func (m *Manager) New(args []string) error

New adds a new pane with optional split-window arguments. In stack mode, applies the stack layout after creating the pane. Outside stack mode, just splits the window.

func (*Manager) Next

func (m *Manager) Next(tmuxArgs []string) error

Next moves to the next pane. tmuxArgs are passed to the select-pane command (e.g., "-Z" to keep zoom). In stack mode, also applies the stack layout. Does nothing silently if already at the last pane (no wrapping).

func (*Manager) Prev

func (m *Manager) Prev(tmuxArgs []string) error

Prev moves to the previous pane. tmuxArgs are passed to the select-pane command (e.g., "-Z" to keep zoom). In stack mode, also applies the stack layout. Does nothing silently if already at the first pane (no wrapping).

func (*Manager) PrintStatus

func (m *Manager) PrintStatus(w io.Writer, asJSON bool) error

PrintStatus prints the current stack status to the given writer.

func (*Manager) SetStackMode

func (m *Manager) SetStackMode(enabled bool) error

SetStackMode enables or disables stack mode.

func (*Manager) SetStderr

func (m *Manager) SetStderr(w io.Writer)

SetStderr sets the stderr writer for warnings.

func (*Manager) SetTitle

func (m *Manager) SetTitle(title string) error

SetTitle sets the title of the current pane.

func (*Manager) Toggle

func (m *Manager) Toggle() error

Toggle toggles between stack mode and the previous layout.

type MockTmuxClient

type MockTmuxClient struct {
	// Panes to return from ListPanes
	Panes []Pane

	// CurrentPane to return from GetCurrentPane
	CurrentPane int

	// WindowLayout to return from GetWindowLayout
	WindowLayout string

	// Environment variables
	Environment map[string]string

	// Track calls for verification
	SelectPaneCalls     []SelectPaneCall
	ResizePaneCalls     []ResizePaneCall
	SplitWindowCalls    [][]string
	SwapPaneCalls       []string
	SetTitleCalls       []string
	SelectLayoutCalls   []string
	SetEnvCalls         []SetEnvCall
	DisplayMessageCalls []string

	// Errors to return
	ListPanesErr      error
	GetCurrentPaneErr error
	SelectPaneErr     error
	ResizePaneErr     error
	SplitWindowErr    error
	SwapPaneErr       error
	SetTitleErr       error
	SelectLayoutErr   error
	GetLayoutErr      error
	GetEnvErr         error
	SetEnvErr         error
	DisplayMessageErr error
}

MockTmuxClient is a mock implementation of TmuxClient for testing.

func NewMockTmuxClient

func NewMockTmuxClient() *MockTmuxClient

NewMockTmuxClient creates a new MockTmuxClient.

func (*MockTmuxClient) DisplayMessage added in v0.25.1

func (m *MockTmuxClient) DisplayMessage(message string) error

DisplayMessage records the call.

func (*MockTmuxClient) GetCurrentPane

func (m *MockTmuxClient) GetCurrentPane() (int, error)

GetCurrentPane returns the configured current pane.

func (*MockTmuxClient) GetEnvironment

func (m *MockTmuxClient) GetEnvironment(key string) (string, error)

GetEnvironment returns the value from the Environment map.

func (*MockTmuxClient) GetPaneCount

func (m *MockTmuxClient) GetPaneCount() (int, error)

GetPaneCount returns the number of configured panes.

func (*MockTmuxClient) GetWindowLayout

func (m *MockTmuxClient) GetWindowLayout() (string, error)

GetWindowLayout returns the configured layout.

func (*MockTmuxClient) ListPanes

func (m *MockTmuxClient) ListPanes() ([]Pane, error)

ListPanes returns the configured panes.

func (*MockTmuxClient) ResizePane

func (m *MockTmuxClient) ResizePane(index int, height string) error

ResizePane records the call.

func (*MockTmuxClient) SelectLayout

func (m *MockTmuxClient) SelectLayout(layout string) error

SelectLayout records the call.

func (*MockTmuxClient) SelectPane

func (m *MockTmuxClient) SelectPane(index int, args []string) error

SelectPane records the call and updates CurrentPane.

func (*MockTmuxClient) SetEnvironment

func (m *MockTmuxClient) SetEnvironment(key, value string) error

SetEnvironment records the call and updates the Environment map.

func (*MockTmuxClient) SetPaneTitle

func (m *MockTmuxClient) SetPaneTitle(title string) error

SetPaneTitle records the call.

func (*MockTmuxClient) SplitWindow

func (m *MockTmuxClient) SplitWindow(args []string) error

SplitWindow records the call and adds a new pane.

func (*MockTmuxClient) SwapPane

func (m *MockTmuxClient) SwapPane(direction string) error

SwapPane records the call.

type Pane

type Pane struct {
	Index   int
	Height  int
	Width   int
	Title   string
	Active  bool
	Command string
}

Pane represents a tmux pane with its properties.

type PaneStatus

type PaneStatus struct {
	Index     int    `json:"index"`
	Height    int    `json:"height"`
	Title     string `json:"title"`
	Active    bool   `json:"active"`
	Collapsed bool   `json:"collapsed"`
	Command   string `json:"command,omitempty"`
}

PaneStatus represents a pane's status for reporting.

type RealTmuxClient

type RealTmuxClient struct{}

RealTmuxClient implements TmuxClient using actual tmux commands.

func NewTmuxClient

func NewTmuxClient() *RealTmuxClient

NewTmuxClient creates a new RealTmuxClient.

func (*RealTmuxClient) DisplayMessage added in v0.25.1

func (c *RealTmuxClient) DisplayMessage(message string) error

DisplayMessage displays a message in the tmux status line.

func (*RealTmuxClient) GetCurrentPane

func (c *RealTmuxClient) GetCurrentPane() (int, error)

GetCurrentPane returns the index of the currently active pane.

func (*RealTmuxClient) GetEnvironment

func (c *RealTmuxClient) GetEnvironment(key string) (string, error)

GetEnvironment retrieves the value of a tmux environment variable. Returns empty string if the variable is not set.

func (*RealTmuxClient) GetPaneCount

func (c *RealTmuxClient) GetPaneCount() (int, error)

GetPaneCount returns the number of panes in the current window.

func (*RealTmuxClient) GetWindowLayout

func (c *RealTmuxClient) GetWindowLayout() (string, error)

GetWindowLayout returns the current window's layout string.

func (*RealTmuxClient) ListPanes

func (c *RealTmuxClient) ListPanes() ([]Pane, error)

ListPanes returns all panes in the current window.

func (*RealTmuxClient) ResizePane

func (c *RealTmuxClient) ResizePane(index int, height string) error

ResizePane resizes the pane with the given index to the specified height. Height can be an absolute number or a percentage (e.g., "95%").

func (*RealTmuxClient) SelectLayout

func (c *RealTmuxClient) SelectLayout(layout string) error

SelectLayout applies a layout to the current window. Layout can be a preset name (e.g., "even-vertical") or a layout string.

func (*RealTmuxClient) SelectPane

func (c *RealTmuxClient) SelectPane(index int, args []string) error

SelectPane selects the pane with the given index. Additional args are passed directly to tmux select-pane (e.g., "-Z" to keep zoom).

func (*RealTmuxClient) SetEnvironment

func (c *RealTmuxClient) SetEnvironment(key, value string) error

SetEnvironment sets a tmux environment variable.

func (*RealTmuxClient) SetPaneTitle

func (c *RealTmuxClient) SetPaneTitle(title string) error

SetPaneTitle sets the title of the current pane.

func (*RealTmuxClient) SplitWindow

func (c *RealTmuxClient) SplitWindow(splitArgs []string) error

SplitWindow creates a new pane by splitting the current window vertically. Additional args are passed directly to tmux split-window (e.g., "-c", "#{pane_current_path}").

func (*RealTmuxClient) SwapPane

func (c *RealTmuxClient) SwapPane(direction string) error

SwapPane swaps the current pane with an adjacent pane. Direction should be "U" for up or "D" for down.

type ResizePaneCall

type ResizePaneCall struct {
	Index  int
	Height string
}

ResizePaneCall records a call to ResizePane.

type SelectPaneCall added in v0.27.0

type SelectPaneCall struct {
	Index int
	Args  []string
}

SelectPaneCall records a call to SelectPane.

type SetEnvCall

type SetEnvCall struct {
	Key   string
	Value string
}

SetEnvCall records a call to SetEnvironment.

type Status

type Status struct {
	Mode           bool         `json:"mode"`
	PreviousLayout string       `json:"previous_layout,omitempty"`
	TotalPanes     int          `json:"total_panes"`
	ActivePane     int          `json:"active_pane"`
	Panes          []PaneStatus `json:"panes"`
}

Status represents the current stack state.

type TmuxClient

type TmuxClient interface {
	ListPanes() ([]Pane, error)
	GetPaneCount() (int, error)
	GetCurrentPane() (int, error)
	SelectPane(index int, args []string) error
	ResizePane(index int, height string) error
	SplitWindow(args []string) error
	SwapPane(direction string) error
	SetPaneTitle(title string) error
	SelectLayout(layout string) error
	GetWindowLayout() (string, error)
	GetEnvironment(key string) (string, error)
	SetEnvironment(key, value string) error
	DisplayMessage(message string) error
}

TmuxClient abstracts tmux command execution for testability.

Jump to

Keyboard shortcuts

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