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:
@@ -7,8 +7,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
tea "charm.land/bubbletea/v2"
|
||||
"charm.land/lipgloss/v2"
|
||||
)
|
||||
|
||||
// SessionSummary is one recent session from GET /sessions. Mirrors the server's
|
||||
@@ -107,19 +107,19 @@ func (m *Model) openSessions() tea.Cmd {
|
||||
|
||||
// handleSessionsKey owns every key while the session browser is open: navigate
|
||||
// the roster, esc closes, enter resumes the selected session.
|
||||
func (m Model) handleSessionsKey(k tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
func (m Model) handleSessionsKey(k keyMsg) (tea.Model, tea.Cmd) {
|
||||
switch {
|
||||
case k.Type == tea.KeyEsc || runeIs(k, "R"):
|
||||
case k.Type == keyEsc || runeIs(k, "R"):
|
||||
m.overlay = OverlayNone
|
||||
case k.Type == tea.KeyUp || runeIs(k, "k"):
|
||||
case k.Type == keyUp || runeIs(k, "k"):
|
||||
if m.sessionListIndex > 0 {
|
||||
m.sessionListIndex--
|
||||
}
|
||||
case k.Type == tea.KeyDown || runeIs(k, "j"):
|
||||
case k.Type == keyDown || runeIs(k, "j"):
|
||||
if m.sessionListIndex < len(m.sessionList)-1 {
|
||||
m.sessionListIndex++
|
||||
}
|
||||
case k.Type == tea.KeyEnter:
|
||||
case k.Type == keyEnter:
|
||||
if m.sessionListIndex >= 0 && m.sessionListIndex < len(m.sessionList) {
|
||||
return m.openSelectedSession()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user