Skip to content

Commit f7b1a86

Browse files
committed
style(tui): clarify active panel
1 parent ee1e440 commit f7b1a86

3 files changed

Lines changed: 36 additions & 11 deletions

File tree

pkg/gui/keybindings_test.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,23 @@ func TestOptionsMapToString(t *testing.T) {
2121
}
2222

2323
func TestFormatPanelTitle(t *testing.T) {
24-
actual := formatPanelTitle(2, "Packages")
25-
expected := "2 Packages"
24+
testCases := []struct {
25+
name string
26+
focused bool
27+
expected string
28+
}{
29+
{name: "focused", focused: true, expected: "> 2 Packages"},
30+
{name: "unfocused", focused: false, expected: " 2 Packages"},
31+
}
2632

27-
if actual != expected {
28-
t.Fatalf("formatPanelTitle() = %q, want %q", actual, expected)
33+
for _, testCase := range testCases {
34+
testCase := testCase
35+
t.Run(testCase.name, func(t *testing.T) {
36+
actual := formatPanelTitle(2, "Packages", testCase.focused)
37+
if actual != testCase.expected {
38+
t.Fatalf("formatPanelTitle() = %q, want %q", actual, testCase.expected)
39+
}
40+
})
2941
}
3042
}
3143

pkg/gui/layout.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
236236
if err.Error() != "unknown view" {
237237
return err
238238
}
239-
v.Title = formatPanelTitle(1, gui.Tr.SLocalize("StatusTitle"))
239+
v.Title = gui.panelTitle("status", 1, gui.Tr.SLocalize("StatusTitle"))
240240
v.FgColor = textColor
241241
}
242242

@@ -246,7 +246,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
246246
return err
247247
}
248248
packagesView.Highlight = true
249-
packagesView.Title = formatPanelTitle(2, gui.Tr.SLocalize("PackagesTitle"))
249+
packagesView.Title = gui.panelTitle("packages", 2, gui.Tr.SLocalize("PackagesTitle"))
250250
packagesView.ContainsList = true
251251
}
252252

@@ -255,7 +255,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
255255
if err.Error() != "unknown view" {
256256
return err
257257
}
258-
depsView.Title = formatPanelTitle(3, gui.Tr.SLocalize("DepsTitle"))
258+
depsView.Title = gui.panelTitle("deps", 3, gui.Tr.SLocalize("DepsTitle"))
259259
depsView.FgColor = textColor
260260
depsView.ContainsList = true
261261
}
@@ -265,7 +265,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
265265
if err.Error() != "unknown view" {
266266
return err
267267
}
268-
scriptsView.Title = formatPanelTitle(4, gui.Tr.SLocalize("ScriptsTitle"))
268+
scriptsView.Title = gui.panelTitle("scripts", 4, gui.Tr.SLocalize("ScriptsTitle"))
269269
scriptsView.FgColor = textColor
270270
scriptsView.ContainsList = true
271271
}
@@ -275,7 +275,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
275275
if err.Error() != "unknown view" {
276276
return err
277277
}
278-
tarballsView.Title = formatPanelTitle(5, gui.Tr.SLocalize("TarballsTitle"))
278+
tarballsView.Title = gui.panelTitle("tarballs", 5, gui.Tr.SLocalize("TarballsTitle"))
279279
tarballsView.FgColor = textColor
280280
tarballsView.ContainsList = true
281281
}

pkg/gui/view_helpers.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,21 @@ func (gui *Gui) optionsMapToString(optionsMap map[string]string) string {
206206
return strings.Join(optionsArray, " • ")
207207
}
208208

209-
func formatPanelTitle(number int, title string) string {
210-
return fmt.Sprintf("%d %s", number, title)
209+
func (gui *Gui) panelTitle(viewName string, number int, title string) string {
210+
currentView := gui.g.CurrentView()
211+
focused := currentView != nil && currentView.Name() == viewName
212+
if currentView == nil {
213+
focused = viewName == "packages"
214+
}
215+
return formatPanelTitle(number, title, focused)
216+
}
217+
218+
func formatPanelTitle(number int, title string, focused bool) string {
219+
marker := " "
220+
if focused {
221+
marker = ">"
222+
}
223+
return fmt.Sprintf("%s %d %s", marker, number, title)
211224
}
212225

213226
func (gui *Gui) renderOptionsMap(optionsMap map[string]string) error {

0 commit comments

Comments
 (0)