Shorthelp/Fullhelp

Signed-off-by: Hadi <112569860+anotherhadi@users.noreply.github.com>
This commit is contained in:
Hadi
2026-08-20 20:30:55 +02:00
parent e77eaf4e2c
commit ccc353261b
2 changed files with 15 additions and 3 deletions
+6
View File
@@ -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")),
+9 -3
View File
@@ -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
}