Enhance search with match highlighting, count display, Ctrl+U to clear

This commit is contained in:
Calmcacil
2026-01-12 23:43:24 +01:00
parent 6629598574
commit 99b9dc17db

View File

@@ -1,8 +1,9 @@
package components package components
import ( import (
"fmt"
"github.com/calmcacil/wg-admin/internal/tui/theme" "github.com/calmcacil/wg-admin/internal/tui/theme"
"strconv"
"strings" "strings"
"github.com/charmbracelet/bubbles/textinput" "github.com/charmbracelet/bubbles/textinput"
@@ -91,6 +92,10 @@ func (m *SearchModel) Update(msg tea.Msg) (*SearchModel, tea.Cmd) {
m.input.Reset() m.input.Reset()
m.matchCount = m.totalCount m.matchCount = m.totalCount
return m, nil return m, nil
case "ctrl+u":
m.input.Reset()
m.matchCount = m.totalCount
return m, nil
case "tab": case "tab":
m.cycleFilterType() m.cycleFilterType()
return m, nil return m, nil
@@ -144,7 +149,7 @@ func (m *SearchModel) View() string {
helpText := "" helpText := ""
if m.active { if m.active {
helpText = searchHelpStyle.Render(" | Tab: filter | Esc: clear") helpText = searchHelpStyle.Render(" | Tab: filter | Ctrl+U: clear | Esc: exit")
} else { } else {
helpText = searchHelpStyle.Render(" | /: search") helpText = searchHelpStyle.Render(" | /: search")
} }
@@ -273,7 +278,7 @@ func (m *SearchModel) HighlightMatches(value string) string {
return lipgloss.JoinHorizontal( return lipgloss.JoinHorizontal(
lipgloss.Left, lipgloss.Left,
before, before,
matchStyle.Render(string(match)), matchStyle.Render(match),
after, after,
) )
} }
@@ -299,7 +304,7 @@ func (m *SearchModel) renderCount(count int) string {
Foreground(lipgloss.Color("196")). Foreground(lipgloss.Color("196")).
Render("No matches") Render("No matches")
} }
return searchCountStyle.Render(string(rune('0' + count))) return searchCountStyle.Render(fmt.Sprintf("%d", count))
} }
// ClientData represents client data for filtering // ClientData represents client data for filtering