From 2b1a49e59bd2f8549b044e49dda1118dacf1953d Mon Sep 17 00:00:00 2001 From: clawbot <35+clawbot@noreply.example.org> Date: Mon, 2 Nov 2026 06:03:53 +0100 Subject: [PATCH] Redraw the status bar when a line arrives in another window (closes #232) A line that arrives in a window that is not shown is counted as unread, but refreshStatusBar did nothing, so the window joined the status bar's unread list only at the next SetStatus. UI now keeps the nick, target and connection state last passed to SetStatus, and refreshStatusBar redraws the status bar with them. Model: opus-5-5 --- internal/cli/app_internal_test.go | 25 +++++++++++++++++++++++++ internal/cli/ui.go | 16 ++++++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/internal/cli/app_internal_test.go b/internal/cli/app_internal_test.go index 0e3203f..679e67e 100644 --- a/internal/cli/app_internal_test.go +++ b/internal/cli/app_internal_test.go @@ -752,6 +752,31 @@ func TestStatusBar(t *testing.T) { } } +// TestUnreadLine checks that a line added to a window that is not +// shown puts that window in the status bar's unread list at once, +// and that the status bar keeps the nick, target and connection +// state last set. +func TestUnreadLine(t *testing.T) { + t.Parallel() + + ui := NewUI() + runUI(t, ui) + + // Window 1, the one shown, is the channel's. The line goes to + // window 2 after SetStatus, so only AddLine can show it in the + // status bar. + ui.SwitchToBuffer(testChannel) + ui.SetStatus(testNick, testChannel, "connected") + ui.AddLine(testOtherNick, testText) + + const want = " [connected] erin [1:#chan] #chan [Act: 2:bob(1)]" + + got := statusBarText(ui) + if got != want { + t.Fatalf("status bar is %q, want %q", got, want) + } +} + // TestOwnEventFromOtherClient checks that a message, notice, // join or part that the user's session makes from another // client shows as one line in the buffer it belongs to. diff --git a/internal/cli/ui.go b/internal/cli/ui.go index f702a8d..6f229df 100644 --- a/internal/cli/ui.go +++ b/internal/cli/ui.go @@ -30,6 +30,12 @@ type UI struct { buffers []*Buffer currentBuffer int + // The nick, target and connection state last passed to + // SetStatus. + nick string + target string + connStatus string + onInput func(string) // inputDone is closed once the line last passed to onInput // has been handled. Only callOnInput, on the event loop, uses @@ -179,7 +185,11 @@ func (ui *UI) SetStatus( nick, target, connStatus string, ) { ui.app.QueueUpdateDraw(func() { - ui.renderStatusBar(nick, target, connStatus) + ui.nick = nick + ui.target = target + ui.connStatus = connStatus + + ui.refreshStatusBar() }) } @@ -300,8 +310,10 @@ func (ui *UI) callOnInput(text string) { }() } +// refreshStatusBar redraws the status bar with the nick, target +// and connection state last passed to SetStatus. func (ui *UI) refreshStatusBar() { - // Placeholder; full refresh needs nick/target context. + ui.renderStatusBar(ui.nick, ui.target, ui.connStatus) } func (ui *UI) renderStatusBar(