mirror of
https://github.com/anotherhadi/usbguard-tui.git
synced 2026-08-21 03:55:50 +02:00
Shorthelp/Fullhelp
Signed-off-by: Hadi <112569860+anotherhadi@users.noreply.github.com>
This commit is contained in:
@@ -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
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user