Skip to content

Commit c5e663e

Browse files
committed
chore: add navigation with q/esc for back navigation
It won't work if you're on "Collections" view because there's no going back from there. I've kept this separate from `Ctrl-c` quit as to have different key-stroke flows for going back/forth vs quitting the app.
1 parent b0311e1 commit c5e663e

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

internal/tui/app/model.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ func (a AppModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
8989
switch {
9090
case key.Matches(msg, keybinds.Keys.Quit):
9191
return a, tea.Quit
92+
case key.Matches(msg, keybinds.Keys.Back):
93+
if a.focusedView == Endpoints {
94+
return a, func() tea.Msg {
95+
return messages.NavigateToView{
96+
ViewName: string(Collections),
97+
Data: nil,
98+
}
99+
}
100+
}
92101
}
93102
}
94103

@@ -114,9 +123,17 @@ func (a AppModel) View() string {
114123

115124
func (a AppModel) Help() string {
116125
viewHelp := a.Views[a.focusedView].Help()
117-
appHelp := append(viewHelp, a.keys...)
126+
127+
var appHelp []key.Binding
128+
appHelp = append(appHelp, a.keys...)
129+
130+
if a.focusedView == Endpoints {
131+
appHelp = append(appHelp, keybinds.Keys.Back)
132+
}
133+
134+
allHelp := append(viewHelp, appHelp...)
118135
helpStruct := keybinds.Help{
119-
Keys: appHelp,
136+
Keys: allHelp,
120137
}
121138
return styles.HelpStyle.Render(a.help.View(helpStruct))
122139
}

internal/tui/keybinds/keys.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ type Keymaps struct {
2424

2525
var Keys = Keymaps{
2626
Back: key.NewBinding(
27-
key.WithKeys("esc"),
28-
key.WithHelp("esc", "back"),
27+
key.WithKeys("esc", "q"),
28+
key.WithHelp("esc/q", "back"),
2929
),
3030
Up: key.NewBinding(
3131
key.WithKeys("up", "k"),

0 commit comments

Comments
 (0)