summaryrefslogtreecommitdiff
path: root/internal/tmuxedit/pane.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/tmuxedit/pane.go')
-rw-r--r--internal/tmuxedit/pane.go28
1 files changed, 24 insertions, 4 deletions
diff --git a/internal/tmuxedit/pane.go b/internal/tmuxedit/pane.go
index aae2d69..0b6be93 100644
--- a/internal/tmuxedit/pane.go
+++ b/internal/tmuxedit/pane.go
@@ -7,8 +7,20 @@ import (
"strings"
)
-// runCommand is the seam for exec.Command().Output(). Override in tests.
-var runCommand = func(name string, args ...string) ([]byte, error) {
+type tmuxEditDeps struct {
+ runCommand func(string, ...string) ([]byte, error)
+ capturePane func(string) (string, error)
+ openEditorPopup func(string, string, string) (string, error)
+ sendKeys func(string, ...string) error
+ sendRepeatedKey func(string, string, int) error
+ sleepAfterClear func()
+ launchPopup func(string, string, string, string) error
+}
+
+func (d tmuxEditDeps) command(name string, args ...string) ([]byte, error) {
+ if d.runCommand != nil {
+ return d.runCommand(name, args...)
+ }
return exec.Command(name, args...).Output()
}
@@ -16,6 +28,10 @@ var runCommand = func(name string, args ...string) ([]byte, error) {
// chain: explicit flag > HEXAI_TMUX_PANE env var > tmux query for active pane.
// Returns the pane ID (e.g. "%5") or an error.
func resolveTargetPane(flagPane string) (string, error) {
+ return tmuxEditDeps{}.resolveTargetPane(flagPane)
+}
+
+func (d tmuxEditDeps) resolveTargetPane(flagPane string) (string, error) {
// 1. Explicit --pane flag
if p := strings.TrimSpace(flagPane); p != "" {
return p, nil
@@ -25,12 +41,16 @@ func resolveTargetPane(flagPane string) (string, error) {
return p, nil
}
// 3. Query tmux for the active pane in the current window
- return queryActivePane()
+ return d.queryActivePane()
}
// queryActivePane asks tmux for the active pane ID using display-message.
func queryActivePane() (string, error) {
- out, err := runCommand("tmux", "display-message", "-p", "#{pane_id}")
+ return tmuxEditDeps{}.queryActivePane()
+}
+
+func (d tmuxEditDeps) queryActivePane() (string, error) {
+ out, err := d.command("tmux", "display-message", "-p", "#{pane_id}")
if err != nil {
return "", fmt.Errorf("cannot determine tmux pane: %w", err)
}