d247b19608
Move the Go TUI from github.com/charmbracelet/{bubbletea,lipgloss} to the v2
ecosystem at charm.land/{bubbletea,lipgloss}/v2 (Go 1.25). v2's kitty keyboard
disambiguation is on by default, so Shift+Enter now reliably inserts a newline
in the composer (Ctrl+J / Alt+Enter kept as fallbacks for non-kitty terminals).
Approach: rather than rewrite ~190 key-match sites to v2's (Code, Mod) idiom, a
small shim (internal/app/key.go) converts a v2 KeyPressMsg into the v1-shaped
keyMsg the handlers already expect, at the single Update boundary. The rest is
mechanical:
- key constants tea.Key* → shim consts; tea.KeyMsg → keyMsg.
- lipgloss.Color is now a func returning color.Color, not a type → fields/params
retyped to image/color.Color (theme/diff/overlays/view).
- v2 View() returns tea.View: render() builds the string, View() wraps it and
carries AltScreen (alt-screen is a per-frame View field now, not a program opt).
- WithWhitespaceBackground/Foreground → WithWhitespaceStyle(Style).
- preview: drop lipgloss.SetColorProfile (v2 renders truecolor by default).
Build, vet, gofmt, and the full test suite are green; preview renders truecolor
across kinds.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
105 lines
3.1 KiB
Go
105 lines
3.1 KiB
Go
package app
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/correx/tui-go/internal/protocol"
|
|
"github.com/correx/tui-go/internal/ws"
|
|
)
|
|
|
|
func clarModel() Model {
|
|
m := NewModel(ws.New("", 0)) // unconnected; Send just buffers
|
|
m.width, m.height = 120, 40
|
|
m.theme = NewTheme(SoftBlue)
|
|
m.selectedID = "s1"
|
|
m.sessionEntered = true
|
|
m.applyServer(protocol.ServerMessage{
|
|
Type: protocol.TypeClarification,
|
|
SessionID: "s1",
|
|
RequestID: "req-1",
|
|
StageID: "analyst",
|
|
Questions: []protocol.ClarificationQuestionDto{
|
|
{ID: "stack", Prompt: "Which stack?", Options: []string{"React", "Vue"}, Header: "Stack"},
|
|
},
|
|
})
|
|
return m
|
|
}
|
|
|
|
func TestClarificationEntersStateAndRenders(t *testing.T) {
|
|
m := clarModel()
|
|
if m.displayState() != StateClarification {
|
|
t.Fatalf("want StateClarification, got %v", m.displayState())
|
|
}
|
|
out := m.clarificationModal()
|
|
for _, want := range []string{"clarifying questions", "Which stack?", "React", "Vue", "Stack", "custom"} {
|
|
if !strings.Contains(out, want) {
|
|
t.Fatalf("modal missing %q:\n%s", want, out)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestClarificationSelectAndSubmit(t *testing.T) {
|
|
m := clarModel()
|
|
// move the option cursor to "Vue" (index 1) and select it
|
|
m = applyClarKey(m, keyMsg{Type: keyRight})
|
|
m = applyClarKey(m, keyMsg{Type: keySpace})
|
|
if !m.clarChosenAt(0, 1) {
|
|
t.Fatalf("expected option 1 chosen, chosen=%v", m.clarChosen)
|
|
}
|
|
// submit
|
|
m = applyClarKey(m, keyMsg{Type: keyEnter})
|
|
if s := m.session("s1"); s == nil || s.Clar != nil {
|
|
t.Fatalf("expected clarification cleared after submit")
|
|
}
|
|
if m.displayState() != StateInSession {
|
|
t.Fatalf("want StateInSession after submit, got %v", m.displayState())
|
|
}
|
|
}
|
|
|
|
func TestClarificationSubmitGuardWaitsForAllAnswers(t *testing.T) {
|
|
m := clarModel()
|
|
m.applyServer(protocol.ServerMessage{
|
|
Type: protocol.TypeClarification, SessionID: "s1", RequestID: "req-2", StageID: "analyst",
|
|
Questions: []protocol.ClarificationQuestionDto{
|
|
{ID: "a", Prompt: "Q A?", Options: []string{"x"}},
|
|
{ID: "b", Prompt: "Q B?", Options: []string{"y"}},
|
|
},
|
|
})
|
|
// answer only the first question, then attempt submit
|
|
m = applyClarKey(m, keyMsg{Type: keySpace})
|
|
m = applyClarKey(m, keyMsg{Type: keyEnter})
|
|
if s := m.session("s1"); s == nil || s.Clar == nil {
|
|
t.Fatalf("expected clarification to remain with partial answers")
|
|
}
|
|
if m.clarFocus != 1 {
|
|
t.Fatalf("expected focus nudged to first unanswered (1), got %d", m.clarFocus)
|
|
}
|
|
}
|
|
|
|
func TestClarificationCustomTextAnswer(t *testing.T) {
|
|
m := clarModel()
|
|
m = applyClarKey(m, keyMsg{Type: keyRunes, Runes: []rune("e")})
|
|
if !m.clarTyping {
|
|
t.Fatalf("expected typing mode after 'e'")
|
|
}
|
|
for _, r := range "Solid" {
|
|
m = applyClarKey(m, keyMsg{Type: keyRunes, Runes: []rune{r}})
|
|
}
|
|
m = applyClarKey(m, keyMsg{Type: keyEnter})
|
|
if m.clarTyping {
|
|
t.Fatalf("expected typing committed")
|
|
}
|
|
if m.clarTextAt(0) != "Solid" {
|
|
t.Fatalf("want custom text 'Solid', got %q", m.clarTextAt(0))
|
|
}
|
|
if !m.clarAnswered(0, m.session("s1").Clar.Questions[0]) {
|
|
t.Fatalf("expected question answered via custom text")
|
|
}
|
|
}
|
|
|
|
func applyClarKey(m Model, k keyMsg) Model {
|
|
updated, _ := m.handleClarificationKey(k)
|
|
return updated.(Model)
|
|
}
|