From ccc353261b2d68e5207cb6d305a0fd9f01831dd4 Mon Sep 17 00:00:00 2001 From: Hadi <112569860+anotherhadi@users.noreply.github.com> Date: Thu, 20 Aug 2026 20:30:55 +0200 Subject: [PATCH] Shorthelp/Fullhelp Signed-off-by: Hadi <112569860+anotherhadi@users.noreply.github.com> --- ui/keys.go | 6 ++++++ ui/model.go | 12 +++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/ui/keys.go b/ui/keys.go index 176c42c..1f930f4 100644 --- a/ui/keys.go +++ b/ui/keys.go @@ -37,6 +37,12 @@ func (k listKeyMap) globalBindings() []key.Binding { } } +func (k listKeyMap) shortHelpBindings() []key.Binding { + return []key.Binding{ + k.Open, k.Allow, k.Block, k.Reject, k.Filter, k.Quit, + } +} + var listKeys = listKeyMap{ Open: key.NewBinding(key.WithKeys("enter", "tab"), key.WithHelp("enter/tab", "select action")), Filter: key.NewBinding(key.WithKeys("/"), key.WithHelp("/", "filter")), diff --git a/ui/model.go b/ui/model.go index 5d2adfe..8e8ac0a 100644 --- a/ui/model.go +++ b/ui/model.go @@ -68,7 +68,6 @@ func New() Model { h := helpbar.New( helpbar.WithToggle(listKeys.Help), - helpbar.WithGlobal(listKeys.globalBindings()...), ) rulesManaged := guard.IsRulesManaged() @@ -265,10 +264,17 @@ func (m Model) updateList(msg tea.KeyPressMsg) (Model, tea.Cmd) { func (m Model) View() string { header := m.renderHeader() listView := strings.TrimRight(m.list.View(), "\n") - helpView := strings.TrimRight(m.help.View(), "\n") + helpView := strings.TrimRight(m.help.View(m.helpBindings()...), "\n") return strings.Join([]string{header, listView, helpView}, "\n") } +func (m Model) helpBindings() []key.Binding { + if m.help.ShowAll { + return listKeys.globalBindings() + } + return listKeys.shortHelpBindings() +} + func (m Model) renderHeader() string { title := headerStyle.Render("USBGuard TUI") if style.S.NerdFonts { @@ -371,7 +377,7 @@ func (m Model) renderPendingRulesLine() string { func (m Model) listHeight() int { headerH := lipgloss.Height(m.renderHeader()) - helpH := m.help.Height() + helpH := m.help.Height(m.helpBindings()...) return m.height - headerH - helpH }