Fix q key behavior in client details view
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package screens
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -135,17 +136,62 @@ func (s *ListScreen) Update(msg tea.Msg) (Screen, tea.Cmd) {
|
||||
}
|
||||
|
||||
// View renders the list screen
|
||||
// Breadcrumb: Home
|
||||
breadcrumb := components.RenderBreadcrumb([]components.BreadcrumbItem{
|
||||
{Label: "Clients", ID: "list"},
|
||||
})
|
||||
|
||||
func (s *ListScreen) View() string {
|
||||
if len(s.clients) == 0 {
|
||||
return s.search.View() + "\n" + "No clients found. Press 'r' to refresh or 'q' to quit."
|
||||
// Empty state with helpful guidance
|
||||
return s.search.View() + "\n\n" +
|
||||
lipgloss.NewStyle().
|
||||
Foreground(lipgloss.Color("226")).
|
||||
Bold(true).
|
||||
Render("No clients yet") + "\n" +
|
||||
lipgloss.NewStyle().
|
||||
Foreground(lipgloss.Color("241")).
|
||||
Render("Let's get started! Here are your options:") + "\n" +
|
||||
lipgloss.NewStyle().
|
||||
Foreground(lipgloss.Color("109")).
|
||||
Render(" • Press [a] to add your first client") + "\n" +
|
||||
lipgloss.NewStyle().
|
||||
Foreground(lipgloss.Color("109")).
|
||||
Render(" • Press [R] to restore from backup") + "\n" +
|
||||
lipgloss.NewStyle().
|
||||
Foreground(lipgloss.Color("109")).
|
||||
Render(" • Press [r] to refresh the client list") + "\n" +
|
||||
lipgloss.NewStyle().
|
||||
Foreground(lipgloss.Color("109")).
|
||||
Render(" • Press [q] to quit")
|
||||
}
|
||||
|
||||
// Check if there are no matches
|
||||
if s.search.IsActive() && len(s.filtered) == 0 && s.search.GetQuery() != "" {
|
||||
return s.search.View() + "\n" + lipgloss.NewStyle().
|
||||
Foreground(lipgloss.Color("241")).
|
||||
Italic(true).
|
||||
Render("No matching clients found. Try a different search term.")
|
||||
// Empty search results with helpful tips
|
||||
return s.search.View() + "\n\n" +
|
||||
lipgloss.NewStyle().
|
||||
Foreground(lipgloss.Color("226")).
|
||||
Bold(true).
|
||||
Render("No matching clients found") + "\n" +
|
||||
lipgloss.NewStyle().
|
||||
Foreground(lipgloss.Color("241")).
|
||||
Render("Search tips:") + "\n" +
|
||||
lipgloss.NewStyle().
|
||||
Foreground(lipgloss.Color("109")).
|
||||
Render(" • Check your spelling") + "\n" +
|
||||
lipgloss.NewStyle().
|
||||
Foreground(lipgloss.Color("109")).
|
||||
Render(" • Try a shorter search term") + "\n" +
|
||||
lipgloss.NewStyle().
|
||||
Foreground(lipgloss.Color("109")).
|
||||
Render(" • Search by name, IP, or status") + "\n" +
|
||||
lipgloss.NewStyle().
|
||||
Foreground(lipgloss.Color("109")).
|
||||
Render(" • Press [esc] to clear search") + "\n" +
|
||||
lipgloss.NewStyle().
|
||||
Foreground(lipgloss.Color("109")).
|
||||
Render(" • Press [r] to refresh client list")
|
||||
}
|
||||
|
||||
// Calculate time since last update
|
||||
@@ -228,13 +274,21 @@ func (s *ListScreen) applyFilter() {
|
||||
s.buildTable()
|
||||
}
|
||||
|
||||
// formatStatusWithIcon formats the status with a colored circle icon
|
||||
func (s *ListScreen) formatStatusWithIcon(status string) string {
|
||||
if status == wireguard.StatusConnected {
|
||||
return lipgloss.NewStyle().Foreground(lipgloss.Color("46")).Render("●") + " " + status
|
||||
}
|
||||
return lipgloss.NewStyle().Foreground(lipgloss.Color("196")).Render("●") + " " + status
|
||||
}
|
||||
|
||||
// buildTable creates and configures the table
|
||||
func (s *ListScreen) buildTable() {
|
||||
columns := []table.Column{
|
||||
{Title: "Name", Width: 20},
|
||||
{Title: "IPv4", Width: 15},
|
||||
{Title: "IPv6", Width: 35},
|
||||
{Title: "Status", Width: 12},
|
||||
{Title: "Status", Width: 14},
|
||||
}
|
||||
|
||||
// Use filtered clients if search is active, otherwise use all clients
|
||||
@@ -245,11 +299,12 @@ func (s *ListScreen) buildTable() {
|
||||
|
||||
var rows []table.Row
|
||||
for _, cws := range displayClients {
|
||||
statusText := s.formatStatusWithIcon(cws.Status)
|
||||
row := table.Row{
|
||||
cws.Client.Name,
|
||||
cws.Client.IPv4,
|
||||
cws.Client.IPv6,
|
||||
cws.Status,
|
||||
statusText,
|
||||
}
|
||||
rows = append(rows, row)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user