diff --git a/internal/tui/components/search.go b/internal/tui/components/search.go index c684c3c..c844869 100644 --- a/internal/tui/components/search.go +++ b/internal/tui/components/search.go @@ -1,8 +1,9 @@ package components import ( + "fmt" + "github.com/calmcacil/wg-admin/internal/tui/theme" - "strconv" "strings" "github.com/charmbracelet/bubbles/textinput" @@ -35,20 +36,20 @@ type SearchModel struct { // Styles (using theme package) var ( searchBarStyle = lipgloss.NewStyle(). - Foreground(lipgloss.Color("255")). - Background(theme.StyleBackground). - Padding(0, 1). - Border(lipgloss.RoundedBorder()). - BorderForeground(theme.StyleBorder) + Foreground(lipgloss.Color("255")). + Background(theme.StyleBackground). + Padding(0, 1). + Border(lipgloss.RoundedBorder()). + BorderForeground(theme.StyleBorder) searchPromptStyle = lipgloss.NewStyle(). - Foreground(lipgloss.Color("226")). - Bold(true) + Foreground(lipgloss.Color("226")). + Bold(true) searchFilterStyle = lipgloss.NewStyle(). - Foreground(lipgloss.Color("147")) + Foreground(lipgloss.Color("147")) searchCountStyle = lipgloss.NewStyle(). - Foreground(lipgloss.Color("241")) + Foreground(lipgloss.Color("241")) searchHelpStyle = lipgloss.NewStyle(). - Foreground(lipgloss.Color("243")) + Foreground(lipgloss.Color("243")) ) // NewSearch creates a new search component @@ -91,6 +92,10 @@ func (m *SearchModel) Update(msg tea.Msg) (*SearchModel, tea.Cmd) { m.input.Reset() m.matchCount = m.totalCount return m, nil + case "ctrl+u": + m.input.Reset() + m.matchCount = m.totalCount + return m, nil case "tab": m.cycleFilterType() return m, nil @@ -144,7 +149,7 @@ func (m *SearchModel) View() string { helpText := "" if m.active { - helpText = searchHelpStyle.Render(" | Tab: filter | Esc: clear") + helpText = searchHelpStyle.Render(" | Tab: filter | Ctrl+U: clear | Esc: exit") } else { helpText = searchHelpStyle.Render(" | /: search") } @@ -273,7 +278,7 @@ func (m *SearchModel) HighlightMatches(value string) string { return lipgloss.JoinHorizontal( lipgloss.Left, before, - matchStyle.Render(string(match)), + matchStyle.Render(match), after, ) } @@ -299,7 +304,7 @@ func (m *SearchModel) renderCount(count int) string { Foreground(lipgloss.Color("196")). Render("No matches") } - return searchCountStyle.Render(string(rune('0' + count))) + return searchCountStyle.Render(fmt.Sprintf("%d", count)) } // ClientData represents client data for filtering