xonecas.io
60255
Zn

Zoea-Nova / commit ce9014f

Consolidate error display into keyboard controls status bar

Move global application errors and validation errors from a separate line
below the input box to the right side of the keyboard controls hint line.
This creates a cleaner, more compact layout while maintaining visibility
of error messages.

Changes:
- Remove separate error line below input box in app.go View()
- Add err parameter to RenderDashboard, RenderFocusView, and RenderFocusViewWithViewport
- Implement renderHintWithError() helper that displays errors on the right side
  of the hint line with smart truncation when space is limited
- Update all render function call sites to pass m.err
- Update all test files to pass nil for error parameter
- Add comprehensive error display tests

The error now appears as:
  [keyboard controls]  ...padding...  Error: message

If terminal width is insufficient (<15 chars for error), only the hint is shown.

xonecas2026-02-08 ce9014f8a7162dd291c5937267a08d3b49245df0 parent 5b7f428

11 files changed

internal/tui/app.go+2−8
@@ -325,7 +325,7 @@ func (m Model) View() string {
325325 content = RenderHelp(m.width, contentHeight)
326326 } else if m.view == ViewFocus {
327327 focusIndex, totalMyses := m.focusPosition(m.focusID)
328- content = RenderFocusViewWithViewport(m.mysisByID(m.focusID), m.viewport, m.width, isLoading, m.spinner.View(), m.verboseJSON, m.viewportTotalLines, focusIndex, totalMyses, m.currentTick)
328+ content = RenderFocusViewWithViewport(m.mysisByID(m.focusID), m.viewport, m.width, isLoading, m.spinner.View(), m.verboseJSON, m.viewportTotalLines, focusIndex, totalMyses, m.currentTick, m.err)
329329 } else {
330330 // Convert swarm messages for display (reversed so most recent is first)
331331 swarmInfos := make([]SwarmMessageInfo, len(m.swarmMessages))
@@ -338,7 +338,7 @@ func (m Model) View() string {
338338 CreatedAt: msg.CreatedAt,
339339 }
340340 }
341- content = RenderDashboard(m.myses, swarmInfos, m.selectedIdx, m.width, contentHeight-3, m.loadingSet, m.spinner.View(), m.currentTick)
341+ content = RenderDashboard(m.myses, swarmInfos, m.selectedIdx, m.width, contentHeight-3, m.loadingSet, m.spinner.View(), m.currentTick, m.err)
342342 }
343343
344344 // Always show message bar
@@ -355,12 +355,6 @@ func (m Model) View() string {
355355 }
356356 content += "\n" + m.input.ViewAlways(m.width, m.sending, sendingLabel, m.spinner.View())
357357
358- // Add error if present
359- if m.err != nil {
360- errMsg := stateErroredStyle.Render(fmt.Sprintf("Error: %v", m.err))
361- content += "\n" + errMsg
362- }
363-
364358 // Build status bar
365359 statusBar := m.renderStatusBar()
366360
internal/tui/dashboard.go+47−3
@@ -44,7 +44,7 @@ type SwarmMessageInfo struct {
4444 }
4545
4646 // RenderDashboard renders the main dashboard view.
47-func RenderDashboard(myses []MysisInfo, swarmMessages []SwarmMessageInfo, selectedIdx int, width, height int, loadingSet map[string]bool, spinnerView string, currentTick int64) string {
47+func RenderDashboard(myses []MysisInfo, swarmMessages []SwarmMessageInfo, selectedIdx int, width, height int, loadingSet map[string]bool, spinnerView string, currentTick int64, err error) string {
4848 var sections []string
4949
5050 // Header - retro-futuristic command center banner with hexagonal motif (matching logo)
@@ -162,8 +162,8 @@ func RenderDashboard(myses []MysisInfo, swarmMessages []SwarmMessageInfo, select
162162 sections = append(sections, mysisList)
163163 }
164164
165- // Footer with hint
166- hint := dimmedStyle.Render("[ ? ] HELP · [ n ] NEW MYSIS · [ b ] BROADCAST")
165+ // Footer with hint and error status
166+ hint := renderHintWithError("[ ? ] HELP · [ n ] NEW MYSIS · [ b ] BROADCAST", err, width)
167167 sections = append(sections, hint)
168168
169169 return lipgloss.JoinVertical(lipgloss.Left, sections...)
@@ -529,3 +529,47 @@ func formatCoreError(err error) string {
529529 }
530530 return err.Error()
531531 }
532+
533+// renderHintWithError renders a hint line with optional error status on the right.
534+func renderHintWithError(hintText string, err error, width int) string {
535+ if err == nil {
536+ return dimmedStyle.Render(hintText)
537+ }
538+
539+ // Format error message
540+ errMsg := fmt.Sprintf("Error: %v", err)
541+ styledError := stateErroredStyle.Render(errMsg)
542+
543+ // Calculate available space
544+ hintWidth := lipgloss.Width(hintText)
545+ errorWidth := lipgloss.Width(styledError)
546+ separator := " "
547+ sepWidth := lipgloss.Width(separator)
548+
549+ // If error is too long, truncate it
550+ maxErrorWidth := width - hintWidth - sepWidth
551+ if maxErrorWidth < 15 {
552+ // Not enough space for meaningful error, just show hint
553+ return dimmedStyle.Render(hintText)
554+ }
555+
556+ if errorWidth > maxErrorWidth {
557+ // Truncate error message
558+ plainErr := fmt.Sprintf("Error: %v", err)
559+ if maxErrorWidth > 10 {
560+ plainErr = truncateToWidth(plainErr, maxErrorWidth-3) + "..."
561+ } else {
562+ plainErr = truncateToWidth(plainErr, maxErrorWidth)
563+ }
564+ styledError = stateErroredStyle.Render(plainErr)
565+ errorWidth = lipgloss.Width(styledError)
566+ }
567+
568+ // Calculate padding between hint and error
569+ padding := width - hintWidth - errorWidth
570+ if padding < sepWidth {
571+ padding = sepWidth
572+ }
573+
574+ return dimmedStyle.Render(hintText) + strings.Repeat(" ", padding-sepWidth) + separator + styledError
575+}
internal/tui/error_display_test.go+144−0
@@ -0,0 +1,144 @@
1+package tui
2+
3+import (
4+ "errors"
5+ "strings"
6+ "testing"
7+
8+ "github.com/charmbracelet/bubbles/viewport"
9+ "github.com/charmbracelet/lipgloss"
10+)
11+
12+func TestErrorDisplayInDashboard(t *testing.T) {
13+ testErr := errors.New("test error message")
14+
15+ // Render dashboard with error
16+ output := RenderDashboard(
17+ []MysisInfo{},
18+ []SwarmMessageInfo{},
19+ 0,
20+ 100,
21+ 30,
22+ make(map[string]bool),
23+ "⠋",
24+ 0,
25+ testErr,
26+ )
27+
28+ // Error should appear in the hint line
29+ if !strings.Contains(output, "Error: test error message") {
30+ t.Error("expected error message to appear in dashboard output")
31+ }
32+
33+ // Error should be on the same line as keyboard controls
34+ lines := strings.Split(output, "\n")
35+ foundErrorLine := false
36+ for _, line := range lines {
37+ if strings.Contains(line, "HELP") && strings.Contains(line, "Error:") {
38+ foundErrorLine = true
39+ break
40+ }
41+ }
42+ if !foundErrorLine {
43+ t.Error("expected error to appear on same line as keyboard controls")
44+ }
45+}
46+
47+func TestErrorDisplayInFocusView(t *testing.T) {
48+ testErr := errors.New("focus view error")
49+
50+ mysis := MysisInfo{
51+ ID: "test-id",
52+ Name: "TestMysis",
53+ State: "running",
54+ Provider: "opencode",
55+ }
56+
57+ vp := viewport.New(120, 20)
58+ vp.SetContent("Test content")
59+
60+ // Render focus view with error (use wider terminal to fit error)
61+ output := RenderFocusViewWithViewport(
62+ mysis,
63+ vp,
64+ 120,
65+ false,
66+ "⠋",
67+ false,
68+ 1,
69+ 1,
70+ 1,
71+ 0,
72+ testErr,
73+ )
74+
75+ // Error should appear in the hint line
76+ if !strings.Contains(output, "Error: focus view error") {
77+ t.Logf("Output:\n%s", output)
78+ t.Error("expected error message to appear in focus view output")
79+ }
80+
81+ // Error should be on the same line as keyboard controls
82+ lines := strings.Split(output, "\n")
83+ foundErrorLine := false
84+ for _, line := range lines {
85+ if strings.Contains(line, "ESC") && strings.Contains(line, "Error:") {
86+ foundErrorLine = true
87+ break
88+ }
89+ }
90+ if !foundErrorLine {
91+ t.Error("expected error to appear on same line as keyboard controls in focus view")
92+ }
93+}
94+
95+func TestNoErrorDisplay(t *testing.T) {
96+ // Render dashboard without error
97+ output := RenderDashboard(
98+ []MysisInfo{},
99+ []SwarmMessageInfo{},
100+ 0,
101+ 100,
102+ 30,
103+ make(map[string]bool),
104+ "⠋",
105+ 0,
106+ nil,
107+ )
108+
109+ // Should not contain "Error:"
110+ if strings.Contains(output, "Error:") {
111+ t.Error("expected no error message when err is nil")
112+ }
113+}
114+
115+func TestLongErrorTruncation(t *testing.T) {
116+ longErr := errors.New("this is a very long error message that should be truncated to fit within the available space on the terminal line without breaking the layout")
117+
118+ output := RenderDashboard(
119+ []MysisInfo{},
120+ []SwarmMessageInfo{},
121+ 0,
122+ 100,
123+ 30,
124+ make(map[string]bool),
125+ "⠋",
126+ 0,
127+ longErr,
128+ )
129+
130+ // Error should be present but truncated
131+ if !strings.Contains(output, "Error:") {
132+ t.Error("expected error message to appear")
133+ }
134+
135+ // Check that no line exceeds terminal width (using display width, not byte length)
136+ lines := strings.Split(output, "\n")
137+ for i, line := range lines {
138+ // Use lipgloss.Width for accurate display width (ignores ANSI codes)
139+ displayWidth := lipgloss.Width(line)
140+ if displayWidth > 100 {
141+ t.Errorf("line %d exceeds terminal width: %d display chars", i, displayWidth)
142+ }
143+ }
144+}
internal/tui/focus.go+7−6
@@ -95,7 +95,7 @@ func wrapText(text string, maxWidth int) []string {
9595 }
9696
9797 // RenderFocusView renders the detailed mysis view (legacy, without viewport).
98-func RenderFocusView(mysis MysisInfo, logs []LogEntry, width, height int, isLoading bool, spinnerView string, verbose bool, focusIndex, totalMyses int, currentTick int64) string {
98+func RenderFocusView(mysis MysisInfo, logs []LogEntry, width, height int, isLoading bool, spinnerView string, verbose bool, focusIndex, totalMyses int, currentTick int64, err error) string {
9999 var sections []string
100100
101101 // Header with mysis name - spans full width (2 lines)
@@ -158,15 +158,15 @@ func RenderFocusView(mysis MysisInfo, logs []LogEntry, width, height int, isLoad
158158 logPanel := logStyle.Width(width-2).Height(logHeight).Padding(0, 2).Render(logContent)
159159 sections = append(sections, logPanel)
160160
161- // Footer
162- hint := dimmedStyle.Render("[ ESC ] BACK · [ m ] MESSAGE · [ r ] RELAUNCH · [ s ] STOP")
161+ // Footer with hint and error status
162+ hint := renderHintWithError("[ ESC ] BACK · [ m ] MESSAGE · [ r ] RELAUNCH · [ s ] STOP", err, width)
163163 sections = append(sections, hint)
164164
165165 return lipgloss.JoinVertical(lipgloss.Left, sections...)
166166 }
167167
168168 // RenderFocusViewWithViewport renders the detailed mysis view using a scrollable viewport.
169-func RenderFocusViewWithViewport(mysis MysisInfo, vp viewport.Model, width int, isLoading bool, spinnerView string, verbose bool, totalLines int, focusIndex, totalMyses int, currentTick int64) string {
169+func RenderFocusViewWithViewport(mysis MysisInfo, vp viewport.Model, width int, isLoading bool, spinnerView string, verbose bool, totalLines int, focusIndex, totalMyses int, currentTick int64, err error) string {
170170 var sections []string
171171
172172 // Header with mysis name - spans full width (2 lines)
@@ -240,14 +240,15 @@ func RenderFocusViewWithViewport(mysis MysisInfo, vp viewport.Model, width int,
240240 logBottomBorder := renderSectionTitle("", width)
241241 sections = append(sections, logBottomBorder)
242242
243- // Footer with scroll hints and verbose toggle
243+ // Footer with scroll hints, verbose toggle, and error status
244244 verboseHint := ""
245245 if verbose {
246246 verboseHint = " · [ v ] VERBOSE: ON"
247247 } else {
248248 verboseHint = " · [ v ] VERBOSE: OFF"
249249 }
250- hint := dimmedStyle.Render(fmt.Sprintf("[ ESC ] BACK · [ m ] MESSAGE · [ ↑↓ ] SCROLL · [ G ] BOTTOM%s", verboseHint))
250+ hintText := fmt.Sprintf("[ ESC ] BACK · [ m ] MESSAGE · [ ↑↓ ] SCROLL · [ G ] BOTTOM%s", verboseHint)
251+ hint := renderHintWithError(hintText, err, width)
251252 sections = append(sections, hint)
252253
253254 return lipgloss.JoinVertical(lipgloss.Left, sections...)
internal/tui/focus_header_test.go+1−1
@@ -73,7 +73,7 @@ func TestFocusViewHeaderPresence(t *testing.T) {
7373 vp.GotoTop()
7474
7575 // Render focus view
76- output := RenderFocusViewWithViewport(mysis, vp, tt.termWidth, false, "⬡", false, len(contentLines), 1, 1, 0)
76+ output := RenderFocusViewWithViewport(mysis, vp, tt.termWidth, false, "⬡", false, len(contentLines), 1, 1, 0, nil)
7777
7878 // Split into lines
7979 lines := strings.Split(output, "\n")
internal/tui/focus_test.go+1−1
@@ -265,7 +265,7 @@ func TestRenderFocusViewWithScrollbar(t *testing.T) {
265265
266266 width := 100
267267 totalLines := 50
268- output := RenderFocusViewWithViewport(mysis, vp, width, false, "⬡", false, totalLines, 1, 1, 0)
268+ output := RenderFocusViewWithViewport(mysis, vp, width, false, "⬡", false, totalLines, 1, 1, 0, nil)
269269
270270 // Should contain scrollbar characters
271271 if !strings.Contains(output, "█") && !strings.Contains(output, "│") {
internal/tui/golden_edge_cases_test.go+2−2
@@ -160,7 +160,7 @@ func TestDashboardEdgeCases(t *testing.T) {
160160
161161 for _, tt := range tests {
162162 t.Run(tt.name, func(t *testing.T) {
163- output := RenderDashboard(tt.myses, tt.swarmMsgs, tt.selectedIdx, tt.width, tt.height, tt.loadingSet, "⠋", 0)
163+ output := RenderDashboard(tt.myses, tt.swarmMsgs, tt.selectedIdx, tt.width, tt.height, tt.loadingSet, "⠋", 0, nil)
164164
165165 t.Run("ANSI", func(t *testing.T) {
166166 golden.RequireEqual(t, []byte(output))
@@ -394,7 +394,7 @@ func TestFocusViewEdgeCases(t *testing.T) {
394394
395395 for _, tt := range tests {
396396 t.Run(tt.name, func(t *testing.T) {
397- output := RenderFocusView(tt.mysis, tt.logs, tt.width, tt.height, false, "⠋", false, 1, 1, 0)
397+ output := RenderFocusView(tt.mysis, tt.logs, tt.width, tt.height, false, "⠋", false, 1, 1, 0, nil)
398398
399399 t.Run("ANSI", func(t *testing.T) {
400400 golden.RequireEqual(t, []byte(output))
internal/tui/golden_test.go+3−3
@@ -152,7 +152,7 @@ func TestDashboard(t *testing.T) {
152152
153153 for _, tt := range tests {
154154 t.Run(tt.name, func(t *testing.T) {
155- output := RenderDashboard(tt.myses, tt.swarmMsgs, tt.selectedIdx, tt.width, tt.height, tt.loadingSet, "⠋", 0)
155+ output := RenderDashboard(tt.myses, tt.swarmMsgs, tt.selectedIdx, tt.width, tt.height, tt.loadingSet, "⠋", 0, nil)
156156
157157 t.Run("ANSI", func(t *testing.T) {
158158 golden.RequireEqual(t, []byte(output))
@@ -267,7 +267,7 @@ func TestFocusView(t *testing.T) {
267267
268268 for _, tt := range tests {
269269 t.Run(tt.name, func(t *testing.T) {
270- output := RenderFocusView(tt.mysis, tt.logs, tt.width, tt.height, false, "⠋", false, 1, 1, 0)
270+ output := RenderFocusView(tt.mysis, tt.logs, tt.width, tt.height, false, "⠋", false, 1, 1, 0, nil)
271271
272272 t.Run("ANSI", func(t *testing.T) {
273273 golden.RequireEqual(t, []byte(output))
@@ -473,7 +473,7 @@ func TestFocusViewWithViewport(t *testing.T) {
473473 vp.SetContent(strings.Join(contentLines, "\n"))
474474 vp.GotoTop()
475475
476- output := RenderFocusViewWithViewport(tt.mysis, vp, tt.width, false, "⠋", false, tt.totalLines, 1, 1, 0)
476+ output := RenderFocusViewWithViewport(tt.mysis, vp, tt.width, false, "⠋", false, tt.totalLines, 1, 1, 0, nil)
477477
478478 t.Run("ANSI", func(t *testing.T) {
479479 golden.RequireEqual(t, []byte(output))
internal/tui/layout_test.go+2−2
@@ -86,7 +86,7 @@ func TestDashboardLayoutCalculations(t *testing.T) {
8686
8787 // Render dashboard (account for input bar height: -3)
8888 contentHeight := tt.termHeight - 3
89- output := RenderDashboard(myses, swarmMsgs, 0, tt.termWidth, contentHeight, loadingSet, spinnerView, 0)
89+ output := RenderDashboard(myses, swarmMsgs, 0, tt.termWidth, contentHeight, loadingSet, spinnerView, 0, nil)
9090
9191 // Basic validations
9292 if output == "" {
@@ -206,7 +206,7 @@ func TestFocusViewLayoutCalculations(t *testing.T) {
206206 }()
207207
208208 // Render focus view
209- output := RenderFocusViewWithViewport(mysis, vp, tt.termWidth, false, "⬡", false, tt.numLogs, 1, 1, 0)
209+ output := RenderFocusViewWithViewport(mysis, vp, tt.termWidth, false, "⬡", false, tt.numLogs, 1, 1, 0, nil)
210210
211211 // Basic validations
212212 if output == "" {
internal/tui/spinner_test.go+1−1
@@ -320,7 +320,7 @@ func TestSpinnerInDashboard(t *testing.T) {
320320 },
321321 }
322322
323- output := RenderDashboard(myses, []SwarmMessageInfo{}, 0, TestTerminalWidth, TestTerminalHeight, map[string]bool{}, tt.spinnerView, 0)
323+ output := RenderDashboard(myses, []SwarmMessageInfo{}, 0, TestTerminalWidth, TestTerminalHeight, map[string]bool{}, tt.spinnerView, 0, nil)
324324
325325 t.Run("ANSI", func(t *testing.T) {
326326 golden.RequireEqual(t, []byte(output))
internal/tui/tui_test.go+7−7
@@ -255,21 +255,21 @@ func TestRenderDashboard(t *testing.T) {
255255
256256 loadingSet := make(map[string]bool)
257257 swarmMsgs := []SwarmMessageInfo{}
258- dashboard := RenderDashboard(myses, swarmMsgs, 0, 80, 24, loadingSet, "⠋", 0)
258+ dashboard := RenderDashboard(myses, swarmMsgs, 0, 80, 24, loadingSet, "⠋", 0, nil)
259259 if dashboard == "" {
260260 t.Error("expected non-empty dashboard")
261261 }
262262
263263 // Test with loading state
264264 loadingSet["1"] = true
265- dashboardWithLoading := RenderDashboard(myses, swarmMsgs, 0, 80, 24, loadingSet, "⠋", 0)
265+ dashboardWithLoading := RenderDashboard(myses, swarmMsgs, 0, 80, 24, loadingSet, "⠋", 0, nil)
266266 if dashboardWithLoading == "" {
267267 t.Error("expected non-empty dashboard with loading")
268268 }
269269 }
270270
271271 func TestRenderDashboardEmpty(t *testing.T) {
272- dashboard := RenderDashboard([]MysisInfo{}, []SwarmMessageInfo{}, 0, 80, 24, make(map[string]bool), "⠋", 0)
272+ dashboard := RenderDashboard([]MysisInfo{}, []SwarmMessageInfo{}, 0, 80, 24, make(map[string]bool), "⠋", 0, nil)
273273 if dashboard == "" {
274274 t.Error("expected non-empty dashboard even with no myses")
275275 }
@@ -282,13 +282,13 @@ func TestRenderFocusView(t *testing.T) {
282282 {Role: "assistant", Content: "Hi there! This is a longer response that might span multiple lines when properly wrapped in the terminal window."},
283283 }
284284
285- view := RenderFocusView(mysis, logs, 80, 24, false, "⠋", false, 1, 1, 0)
285+ view := RenderFocusView(mysis, logs, 80, 24, false, "⠋", false, 1, 1, 0, nil)
286286 if view == "" {
287287 t.Error("expected non-empty focus view")
288288 }
289289
290290 // Test with loading state
291- viewLoading := RenderFocusView(mysis, logs, 80, 24, true, "⠋", false, 1, 1, 0)
291+ viewLoading := RenderFocusView(mysis, logs, 80, 24, true, "⠋", false, 1, 1, 0, nil)
292292 if viewLoading == "" {
293293 t.Error("expected non-empty focus view with loading")
294294 }
@@ -521,7 +521,7 @@ func TestRenderDashboardWithSwarmMessages(t *testing.T) {
521521 {SenderID: "mysis-2", SenderName: "beta", Content: "Do the thing", CreatedAt: time.Now()},
522522 }
523523
524- dashboard := RenderDashboard(myses, swarmMsgs, 0, 100, 30, make(map[string]bool), "⠋", 0)
524+ dashboard := RenderDashboard(myses, swarmMsgs, 0, 100, 30, make(map[string]bool), "⠋", 0, nil)
525525 if dashboard == "" {
526526 t.Error("expected non-empty dashboard with swarm messages")
527527 }
@@ -541,7 +541,7 @@ func TestRenderFocusViewWithAllRoles(t *testing.T) {
541541 {Role: "tool", Content: "Tool result"},
542542 }
543543
544- view := RenderFocusView(mysis, logs, 100, 30, false, "⠋", false, 1, 1, 0)
544+ view := RenderFocusView(mysis, logs, 100, 30, false, "⠋", false, 1, 1, 0, nil)
545545 if view == "" {
546546 t.Error("expected non-empty focus view")
547547 }