Enhance search with match highlighting, count display, Ctrl+U to clear
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
package components
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/calmcacil/wg-admin/internal/tui/theme"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/charmbracelet/bubbles/textinput"
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user