From 87d65552e3a9699fadf1ff13571a3d39065fb19b Mon Sep 17 00:00:00 2001 From: clawbot <35+clawbot@noreply.example.org> Date: Mon, 2 Nov 2026 04:42:48 +0000 Subject: [PATCH] Keep the connection state in the status bar on /query (closes #235) /query set the status bar to [connected] whatever the connection state. Before /connect, it made the status bar say [connected] while the client had no session. /query now reads the connection state with the nick, as /window does, and shows [connected] only while the client is connected, [disconnected] otherwise. TestQueryConnectionState types /query bob, connected and not, and checks the status bar. The two status texts are now test constants, because the linter asks for one once a third copy appears. Model: opus-5-5 --- internal/cli/app.go | 8 ++++- internal/cli/app_internal_test.go | 57 ++++++++++++++++++++++++++++--- 2 files changed, 59 insertions(+), 6 deletions(-) diff --git a/internal/cli/app.go b/internal/cli/app.go index 207048b..659c9e2 100644 --- a/internal/cli/app.go +++ b/internal/cli/app.go @@ -402,10 +402,16 @@ func (a *App) cmdQuery(nick string) { a.mu.Lock() a.target = nick myNick := a.nick + connected := a.connected a.mu.Unlock() + connStatus := "disconnected" + if connected { + connStatus = "connected" + } + a.ui.SwitchToBuffer(nick) - a.ui.SetStatus(myNick, nick, "connected") + a.ui.SetStatus(myNick, nick, connStatus) } func (a *App) cmdTopic(args string) { diff --git a/internal/cli/app_internal_test.go b/internal/cli/app_internal_test.go index 0e3203f..a941c1e 100644 --- a/internal/cli/app_internal_test.go +++ b/internal/cli/app_internal_test.go @@ -23,6 +23,13 @@ const ( testText = "hello" ) +// What the status bar shows while the client is connected, and +// while it is not. +const ( + statusConnected = "[connected]" + statusDisconnected = "[disconnected]" +) + // eventLoopTimeout is how long a test waits for a typed line to // be handled, for the welcome lines, for the UI to stop, for a poll // or for a poll loop to end, before it fails. @@ -326,19 +333,19 @@ func TestWindowConnectionState(t *testing.T) { }{ { name: "typed line, not connected", send: typeLine, - connected: false, want: "[disconnected]", + connected: false, want: statusDisconnected, }, { name: "Alt and 0, not connected", send: pressAltZero, - connected: false, want: "[disconnected]", + connected: false, want: statusDisconnected, }, { name: "typed line, connected", send: typeLine, - connected: true, want: "[connected]", + connected: true, want: statusConnected, }, { name: "Alt and 0, connected", send: pressAltZero, - connected: true, want: "[connected]", + connected: true, want: statusConnected, }, } @@ -361,6 +368,46 @@ func TestWindowConnectionState(t *testing.T) { } } +// TestQueryConnectionState checks that typing /query bob leaves the +// status bar showing [connected] only while the client is connected, +// and [disconnected] otherwise. +func TestQueryConnectionState(t *testing.T) { + t.Parallel() + + const line = "/query " + testOtherNick + + tests := []struct { + name string + connected bool + want string + }{ + {name: "not connected", connected: false, want: statusDisconnected}, + {name: "connected", connected: true, want: statusConnected}, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + t.Parallel() + + app := &App{ui: NewUI(), nick: testNick, connected: test.connected} + handled := handledLines(app) + runUI(t, app.ui) + + for _, r := range line { + app.ui.app.QueueEvent(tcell.NewEventKey(tcell.KeyRune, r, tcell.ModNone)) + } + + app.ui.app.QueueEvent(tcell.NewEventKey(tcell.KeyEnter, 0, tcell.ModNone)) + waitHandled(t, handled, line) + + status := statusBarText(app.ui) + if !strings.Contains(status, test.want) { + t.Fatalf("status bar is %q, want it to show %s", status, test.want) + } + }) + } +} + // TestEventLoopKeepsRunning sends Alt and 1, then a typed line and // Enter, to a running UI. It checks that both are handled, so the // event loop did not stop on either. @@ -682,7 +729,7 @@ func TestStartUp(t *testing.T) { // run sets the status bar before it adds the welcome lines. status := statusBarText(ui) - if !strings.Contains(status, "[disconnected]") { + if !strings.Contains(status, statusDisconnected) { t.Errorf("status bar is %q, want it to show [disconnected]", status) } }