Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions internal/platform/coverage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,57 @@ func TestLaunchStyleConstants(t *testing.T) {
}
}

// ---------------------------------------------------------------------------
// appendWTPaneDirFlags
// ---------------------------------------------------------------------------

func TestAppendWTPaneDirFlags(t *testing.T) {
tests := []struct {
name string
dir string
want []string
}{
{"down", "down", []string{"-H"}},
{"up", "up", []string{"-H"}},
{"right", "right", []string{"-V"}},
{"left", "left", []string{"-V"}},
{"auto", "auto", nil},
{"empty", "", nil},
{"unknown", "diagonal", nil},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
base := []string{"-w", "0", "split-pane"}
got := appendWTPaneDirFlags(base, tc.dir)

// base should never be modified in place.
extra := got[len(base):]
if tc.want == nil {
if len(extra) != 0 {
t.Errorf("dir=%q: got extra args %v, want none", tc.dir, extra)
}
return
}
if len(extra) != len(tc.want) {
t.Fatalf("dir=%q: got %v extra args, want %v", tc.dir, extra, tc.want)
}
for i, w := range tc.want {
if extra[i] != w {
t.Errorf("dir=%q: extra[%d]=%q, want %q", tc.dir, i, extra[i], w)
}
}
})
}
}

func TestAppendWTPaneDirFlags_PreservesExistingArgs(t *testing.T) {
base := []string{"existing", "args"}
got := appendWTPaneDirFlags(base, "down")
if len(got) != 3 || got[0] != "existing" || got[1] != "args" || got[2] != "-H" {
t.Errorf("got %v, want [existing args -H]", got)
}
}

// ---------------------------------------------------------------------------
// TerminalInfo and ShellInfo
// ---------------------------------------------------------------------------
Expand Down
24 changes: 18 additions & 6 deletions internal/platform/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,22 @@ func defaultWindowsShell() ShellInfo {
return ShellInfo{Name: "Command Prompt", Path: p}
}

// appendWTPaneDirFlags translates a dispatch pane direction into the correct
// wt.exe split-pane flags (-H for horizontal/down, -V for vertical/right).
// Windows Terminal does not support "up" or "left" natively, so those fall
// back to -H and -V respectively (the closest available direction).
func appendWTPaneDirFlags(args []string, dir string) []string {
switch dir {
case "down", "up":
return append(args, "-H")
case "right", "left":
return append(args, "-V")
default:
// "auto" or empty — let Windows Terminal choose.
return args
}
}

func launchWindowsSession(shell ShellInfo, resumeCmd string, terminal string, cwd string, launchStyle string, paneDirection string) error {
// Use Windows Terminal when configured (or defaulted by LaunchSession).
if terminal == termWindowsTerminal {
Expand All @@ -549,9 +565,7 @@ func launchWindowsSession(shell ShellInfo, resumeCmd string, terminal string, cw
case LaunchStylePane:
// Open a split pane in the current tab.
args = append(args, "-w", "0", "split-pane")
if paneDirection != "" && paneDirection != "auto" {
args = append(args, "--direction", paneDirection)
}
args = appendWTPaneDirFlags(args, paneDirection)
default:
// Open a new tab in the most recently used window.
// Without -w 0, wt.exe opens a new window by default.
Expand Down Expand Up @@ -879,9 +893,7 @@ func buildWSLWTArgs(shell ShellInfo, resumeCmd, winCwd, distro, launchStyle, pan
args = append(args, "-w", "new", "new-tab")
case LaunchStylePane:
args = append(args, "-w", "0", "split-pane")
if paneDirection != "" && paneDirection != "auto" {
args = append(args, "--direction", paneDirection)
}
args = appendWTPaneDirFlags(args, paneDirection)
default:
args = append(args, "-w", "0", "new-tab")
}
Expand Down
7 changes: 5 additions & 2 deletions internal/platform/wsl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,11 @@ func TestBuildWSLWTArgs_LaunchStyles(t *testing.T) {
{"explicit_tab", LaunchStyleTab, "", []string{"-w", "0", "new-tab"}},
{"window", LaunchStyleWindow, "", []string{"-w", "new", "new-tab"}},
{"pane_auto", LaunchStylePane, "auto", []string{"-w", "0", "split-pane"}},
{"pane_right", LaunchStylePane, "right", []string{"-w", "0", "split-pane", "--direction", "right"}},
{"pane_down", LaunchStylePane, "down", []string{"-w", "0", "split-pane", "--direction", "down"}},
{"pane_right", LaunchStylePane, "right", []string{"-w", "0", "split-pane", "-V"}},
{"pane_down", LaunchStylePane, "down", []string{"-w", "0", "split-pane", "-H"}},
{"pane_left", LaunchStylePane, "left", []string{"-w", "0", "split-pane", "-V"}},
{"pane_up", LaunchStylePane, "up", []string{"-w", "0", "split-pane", "-H"}},
{"pane_empty_dir", LaunchStylePane, "", []string{"-w", "0", "split-pane"}},
}

for _, tc := range tests {
Expand Down
Loading