From 306f38e862a325a415410775673d2ff72349c7b5 Mon Sep 17 00:00:00 2001 From: Gu1llaum-3 Date: Sat, 13 Sep 2025 08:34:11 +0200 Subject: [PATCH] feat: show error when move requires includes but none found --- internal/ui/model.go | 4 ++++ internal/ui/move_form.go | 2 +- internal/ui/update.go | 18 ++++++++++++++++-- internal/ui/view.go | 14 ++++++++++++++ 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/internal/ui/model.go b/internal/ui/model.go index 5c74c49..a47e4ab 100644 --- a/internal/ui/model.go +++ b/internal/ui/model.go @@ -99,6 +99,10 @@ type Model struct { height int styles Styles ready bool + + // Error handling + errorMessage string + showingError bool } // updateTableStyles updates the table header border color based on focus state diff --git a/internal/ui/move_form.go b/internal/ui/move_form.go index a5032e0..46019ae 100644 --- a/internal/ui/move_form.go +++ b/internal/ui/move_form.go @@ -42,7 +42,7 @@ func NewMoveForm(hostName string, styles Styles, width, height int, configFile s } if len(files) == 0 { - return nil, fmt.Errorf("no other config files available to move host to") + return nil, fmt.Errorf("no includes found in SSH config file - move operation requires multiple config files") } // Create a custom file selector for move operation diff --git a/internal/ui/update.go b/internal/ui/update.go index 38f9f41..3928c04 100644 --- a/internal/ui/update.go +++ b/internal/ui/update.go @@ -19,6 +19,7 @@ type ( pingResultMsg *connectivity.HostPingResult versionCheckMsg *version.UpdateInfo versionErrorMsg error + errorMsg string ) // startPingAllCmd creates a command to ping all hosts concurrently @@ -157,6 +158,14 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { // as it might disrupt the user experience return m, nil + case errorMsg: + // Handle general error messages + if string(msg) == "clear" { + m.showingError = false + m.errorMessage = "" + } + return m, nil + case addFormSubmitMsg: if msg.err != nil { // Show error in form @@ -587,8 +596,13 @@ func (m Model) handleListViewKeys(msg tea.KeyMsg) (tea.Model, tea.Cmd) { hostName := extractHostNameFromTableRow(selected[0]) // Extract hostname from first column moveForm, err := NewMoveForm(hostName, m.styles, m.width, m.height, m.configFile) if err != nil { - // Handle error - could show in UI, e.g., no other config files available - return m, nil + // Show error message to user + m.errorMessage = err.Error() + m.showingError = true + return m, func() tea.Msg { + time.Sleep(3 * time.Second) // Show error for 3 seconds + return errorMsg("clear") + } } m.moveForm = moveForm m.viewMode = ViewMove diff --git a/internal/ui/view.go b/internal/ui/view.go index 9875c86..9f5f94e 100644 --- a/internal/ui/view.go +++ b/internal/ui/view.go @@ -72,6 +72,20 @@ func (m Model) renderListView() string { components = append(components, updateStyle.Render(updateText)) } + // Add error message if there's one to show + if m.showingError && m.errorMessage != "" { + errorStyle := lipgloss.NewStyle(). + Foreground(lipgloss.Color("9")). // Red color + Background(lipgloss.Color("1")). // Dark red background + Bold(true). + Padding(0, 1). + Border(lipgloss.RoundedBorder()). + BorderForeground(lipgloss.Color("9")). + Align(lipgloss.Center) + + components = append(components, errorStyle.Render("❌ "+m.errorMessage)) + } + // Add the search bar with the appropriate style based on focus searchPrompt := "Search (/ to focus): " if m.searchMode {