From 06d5095a550ec587ea191ca4128c80c4138730a7 Mon Sep 17 00:00:00 2001 From: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Date: Fri, 23 Oct 2026 06:12:36 -0700 Subject: [PATCH] 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 --- main.go | 8 ++++++ main_test.go | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) diff --git a/main.go b/main.go index c8e4fde..8c0a10b 100644 --- a/main.go +++ b/main.go @@ -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" diff --git a/main_test.go b/main_test.go index 1acfab1..1c13cac 100644 --- a/main_test.go +++ b/main_test.go @@ -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") + } +}