Restore navigation after SSH manager host switching

After the manager is closed and drawn again, SetCurrentView selects the
new sshManager and that view's frame and title are set to the selected
colors. TestSSHManagerNavigation opens the manager with one configured
host, runs the selection through a stub ssh command, and checks that the
current view is the rebuilt manager with those colors.

Fixes #70
This commit is contained in:
Matt Van Horn
2026-10-23 06:12:36 -07:00
parent 910a15caf7
commit 06d5095a55
2 changed files with 87 additions and 0 deletions
+8
View File
@@ -9819,6 +9819,14 @@ func (app *App) getSelectedLine(g *gocui.Gui, v *gocui.View) error {
// Обновляем все списки в менеджере (что бы загрузить удаленный список контекстов Docker и Kubernetes)
app.closeManager(g)
app.showInterfaceManager(g)
// closeManager удаляет сфокусированное окно. Без нового фокуса стрелки
// продолжают попадать в старый sshManager, которого уже нет на экране.
sshView, err := g.SetCurrentView("sshManager")
if err != nil {
return err
}
sshView.FrameColor = app.selectedFrameColor
sshView.TitleColor = app.selectedTitleColor
// Сбрасываем контексты
app.dockerContext = "default"
app.kubernetesContext = "default"
+79
View File
@@ -9,6 +9,7 @@ import (
"os"
"os/exec"
"os/user"
"path/filepath"
"regexp"
"runtime"
"strings"
@@ -1736,3 +1737,81 @@ func TestMockInterface(t *testing.T) {
quit(g, nil)
}
// TestSSHManagerNavigation проверяет фокус после смены SSH-хоста.
func TestSSHManagerNavigation(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("SSH fixture requires a Unix shell")
}
origConfig, origGui := config, g
t.Cleanup(func() {
config, g = origConfig, origGui
})
config = Config{}
config.Ssh.Hosts = []string{"user@host-a"}
binDir := t.TempDir()
if err := os.WriteFile(filepath.Join(binDir, "ssh"), []byte("#!/bin/sh\ncase \"$*\" in *uname*) printf Linux ;; esac\n"), 0o755); err != nil {
t.Fatal(err)
}
t.Setenv("PATH", binDir)
app := &App{
testMode: true,
fastMode: false,
getOS: runtime.GOOS,
getArch: runtime.GOARCH,
selectUnits: "systemUnits",
selectPath: "varlog",
selectContainerizationSystem: "docker",
selectFilterMode: "default",
logViewCount: "10000",
unitType: "service",
colorMode: "disable",
dockerContext: "default",
kubernetesContext: "default",
kubernetesNamespace: "--all-namespaces",
sshStatus: "false",
globalCurrentView: "filterList",
keybindingsEnabled: true,
autoScroll: true,
timestampDocker: true,
frameColor: gocui.ColorWhite,
titleColor: gocui.ColorWhite,
selectedFrameColor: gocui.ColorGreen,
selectedTitleColor: gocui.ColorYellow,
filterByDateStatus: "false",
journalPriority: "debug",
journalBoot: "all",
}
var err error
g, err = gocui.NewGui(gocui.OutputSimulator, true)
if err != nil {
t.Fatal(err)
}
app.gui = g
g.Mouse = false
if err := app.layout(g); err != nil {
t.Fatal(err)
}
app.showInterfaceManager(g)
view, err := g.SetCurrentView("sshManager")
if err != nil {
t.Fatal(err)
}
view.Clear()
fmt.Fprintln(view, "user@host-a")
if err := app.getSelectedLine(g, view); err != nil {
t.Fatal(err)
}
fresh, err := g.View("sshManager")
if err != nil {
t.Fatal(err)
}
if fresh == view || g.CurrentView() != fresh {
t.Fatal("SSH selection did not focus the rebuilt manager")
}
if fresh.FrameColor != app.selectedFrameColor || fresh.TitleColor != app.selectedTitleColor {
t.Fatal("rebuilt SSH manager does not have selected colors")
}
}