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:
@@ -3,8 +3,8 @@ package app
|
||||
import (
|
||||
"strings"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
tea "charm.land/bubbletea/v2"
|
||||
"charm.land/lipgloss/v2"
|
||||
"github.com/correx/tui-go/internal/protocol"
|
||||
)
|
||||
|
||||
@@ -24,7 +24,7 @@ func (m *Model) proposeInitState() {
|
||||
|
||||
// --- key handling ---
|
||||
|
||||
func (m Model) handleProposeKey(k tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
func (m Model) handleProposeKey(k keyMsg) (tea.Model, tea.Cmd) {
|
||||
s := m.session(m.selectedID)
|
||||
if s == nil || s.Propose == nil {
|
||||
return m, nil
|
||||
@@ -34,15 +34,15 @@ func (m Model) handleProposeKey(k tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
n := len(s.Propose.Candidates) // index n == the custom slot
|
||||
switch k.Type {
|
||||
case tea.KeyEsc:
|
||||
case keyEsc:
|
||||
m.proposeDismissed = true
|
||||
case tea.KeyUp:
|
||||
case keyUp:
|
||||
m.proposeCursor = clampInt(m.proposeCursor-1, 0, n)
|
||||
case tea.KeyDown:
|
||||
case keyDown:
|
||||
m.proposeCursor = clampInt(m.proposeCursor+1, 0, n)
|
||||
case tea.KeyEnter, tea.KeySpace:
|
||||
case keyEnter, keySpace:
|
||||
return m.proposeSubmit()
|
||||
case tea.KeyRunes:
|
||||
case keyRunes:
|
||||
switch string(k.Runes) {
|
||||
case "k":
|
||||
m.proposeCursor = clampInt(m.proposeCursor-1, 0, n)
|
||||
@@ -56,17 +56,17 @@ func (m Model) handleProposeKey(k tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (m Model) handleProposeTyping(k tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
func (m Model) handleProposeTyping(k keyMsg) (tea.Model, tea.Cmd) {
|
||||
switch k.Type {
|
||||
case tea.KeyEsc:
|
||||
case keyEsc:
|
||||
m.proposeTyping = false
|
||||
case tea.KeyEnter:
|
||||
case keyEnter:
|
||||
return m.proposeSubmit() // commit the custom answer and send it as chat
|
||||
case tea.KeyBackspace:
|
||||
case keyBackspace:
|
||||
if len(m.proposeText) > 0 {
|
||||
m.proposeText = m.proposeText[:len(m.proposeText)-1]
|
||||
}
|
||||
case tea.KeyRunes, tea.KeySpace:
|
||||
case keyRunes, keySpace:
|
||||
m.proposeText += string(k.Runes)
|
||||
}
|
||||
return m, nil
|
||||
|
||||
Reference in New Issue
Block a user