From f01a181455394bcf38db616ec9ef211572f5974c Mon Sep 17 00:00:00 2001 From: "nekomimi.pet" Date: Wed, 21 Oct 2026 21:04:55 -0400 Subject: [PATCH] tui: a focus report before any session is open reads nothing instead of panicking on the chat's missing client --- cli/internal/tui/chat_focus.go | 5 +++-- cli/internal/tui/chat_focus_test.go | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/cli/internal/tui/chat_focus.go b/cli/internal/tui/chat_focus.go index 9509ca9c..1635a226 100644 --- a/cli/internal/tui/chat_focus.go +++ b/cli/internal/tui/chat_focus.go @@ -27,10 +27,11 @@ func (m *ChatModel) statusPollCmd() tea.Cmd { } // focus follows the terminal's focus: losing it stops the face, and regaining -// it reads status at once and lets the face move again. +// it reads status at once and lets the face move again. Before any session is +// open the app holds a zero chat with no client, and focus has nothing to read. func (m *ChatModel) focus(focused bool) tea.Cmd { m.blurred = !focused - if m.blurred { + if m.blurred || m.client == nil { return nil } return tea.Batch(m.startAnimation(), m.statusCmd()) diff --git a/cli/internal/tui/chat_focus_test.go b/cli/internal/tui/chat_focus_test.go index fdc103b4..8e704e3c 100644 --- a/cli/internal/tui/chat_focus_test.go +++ b/cli/internal/tui/chat_focus_test.go @@ -131,3 +131,16 @@ func TestOnlyTheNewestScheduledPollReadsStatus(t *testing.T) { t.Fatal("the newest poll did not read status") } } + +// A terminal reports focus as soon as the program starts, often while the +// session picker or the login screen is up and no chat has a client yet. +func TestFocusBeforeAnyChatReadsNothing(t *testing.T) { + var app AppModel + updated, cmd := app.Update(tea.FocusMsg{}) + if cmd != nil { + t.Fatalf("focus without a chat asked for %T", cmd()) + } + if _, cmd := updated.Update(tea.BlurMsg{}); cmd != nil { + t.Fatal("blur without a chat asked for a command") + } +} -- knotmirror 0.0.1