tui: migrate Bubble Tea v1 → v2 (charm.land), enable Shift+Enter
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>
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/correx/tui-go/internal/protocol"
|
||||
"github.com/correx/tui-go/internal/ws"
|
||||
)
|
||||
@@ -47,8 +46,8 @@ func TestProposeEntersStateAndRenders(t *testing.T) {
|
||||
func TestProposePickLaunchesChosenWorkflow(t *testing.T) {
|
||||
m, client := proposeModel()
|
||||
// move cursor to the second candidate (role_pipeline) and launch it
|
||||
m = applyProposeKey(m, tea.KeyMsg{Type: tea.KeyDown})
|
||||
m = applyProposeKey(m, tea.KeyMsg{Type: tea.KeyEnter})
|
||||
m = applyProposeKey(m, keyMsg{Type: keyDown})
|
||||
m = applyProposeKey(m, keyMsg{Type: keyEnter})
|
||||
|
||||
if s := m.session("s1"); s == nil || s.Propose != nil {
|
||||
t.Fatalf("expected proposal cleared after launch")
|
||||
@@ -67,7 +66,7 @@ func TestProposePickLaunchesChosenWorkflow(t *testing.T) {
|
||||
|
||||
func TestProposeFirstCandidateIsDefault(t *testing.T) {
|
||||
m, client := proposeModel()
|
||||
m = applyProposeKey(m, tea.KeyMsg{Type: tea.KeyEnter}) // no nav → first candidate
|
||||
m = applyProposeKey(m, keyMsg{Type: keyEnter}) // no nav → first candidate
|
||||
wf, _ := decodeStart(t, client)
|
||||
if wf != "research" {
|
||||
t.Fatalf("expected first candidate launched by default, got %q", wf)
|
||||
@@ -76,14 +75,14 @@ func TestProposeFirstCandidateIsDefault(t *testing.T) {
|
||||
|
||||
func TestProposeCustomAnswerContinuesChat(t *testing.T) {
|
||||
m, client := proposeModel()
|
||||
m = applyProposeKey(m, tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("e")})
|
||||
m = applyProposeKey(m, keyMsg{Type: keyRunes, Runes: []rune("e")})
|
||||
if !m.proposeTyping {
|
||||
t.Fatalf("expected typing mode after 'e'")
|
||||
}
|
||||
for _, r := range "do it manually" {
|
||||
m = applyProposeKey(m, tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{r}})
|
||||
m = applyProposeKey(m, keyMsg{Type: keyRunes, Runes: []rune{r}})
|
||||
}
|
||||
m = applyProposeKey(m, tea.KeyMsg{Type: tea.KeyEnter})
|
||||
m = applyProposeKey(m, keyMsg{Type: keyEnter})
|
||||
|
||||
if s := m.session("s1"); s == nil || s.Propose != nil {
|
||||
t.Fatalf("expected proposal cleared after custom answer")
|
||||
@@ -109,7 +108,7 @@ func TestProposeCustomAnswerContinuesChat(t *testing.T) {
|
||||
|
||||
func TestProposeEscDismisses(t *testing.T) {
|
||||
m, _ := proposeModel()
|
||||
m = applyProposeKey(m, tea.KeyMsg{Type: tea.KeyEsc})
|
||||
m = applyProposeKey(m, keyMsg{Type: keyEsc})
|
||||
if m.displayState() != StateInSession {
|
||||
t.Fatalf("expected StateInSession after esc, got %v", m.displayState())
|
||||
}
|
||||
@@ -118,7 +117,7 @@ func TestProposeEscDismisses(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func applyProposeKey(m Model, k tea.KeyMsg) Model {
|
||||
func applyProposeKey(m Model, k keyMsg) Model {
|
||||
updated, _ := m.handleProposeKey(k)
|
||||
return updated.(Model)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user