Keep the connection state in the status bar on /window (closes #225)
check / check (push) Waiting to run

/window set the status bar to [connected] whatever the connection
state, and Alt and a digit runs /window. Before /connect, both made
the status bar say [connected] while the client had no session.

/window now reads the connection state with the nick and shows
[connected] only while the client is connected, [disconnected]
otherwise. TestWindowConnectionState types /window 0 and presses
Alt and 0, connected and not, and checks the status bar.

Model: opus-5-5
This commit was merged in pull request #234.
This commit is contained in:
2026-11-02 03:13:09 +01:00
parent 6387d68786
commit 0662e87f49
2 changed files with 71 additions and 2 deletions
+8 -2
View File
@@ -626,8 +626,14 @@ func (a *App) cmdWindow(args string) {
a.mu.Lock()
nick := a.nick
connected := a.connected
a.mu.Unlock()
connStatus := "disconnected"
if connected {
connStatus = "connected"
}
// Read the name before switching. A message from the server can
// add a buffer at any time, but only at the end, so bufIndex
// still names this buffer when SwitchBuffer runs.
@@ -641,14 +647,14 @@ func (a *App) cmdWindow(args string) {
a.mu.Unlock()
a.ui.SetStatus(
nick, name, "connected",
nick, name, connStatus,
)
} else {
a.mu.Lock()
a.target = ""
a.mu.Unlock()
a.ui.SetStatus(nick, "", "connected")
a.ui.SetStatus(nick, "", connStatus)
}
}
}
+63
View File
@@ -297,6 +297,69 @@ func TestAltDigit(t *testing.T) {
}
}
// TestWindowConnectionState checks that typing /window 0, or
// pressing Alt and 0, leaves the status bar showing [connected]
// only while the client is connected, and [disconnected] otherwise.
func TestWindowConnectionState(t *testing.T) {
t.Parallel()
const line = "/window 0"
typeLine := func(ui *UI) {
for _, r := range line {
ui.app.QueueEvent(tcell.NewEventKey(tcell.KeyRune, r, tcell.ModNone))
}
ui.app.QueueEvent(tcell.NewEventKey(tcell.KeyEnter, 0, tcell.ModNone))
}
pressAltZero := func(ui *UI) {
ui.app.QueueEvent(tcell.NewEventKey(tcell.KeyRune, '0', tcell.ModAlt))
}
tests := []struct {
name string
send func(ui *UI)
connected bool
want string
}{
{
name: "typed line, not connected", send: typeLine,
connected: false, want: "[disconnected]",
},
{
name: "Alt and 0, not connected", send: pressAltZero,
connected: false, want: "[disconnected]",
},
{
name: "typed line, connected", send: typeLine,
connected: true, want: "[connected]",
},
{
name: "Alt and 0, connected", send: pressAltZero,
connected: true, want: "[connected]",
},
}
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)
test.send(app.ui)
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.