mirror of
https://github.com/Twigpine/zero.git
synced 2026-11-10 17:57:54 -10:00
* Migrate TUI to Bubble Tea v2 Move the TUI stack to charm.land Bubble Tea, Bubbles, and Lip Gloss v2, including key, paste, mouse, and view handling changes for the v2 APIs. Add compatibility helpers for the new input event shapes and update TUI tests accordingly. Refresh related Go dependencies and make the PDF truncation fixture deterministic across poppler and pure-Go extraction. Tested: GOCACHE=/tmp/zero-go-cache GOMODCACHE=/tmp/zero-go-mod-cache go test ./internal/tui Tested: GOCACHE=/tmp/zero-go-cache GOMODCACHE=/tmp/zero-go-mod-cache go test ./internal/imageinput -count=1 -v Tested: GOCACHE=/tmp/zero-go-cache GOMODCACHE=/tmp/zero-go-mod-cache go test ./... * Address provider wizard OAuth review feedback Remove the unused mouseButton compatibility helper flagged by lint. Correlate provider wizard OAuth and device-code async results with the active provider and attempt id so stale results from abandoned attempts are ignored. Add regression coverage for stale browser OAuth and stale device-code results. Tested: GOCACHE=/tmp/zero-go-cache GOMODCACHE=/tmp/zero-go-mod-cache go test ./internal/tui -run 'ProviderWizard.*OAuth|ProviderWizard.*Device|ApplyProviderWizardOAuth|RenderCredentialStepShowsOAuth' -count=1 -v Tested: GOCACHE=/tmp/zero-go-cache GOMODCACHE=/tmp/zero-go-mod-cache go test ./internal/tui Tested: GOCACHE=/tmp/zero-go-cache GOMODCACHE=/tmp/zero-go-mod-cache go test ./... Tested: git diff --check * Smooth TUI mouse scrolling
86 lines
1.9 KiB
Go
86 lines
1.9 KiB
Go
package tui
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
tea "charm.land/bubbletea/v2"
|
|
)
|
|
|
|
func testKey(code rune) tea.KeyPressMsg {
|
|
text := ""
|
|
if code == tea.KeySpace {
|
|
text = " "
|
|
}
|
|
return tea.KeyPressMsg(tea.Key{Code: code, Text: text})
|
|
}
|
|
|
|
func testKeyText(text string) tea.KeyPressMsg {
|
|
runes := []rune(text)
|
|
code := tea.KeyExtended
|
|
if len(runes) == 1 {
|
|
code = runes[0]
|
|
}
|
|
return tea.KeyPressMsg(tea.Key{Code: code, Text: text})
|
|
}
|
|
|
|
func testKeyAlt(code rune) tea.KeyPressMsg {
|
|
return testKeyPressMod(code, tea.ModAlt)
|
|
}
|
|
|
|
func testKeyAltText(text string) tea.KeyPressMsg {
|
|
msg := testKeyText(text)
|
|
key := msg.Key()
|
|
key.Mod = tea.ModAlt
|
|
return tea.KeyPressMsg(key)
|
|
}
|
|
|
|
func testKeyCtrl(code rune) tea.KeyPressMsg {
|
|
return testKeyPressMod(code, tea.ModCtrl)
|
|
}
|
|
|
|
func testKeyShift(code rune) tea.KeyPressMsg {
|
|
return testKeyPressMod(code, tea.ModShift)
|
|
}
|
|
|
|
func testKeyPressMod(code rune, mod tea.KeyMod) tea.KeyPressMsg {
|
|
msg := testKey(code)
|
|
key := msg.Key()
|
|
key.Mod = mod
|
|
return tea.KeyPressMsg(key)
|
|
}
|
|
|
|
func testPaste(content string) tea.PasteMsg {
|
|
return tea.PasteMsg{Content: content}
|
|
}
|
|
|
|
func testMouseClick(button tea.MouseButton, x int, y int) tea.MouseClickMsg {
|
|
return tea.MouseClickMsg(tea.Mouse{Button: button, X: x, Y: y})
|
|
}
|
|
|
|
func testMouseWheel(button tea.MouseButton, x int, y int) tea.MouseWheelMsg {
|
|
return tea.MouseWheelMsg(tea.Mouse{Button: button, X: x, Y: y})
|
|
}
|
|
|
|
func testMouseMotion(button tea.MouseButton, x int, y int) tea.MouseMotionMsg {
|
|
return tea.MouseMotionMsg(tea.Mouse{Button: button, X: x, Y: y})
|
|
}
|
|
|
|
func testMouseRelease(button tea.MouseButton, x int, y int) tea.MouseReleaseMsg {
|
|
return tea.MouseReleaseMsg(tea.Mouse{Button: button, X: x, Y: y})
|
|
}
|
|
|
|
func viewString(view tea.View) string {
|
|
return view.Content
|
|
}
|
|
|
|
func renderContent(rendered any) string {
|
|
switch v := rendered.(type) {
|
|
case string:
|
|
return v
|
|
case tea.View:
|
|
return v.Content
|
|
default:
|
|
return fmt.Sprint(v)
|
|
}
|
|
}
|