Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/guides/tui.md
Original file line number Diff line number Diff line change
Expand Up @@ -2941,6 +2941,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)
Expand Down
5 changes: 5 additions & 0 deletions internal/tui/chatrender.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down
44 changes: 44 additions & 0 deletions internal/tui/chatview.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -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
}
if note, ok := optionKeyNote(msg.Text); ok {
// Typed all the same: it may be meant (#1061).
v.note, v.noteBad = note, false
Expand Down Expand Up @@ -2498,3 +2511,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
}
42 changes: 42 additions & 0 deletions internal/tui/endedchat_test.go
Original file line number Diff line number Diff line change
@@ -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())
}
}