From 0721262e2a64549f0760b48f6b293b9ea8a95439 Mon Sep 17 00:00:00 2001 From: lezli01 Date: Mon, 23 Nov 2026 14:11:48 +0100 Subject: [PATCH] fix(tui): give an ended chat no composer A closed, archived or handed-off chat now draws, where the composer was, a line saying it takes no more turns and the keys that still work with it (export, copy, search, Markdown). Typed or pasted text goes nowhere and says why, rather than filling a draft that could never be sent and was lost on leaving. Closes #1054 --- docs/guides/tui.md | 6 +++++ internal/tui/chatrender.go | 5 ++++ internal/tui/chatview.go | 44 ++++++++++++++++++++++++++++++++++ internal/tui/endedchat_test.go | 42 ++++++++++++++++++++++++++++++++ 4 files changed, 97 insertions(+) create mode 100644 internal/tui/endedchat_test.go diff --git a/docs/guides/tui.md b/docs/guides/tui.md index c9413853..b329038c 100644 --- a/docs/guides/tui.md +++ b/docs/guides/tui.md @@ -2919,6 +2919,12 @@ tall and grows with the draft, up to a third of the screen and at most ten rows; a draft taller still scrolls inside it, and the box's title says how many lines are out of view (`+N lines`). The conversation shrinks to pay for the rows. +An ended chat — closed, archived or handed off — takes no more turns, so it has +no composer: in its place a line says so and names what still works with it, +`alt+e` export, `ctrl+y` copy, `ctrl+f` search and `alt+v` Markdown. A key +typed there goes nowhere and says why, rather than filling a draft that could +never be sent. + ![The chat workspace at `quiet`: the second turn's prompt as a right-aligned card, the answer rendered below it with its fenced block, and the titled `message` composer under them](../assets/tui-chat.png) diff --git a/internal/tui/chatrender.go b/internal/tui/chatrender.go index 0451046b..28895216 100644 --- a/internal/tui/chatrender.go +++ b/internal/tui/chatrender.go @@ -783,6 +783,11 @@ func (v *chatView) footerLines(width, height int) []string { // many columns the composer actually has, and a composer sized from the // whole terminal has its rows cut by the Truncate pass above. Two of them // go to the border, which is what shell.go's frame draws in. + if v.ended() { + // No composer where nothing can be sent (#1054): what still works, + // in its place. + return capChatFooter(out, endedChatLine(v.chat, width), height-chatHeadLines-1) + } v.composer.SetWidth(chatComposerWidth(width)) title := "message" if chip := chatSettingsChip(v.chat); chip != "" { diff --git a/internal/tui/chatview.go b/internal/tui/chatview.go index d77190e8..eb40505c 100644 --- a/internal/tui/chatview.go +++ b/internal/tui/chatview.go @@ -11,6 +11,7 @@ import ( "charm.land/bubbles/v2/textarea" "charm.land/bubbles/v2/viewport" tea "charm.land/bubbletea/v2" + "github.com/charmbracelet/x/ansi" "github.com/lezli01/vincent/internal/apiclient" "github.com/lezli01/vincent/internal/chatstate" @@ -408,6 +409,10 @@ func (v *chatView) paste(text string) tea.Cmd { // pasteText is a paste into the composer as text. func (v *chatView) pasteText(text string) tea.Cmd { + if v.ended() { + v.note, v.noteBad = endedChatNote(v.chat), false + return nil + } var cmd tea.Cmd before := v.composer.Value() v.composer, cmd = v.composer.Update(tea.PasteMsg{Content: text}) @@ -1540,6 +1545,14 @@ func (v *chatView) updateKey(msg tea.KeyPressMsg) (panel, tea.Cmd) { } return v, openChatExportCmd(v.chat.ID, v.chat.Title) } + if v.ended() { + // No text where nothing can be sent (#1054): an ended chat stores + // no draft, so what was typed would be lost on leaving. + if msg.Text != "" { + v.note, v.noteBad = endedChatNote(v.chat), false + } + return v, nil + } var cmd tea.Cmd before := v.composer.Value() v.composer, cmd = v.composer.Update(msg) @@ -2494,3 +2507,34 @@ func (v *chatView) resolveDoc(seq int64) (string, bool) { // notesClipboard marks the chat as saying a copy's outcome itself, on its // note line, so the root's status line stands down. func (v *chatView) notesClipboard() {} + +// ended is whether the chat is terminal: closed, archived or handed off. It +// takes no more turns, so it has no composer (#1054). +func (v *chatView) ended() bool { + return v.chat != nil && chatstate.Terminal(chatstate.State(v.chat.State)) +} + +// endedChatNote says an ended chat takes no text. +func endedChatNote(chat *apiclient.Chat) string { + return sendRefusal(chatstate.State(chat.State)) + " — nothing typed here can be sent" +} + +// endedChatLine is what an ended chat draws where the composer was: that it +// takes no more turns, and the keys that still do something with it. +func endedChatLine(chat *apiclient.Chat, width int) []string { + var keys []string + add := func(key, label string) { + if key != "" { + keys = append(keys, styleKey.Render(key)+" "+label) + } + } + add(opKey(keymap.ExportChat), "export") + add(copyPickKey, "copy") + add(chatSearchKey, "search") + add(opKey(keymap.ChatMarkdown), "Markdown") + out := []string{" " + styleDim.Render(ansi.Truncate("this chat is "+chatStateLabel(chat.State)+" and takes no more turns", max(width-1, 1), "…"))} + if len(keys) > 0 { + out = append(out, " "+ansi.Truncate(strings.Join(keys, styleDim.Render(" · ")), max(width-1, 1), "…")) + } + return out +} diff --git a/internal/tui/endedchat_test.go b/internal/tui/endedchat_test.go new file mode 100644 index 00000000..8e5102f9 --- /dev/null +++ b/internal/tui/endedchat_test.go @@ -0,0 +1,42 @@ +package tui + +import ( + "strings" + "testing" + + tea "charm.land/bubbletea/v2" + "github.com/charmbracelet/x/ansi" +) + +// #1054: an ended chat draws what still works where the composer was, and +// takes no text, typed or pasted. +func TestEndedChatHasNoComposer(t *testing.T) { + v := chatViewFixture() + v.chat.State = "closed" + foot := ansi.Strip(strings.Join(v.footerLines(100, 30), "\n")) + for _, want := range []string{"this chat is closed and takes no more turns", "ctrl+y copy", "ctrl+f search"} { + if !strings.Contains(foot, want) { + t.Errorf("ended chat's footer misses %q:\n%s", want, foot) + } + } + if strings.Contains(foot, "message") { + t.Errorf("ended chat still draws the composer:\n%s", foot) + } + v.updateKey(tea.KeyPressMsg{Code: 'h', Text: "h"}) + if v.composer.Value() != "" { + t.Fatalf("an ended chat took typed text: %q", v.composer.Value()) + } + if !strings.Contains(v.note, "nothing typed here can be sent") { + t.Errorf("typing said %q", v.note) + } + v.pasteText("pasted") + if v.composer.Value() != "" { + t.Fatalf("an ended chat took a paste: %q", v.composer.Value()) + } + + live := chatViewFixture() + live.updateKey(tea.KeyPressMsg{Code: 'h', Text: "h"}) + if live.composer.Value() != "h" { + t.Fatalf("a live chat lost typed text: %q", live.composer.Value()) + } +}