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"
|
||||
)
|
||||
@@ -40,12 +39,12 @@ func apprReq(reqID, tier string) protocol.ServerMessage {
|
||||
}
|
||||
|
||||
// applyKey drives a key through the production handleKey entry and returns the model.
|
||||
func applyKey(m Model, k tea.KeyMsg) Model {
|
||||
func applyKey(m Model, k keyMsg) Model {
|
||||
updated, _ := m.handleKey(k)
|
||||
return updated.(Model)
|
||||
}
|
||||
|
||||
func runeKey(r rune) tea.KeyMsg { return tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{r}} }
|
||||
func runeKey(r rune) keyMsg { return keyMsg{Type: keyRunes, Runes: []rune{r}} }
|
||||
|
||||
// decodeApproval pulls the single ApprovalResponse frame off the client and returns
|
||||
// its request id + decision. Fails if there isn't exactly one decision frame.
|
||||
@@ -146,7 +145,7 @@ func TestApprovalHighTierArmCancelledByNavKey(t *testing.T) {
|
||||
// no decision may be emitted.
|
||||
m, client := approvalModel(apprReq("req-1", "T3"), apprReq("req-2", "T3"))
|
||||
m = applyKey(m, runeKey('y')) // arm req-1
|
||||
m = applyKey(m, tea.KeyMsg{Type: tea.KeyDown})
|
||||
m = applyKey(m, keyMsg{Type: keyDown})
|
||||
if m.approvalArmed {
|
||||
t.Fatalf("nav key should disarm")
|
||||
}
|
||||
@@ -168,7 +167,7 @@ func TestApprovalQueueNavigatesAndCounts(t *testing.T) {
|
||||
t.Fatalf("band should show queue count 1/3:\n%s", out)
|
||||
}
|
||||
// ↓ advances the selection; Pending follows the cursor.
|
||||
m = applyKey(m, tea.KeyMsg{Type: tea.KeyDown})
|
||||
m = applyKey(m, keyMsg{Type: keyDown})
|
||||
s = m.session("s1")
|
||||
if s.PendingIdx != 1 || s.Pending.RequestID != "req-2" {
|
||||
t.Fatalf("↓ should select req-2, got idx=%d id=%s", s.PendingIdx, s.Pending.RequestID)
|
||||
@@ -178,7 +177,7 @@ func TestApprovalQueueNavigatesAndCounts(t *testing.T) {
|
||||
t.Fatalf("band should show 2/3 after ↓:\n%s", out)
|
||||
}
|
||||
// ↑ wraps back.
|
||||
m = applyKey(m, tea.KeyMsg{Type: tea.KeyUp})
|
||||
m = applyKey(m, keyMsg{Type: keyUp})
|
||||
if m.session("s1").PendingIdx != 0 {
|
||||
t.Fatalf("↑ should return to index 0")
|
||||
}
|
||||
@@ -238,7 +237,7 @@ func TestApprovalRejectAndSteerRoute(t *testing.T) {
|
||||
for _, r := range "use sudo" {
|
||||
m2 = applyKey(m2, runeKey(r))
|
||||
}
|
||||
m2 = applyKey(m2, tea.KeyMsg{Type: tea.KeyEnter})
|
||||
m2 = applyKey(m2, keyMsg{Type: keyEnter})
|
||||
frames := client2.Drain()
|
||||
var note string
|
||||
for _, f := range frames {
|
||||
|
||||
Reference in New Issue
Block a user