From 63b11ee11fbf66cfe526a4e0894ec5104df8a012 Mon Sep 17 00:00:00 2001 From: dawn <90008@klbr.net> Date: Sat, 26 Sep 2026 17:31:05 +0300 Subject: [PATCH] move the tui to bubbletea, bubbles, lipgloss and glamour v2 the port came in on bubbletea v1.3.4 and bubbles v0.20. v2's renderer diffs cells instead of lines, and the view declares terminal state, so the mouse mode lives in AppModel.View instead of being toggled by commands. v2's reader keeps split mouse reports whole, so the filter that repaired them is gone. every input comes from newTextInput with a still cursor, including the agents view and the mcp and webhook forms, which used to blink. those forms now size their fields, since a textinput without a width shows only the first rune of its placeholder, and pastes reach them as PasteMsg. --- cli/cmd/albedo/main.go | 6 +- cli/go.mod | 37 ++--- cli/go.sum | 90 +++++------ cli/internal/tui/agents_view.go | 22 +-- cli/internal/tui/agents_view_test.go | 16 +- cli/internal/tui/app.go | 39 ++--- cli/internal/tui/capability_pages.go | 99 ++++++------ cli/internal/tui/capability_pages_test.go | 4 +- cli/internal/tui/chat.go | 186 +++++++++++----------- cli/internal/tui/chat_navigation_test.go | 16 +- cli/internal/tui/clipboard.go | 2 +- cli/internal/tui/commands.go | 16 +- cli/internal/tui/context_inspector.go | 28 ++-- cli/internal/tui/effort_selector.go | 2 +- cli/internal/tui/effort_selector_test.go | 16 +- cli/internal/tui/effort_test.go | 6 +- cli/internal/tui/extension_picker.go | 49 +++--- cli/internal/tui/extension_scope_test.go | 16 +- cli/internal/tui/login.go | 30 ++-- cli/internal/tui/login_test.go | 20 +-- cli/internal/tui/markdown.go | 6 +- cli/internal/tui/mcp_form.go | 57 ++++--- cli/internal/tui/mcp_form_test.go | 12 +- cli/internal/tui/memory_profile_test.go | 2 +- cli/internal/tui/model_picker.go | 38 ++--- cli/internal/tui/model_picker_test.go | 34 ++-- cli/internal/tui/mouse_repair.go | 96 ----------- cli/internal/tui/mouse_repair_test.go | 111 ------------- cli/internal/tui/notice_clear_test.go | 4 +- cli/internal/tui/older_history_test.go | 6 +- cli/internal/tui/page_secret_test.go | 6 +- cli/internal/tui/page_view.go | 36 ++--- cli/internal/tui/pending_test.go | 8 +- cli/internal/tui/picker.go | 22 ++- cli/internal/tui/prompt_multiline_test.go | 48 +++--- cli/internal/tui/scroll_perf_test.go | 49 +++--- cli/internal/tui/session_viewer.go | 28 ++-- cli/internal/tui/session_viewer_test.go | 28 ++-- cli/internal/tui/session_viewer_view.go | 2 +- cli/internal/tui/theme.go | 41 +++-- cli/internal/tui/transcript.go | 2 +- cli/internal/tui/tree_picker.go | 20 +-- cli/internal/tui/webhooks_page.go | 140 ++++++++-------- cli/internal/tui/webhooks_page_test.go | 20 +-- 44 files changed, 658 insertions(+), 858 deletions(-) delete mode 100644 cli/internal/tui/mouse_repair.go delete mode 100644 cli/internal/tui/mouse_repair_test.go diff --git a/cli/cmd/albedo/main.go b/cli/cmd/albedo/main.go index 20c750774..2d37889b6 100644 --- a/cli/cmd/albedo/main.go +++ b/cli/cmd/albedo/main.go @@ -15,7 +15,7 @@ import ( "strings" "time" - tea "github.com/charmbracelet/bubbletea" + tea "charm.land/bubbletea/v2" "github.com/charmbracelet/x/ansi" "github.com/mattn/go-isatty" ) @@ -224,7 +224,7 @@ func open(id, workspace string, fresh bool) error { appModel.BrowserOpener = config.OpenBrowser appModel.Login.BrowserOpener = config.OpenBrowser } - p := tea.NewProgram(appModel, tea.WithFPS(120), tea.WithFilter(tui.RepairSplitMouse())) + p := tea.NewProgram(appModel, tea.WithFPS(120)) _, err = p.Run() return err } @@ -425,7 +425,7 @@ func run(args []string) error { appModel.Login.BrowserOpener = config.OpenBrowser } } - p := tea.NewProgram(appModel, tea.WithFPS(120), tea.WithFilter(tui.RepairSplitMouse())) + p := tea.NewProgram(appModel, tea.WithFPS(120)) _, err = p.Run() return err diff --git a/cli/go.mod b/cli/go.mod index bc6c9f3c9..644e3fccc 100644 --- a/cli/go.mod +++ b/cli/go.mod @@ -3,42 +3,39 @@ module albedo/cli go 1.26.7 require ( + charm.land/bubbles/v2 v2.2.1 + charm.land/bubbletea/v2 v2.0.10 + charm.land/glamour/v2 v2.0.1 + charm.land/lipgloss/v2 v2.0.6 github.com/alecthomas/chroma/v2 v2.20.0 github.com/atotto/clipboard v0.1.4 - github.com/charmbracelet/bubbles v0.20.0 - github.com/charmbracelet/bubbletea v1.3.4 - github.com/charmbracelet/glamour v1.0.0 - github.com/charmbracelet/lipgloss v1.1.1-0.20250404203927-76690c660834 - github.com/charmbracelet/x/ansi v0.10.2 - github.com/charmbracelet/x/term v0.2.1 + github.com/charmbracelet/x/ansi v0.11.8 + github.com/charmbracelet/x/term v0.2.2 github.com/mattn/go-isatty v0.0.20 - github.com/muesli/termenv v0.16.0 github.com/rivo/uniseg v0.4.7 github.com/sahilm/fuzzy v0.1.3 - golang.org/x/sys v0.37.0 + golang.org/x/sys v0.47.0 golang.org/x/text v0.30.0 ) require ( - github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect github.com/aymerick/douceur v0.2.0 // indirect - github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect - github.com/charmbracelet/x/cellbuf v0.0.13 // indirect + github.com/charmbracelet/colorprofile v0.4.3 // indirect + github.com/charmbracelet/ultraviolet v0.0.0-20260811164956-006e29f97886 // indirect github.com/charmbracelet/x/exp/slice v0.0.0-20250327172914-2fdc97757edf // indirect + github.com/charmbracelet/x/termios v0.1.1 // indirect + github.com/charmbracelet/x/windows v0.2.2 // indirect + github.com/clipperhouse/displaywidth v0.11.0 // indirect + github.com/clipperhouse/uax29/v2 v2.7.0 // indirect github.com/dlclark/regexp2 v1.11.5 // indirect - github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect github.com/gorilla/css v1.0.1 // indirect - github.com/lucasb-eyer/go-colorful v1.3.0 // indirect - github.com/mattn/go-localereader v0.0.1 // indirect - github.com/mattn/go-runewidth v0.0.17 // indirect + github.com/lucasb-eyer/go-colorful v1.4.1 // indirect + github.com/mattn/go-runewidth v0.0.27 // indirect github.com/microcosm-cc/bluemonday v1.0.27 // indirect - github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect github.com/muesli/cancelreader v0.2.2 // indirect - github.com/muesli/reflow v0.3.0 // indirect github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect github.com/yuin/goldmark v1.7.13 // indirect github.com/yuin/goldmark-emoji v1.0.6 // indirect - golang.org/x/net v0.38.0 // indirect - golang.org/x/sync v0.17.0 // indirect - golang.org/x/term v0.36.0 // indirect + golang.org/x/net v0.39.0 // indirect + golang.org/x/sync v0.22.0 // indirect ) diff --git a/cli/go.sum b/cli/go.sum index 8287d2dde..580836f83 100644 --- a/cli/go.sum +++ b/cli/go.sum @@ -1,3 +1,11 @@ +charm.land/bubbles/v2 v2.2.1 h1:Fq1+qm5hV6GkvzLQDhCBpXXE5tLgvh1PRriCLwSvIQU= +charm.land/bubbles/v2 v2.2.1/go.mod h1:wdMgn+sje1KNXdwFizIWjbf328fIUBxqEmJ/vYPo8yc= +charm.land/bubbletea/v2 v2.0.10 h1:oolvo20VBpI0PfqE7iFjkZ1bx0WpmXGfnKz5Yldjq5o= +charm.land/bubbletea/v2 v2.0.10/go.mod h1:QOatcnhOjYIfxzUSTz6raF7Ex4R/rIuHa3SnBdCCpMc= +charm.land/glamour/v2 v2.0.1 h1:xl+r00A4aJWU0z8fgwKd9fQQ4rsphqGUzuEiXZP5n+c= +charm.land/glamour/v2 v2.0.1/go.mod h1:jo9z8XqVKPeEFMVdvCRLGk++RyJ3CdUwgNr7EvXLw3k= +charm.land/lipgloss/v2 v2.0.6 h1:EaGKeuA8FvF+v2BT5VmZd2LoYLaMZJXA5n34th8nCIQ= +charm.land/lipgloss/v2 v2.0.6/go.mod h1:ipDDJNSGa1hlwDtSfW1s2/xR8Vdhbut4PXh2zEKZd0Q= github.com/MakeNowJust/heredoc v1.0.0 h1:cXCdzVdstXyiTqTvfqk9SDHpKNjxuom+DOlyEeQ4pzQ= github.com/MakeNowJust/heredoc v1.0.0/go.mod h1:mG5amYoWBHf8vpLOuehzbGGw0EHxpZZ6lCpQ4fNJ8LE= github.com/alecthomas/assert/v2 v2.11.0 h1:2Q9r3ki8+JYXvGsDyBXwH3LcJ+WK5D0gc5E8vS6K3D0= @@ -8,63 +16,48 @@ github.com/alecthomas/repr v0.5.1 h1:E3G4t2QbHTSNpPKBgMTln5KLkZHLOcU7r37J4pXBuIg github.com/alecthomas/repr v0.5.1/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4= github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= -github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= -github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= -github.com/aymanbagabas/go-udiff v0.2.0 h1:TK0fH4MteXUDspT88n8CKzvK0X9O2xu9yQjWpi6yML8= -github.com/aymanbagabas/go-udiff v0.2.0/go.mod h1:RE4Ex0qsGkTAJoQdQQCA0uG+nAzJO/pI/QwceO5fgrA= +github.com/aymanbagabas/go-udiff v0.4.1 h1:OEIrQ8maEeDBXQDoGCbbTTXYJMYRCRO1fnodZ12Gv5o= +github.com/aymanbagabas/go-udiff v0.4.1/go.mod h1:0L9PGwj20lrtmEMeyw4WKJ/TMyDtvAoK9bf2u/mNo3w= github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk= github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4= -github.com/charmbracelet/bubbles v0.20.0 h1:jSZu6qD8cRQ6k9OMfR1WlM+ruM8fkPWkHvQWD9LIutE= -github.com/charmbracelet/bubbles v0.20.0/go.mod h1:39slydyswPy+uVOHZ5x/GjwVAFkCsV8IIVy+4MhzwwU= -github.com/charmbracelet/bubbletea v1.3.4 h1:kCg7B+jSCFPLYRA52SDZjr51kG/fMUEoPoZrkaDHyoI= -github.com/charmbracelet/bubbletea v1.3.4/go.mod h1:dtcUCyCGEX3g9tosuYiut3MXgY/Jsv9nKVdibKKRRXo= -github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc h1:4pZI35227imm7yK2bGPcfpFEmuY1gc2YSTShr4iJBfs= -github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc/go.mod h1:X4/0JoqgTIPSFcRA/P6INZzIuyqdFY5rm8tb41s9okk= -github.com/charmbracelet/glamour v1.0.0 h1:AWMLOVFHTsysl4WV8T8QgkQ0s/ZNZo7CiE4WKhk8l08= -github.com/charmbracelet/glamour v1.0.0/go.mod h1:DSdohgOBkMr2ZQNhw4LZxSGpx3SvpeujNoXrQyH2hxo= -github.com/charmbracelet/lipgloss v1.1.1-0.20250404203927-76690c660834 h1:ZR7e0ro+SZZiIZD7msJyA+NjkCNNavuiPBLgerbOziE= -github.com/charmbracelet/lipgloss v1.1.1-0.20250404203927-76690c660834/go.mod h1:aKC/t2arECF6rNOnaKaVU6y4t4ZeHQzqfxedE/VkVhA= -github.com/charmbracelet/x/ansi v0.10.2 h1:ith2ArZS0CJG30cIUfID1LXN7ZFXRCww6RUvAPA+Pzw= -github.com/charmbracelet/x/ansi v0.10.2/go.mod h1:HbLdJjQH4UH4AqA2HpRWuWNluRE6zxJH/yteYEYCFa8= -github.com/charmbracelet/x/cellbuf v0.0.13 h1:/KBBKHuVRbq1lYx5BzEHBAFBP8VcQzJejZ/IA3iR28k= -github.com/charmbracelet/x/cellbuf v0.0.13/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs= -github.com/charmbracelet/x/exp/golden v0.0.0-20240815200342-61de596daa2b h1:MnAMdlwSltxJyULnrYbkZpp4k58Co7Tah3ciKhSNo0Q= -github.com/charmbracelet/x/exp/golden v0.0.0-20240815200342-61de596daa2b/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U= +github.com/charmbracelet/colorprofile v0.4.3 h1:QPa1IWkYI+AOB+fE+mg/5/4HRMZcaXex9t5KX76i20Q= +github.com/charmbracelet/colorprofile v0.4.3/go.mod h1:/zT4BhpD5aGFpqQQqw7a+VtHCzu+zrQtt1zhMt9mR4Q= +github.com/charmbracelet/ultraviolet v0.0.0-20260811164956-006e29f97886 h1:rdnVWKgJpTVXKuKuJyxDJ+NFJdUaUqGvyGy61OcvlbA= +github.com/charmbracelet/ultraviolet v0.0.0-20260811164956-006e29f97886/go.mod h1:nAw0d9PhFp1qdzi2xhQU5YOu5sVpDIHWlaW2Uz/bCro= +github.com/charmbracelet/x/ansi v0.11.8 h1:JMFwp0CgDC2+jcOB162HH5k7I3FVbgFSMMYg7dSPBQQ= +github.com/charmbracelet/x/ansi v0.11.8/go.mod h1:ZNN+3mXny/516oTQPLMPIBeSINvNJJQ8uQXDgbeJxY0= +github.com/charmbracelet/x/exp/golden v0.0.0-20250806222409-83e3a29d542f h1:pk6gmGpCE7F3FcjaOEKYriCvpmIN4+6OS/RD0vm4uIA= +github.com/charmbracelet/x/exp/golden v0.0.0-20250806222409-83e3a29d542f/go.mod h1:IfZAMTHB6XkZSeXUqriemErjAWCCzT0LwjKFYCZyw0I= github.com/charmbracelet/x/exp/slice v0.0.0-20250327172914-2fdc97757edf h1:rLG0Yb6MQSDKdB52aGX55JT1oi0P0Kuaj7wi1bLUpnI= github.com/charmbracelet/x/exp/slice v0.0.0-20250327172914-2fdc97757edf/go.mod h1:B3UgsnsBZS/eX42BlaNiJkD1pPOUa+oF1IYC6Yd2CEU= -github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= -github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg= +github.com/charmbracelet/x/term v0.2.2 h1:xVRT/S2ZcKdhhOuSP4t5cLi5o+JxklsoEObBSgfgZRk= +github.com/charmbracelet/x/term v0.2.2/go.mod h1:kF8CY5RddLWrsgVwpw4kAa6TESp6EB5y3uxGLeCqzAI= +github.com/charmbracelet/x/termios v0.1.1 h1:o3Q2bT8eqzGnGPOYheoYS8eEleT5ZVNYNy8JawjaNZY= +github.com/charmbracelet/x/termios v0.1.1/go.mod h1:rB7fnv1TgOPOyyKRJ9o+AsTU/vK5WHJ2ivHeut/Pcwo= +github.com/charmbracelet/x/windows v0.2.2 h1:IofanmuvaxnKHuV04sC0eBy/smG6kIKrWG2/jYn2GuM= +github.com/charmbracelet/x/windows v0.2.2/go.mod h1:/8XtdKZzedat74NQFn0NGlGL4soHB0YQZrETF96h75k= +github.com/clipperhouse/displaywidth v0.11.0 h1:lBc6kY44VFw+TDx4I8opi/EtL9m20WSEFgwIwO+UVM8= +github.com/clipperhouse/displaywidth v0.11.0/go.mod h1:bkrFNkf81G8HyVqmKGxsPufD3JhNl3dSqnGhOoSD/o0= +github.com/clipperhouse/uax29/v2 v2.7.0 h1:+gs4oBZ2gPfVrKPthwbMzWZDaAFPGYK72F0NJv2v7Vk= +github.com/clipperhouse/uax29/v2 v2.7.0/go.mod h1:EFJ2TJMRUaplDxHKj1qAEhCtQPW2tJSwu5BF98AuoVM= github.com/dlclark/regexp2 v1.11.5 h1:Q/sSnsKerHeCkc/jSTNq1oCm7KiVgUMZRDUoRu0JQZQ= github.com/dlclark/regexp2 v1.11.5/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= -github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4= -github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM= github.com/gorilla/css v1.0.1 h1:ntNaBIghp6JmvWnxbZKANoLyuXTPZ4cAMlo6RyhlbO8= github.com/gorilla/css v1.0.1/go.mod h1:BvnYkspnSzMmwRK+b8/xgNPLiIuNZr6vbZBTPQ2A3b0= github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= -github.com/lucasb-eyer/go-colorful v1.3.0 h1:2/yBRLdWBZKrf7gB40FoiKfAWYQ0lqNcbuQwVHXptag= -github.com/lucasb-eyer/go-colorful v1.3.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= +github.com/lucasb-eyer/go-colorful v1.4.1 h1:1EO+WB73+EH8EVbzlrG3KLAfEypQWVHIBqlTf+2hNss= +github.com/lucasb-eyer/go-colorful v1.4.1/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4= -github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88= -github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= -github.com/mattn/go-runewidth v0.0.17 h1:78v8ZlW0bP43XfmAfPsdXcoNCelfMHsDmd/pkENfrjQ= -github.com/mattn/go-runewidth v0.0.17/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/mattn/go-runewidth v0.0.27 h1:Feg/Oou5zI/wnpgDF6omIU0OokC9GxLC/WRknhVlIR0= +github.com/mattn/go-runewidth v0.0.27/go.mod h1:3qAiGCV4Koz/yuveO58qUefmUTRm8r0IGEXZ9jeHp/8= github.com/microcosm-cc/bluemonday v1.0.27 h1:MpEUotklkwCSLeH+Qdx1VJgNqLlpY2KXwXFM08ygZfk= github.com/microcosm-cc/bluemonday v1.0.27/go.mod h1:jFi9vgW+H7c3V0lb6nR74Ib/DIB5OBs92Dimizgw2cA= -github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI= -github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo= github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA= github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo= -github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s= -github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8= -github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc= -github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk= -github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= -github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/sahilm/fuzzy v0.1.3 h1:juByESSS32nVD81vr6tHmKmA/8zde7gE+x5CLxrzXPU= @@ -75,17 +68,14 @@ github.com/yuin/goldmark v1.7.13 h1:GPddIs617DnBLFFVJFgpo1aBfe/4xcvMc3SB5t/D0pA= github.com/yuin/goldmark v1.7.13/go.mod h1:ip/1k0VRfGynBgxOz0yCqHrbZXhcjxyuS66Brc7iBKg= github.com/yuin/goldmark-emoji v1.0.6 h1:QWfF2FYaXwL74tfGOW5izeiZepUDroDJfWubQI9HTHs= github.com/yuin/goldmark-emoji v1.0.6/go.mod h1:ukxJDKFpdFb5x0a5HqbdlcKtebh086iJpI31LTKmWuA= -golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E= -golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE= -golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8= -golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8= -golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug= -golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= -golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI= +golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo= +golang.org/x/net v0.39.0 h1:ZCu7HMWDxpXpaiKdhzIfaltL9Lp31x/3fCP11bc6/fY= +golang.org/x/net v0.39.0/go.mod h1:X7NRbYVEA+ewNkCNyJ513WmMdQ3BineSwVtN2zD/d+E= +golang.org/x/sync v0.22.0 h1:SZjpbeLmrCk4xhRSZFNZW5gFUeCeFgjekvI/+gfScek= +golang.org/x/sync v0.22.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ= -golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= -golang.org/x/term v0.36.0 h1:zMPR+aF8gfksFprF/Nc/rd1wRS1EI6nDBGyWAvDzx2Q= -golang.org/x/term v0.36.0/go.mod h1:Qu394IJq6V6dCBRgwqshf3mPF85AqzYEzofzRdZkWss= +golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs= +golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= golang.org/x/text v0.30.0 h1:yznKA/E9zq54KzlzBEAWn1NXSQ8DIp/NYMy88xJjl4k= golang.org/x/text v0.30.0/go.mod h1:yDdHFIX9t+tORqspjENWgzaCVXgk0yYnYuSZ8UzzBVM= diff --git a/cli/internal/tui/agents_view.go b/cli/internal/tui/agents_view.go index dcb95dc8b..a427a00c4 100644 --- a/cli/internal/tui/agents_view.go +++ b/cli/internal/tui/agents_view.go @@ -16,8 +16,8 @@ import ( "albedo/cli/internal/daemon" - "github.com/charmbracelet/bubbles/textinput" - tea "github.com/charmbracelet/bubbletea" + "charm.land/bubbles/v2/textinput" + tea "charm.land/bubbletea/v2" "github.com/charmbracelet/x/ansi" ) @@ -170,7 +170,7 @@ var ( ) func NewAgentsViewModel(conn *daemon.Connection, sessionID string) AgentsViewModel { - input := textinput.New() + input := newTextInput() input.Prompt = "" input.CharLimit = 4000 input.Focus() @@ -399,7 +399,7 @@ func (m AgentsViewModel) update(msg tea.Msg) (AgentsViewModel, tea.Cmd) { } return m, nil - case tea.KeyMsg: + case tea.KeyPressMsg: return m.key(msg) } var cmd tea.Cmd @@ -409,7 +409,7 @@ func (m AgentsViewModel) update(msg tea.Msg) (AgentsViewModel, tea.Cmd) { type agentsReconnectMsg struct{ Gen int } -func (m AgentsViewModel) key(msg tea.KeyMsg) (AgentsViewModel, tea.Cmd) { +func (m AgentsViewModel) key(msg tea.KeyPressMsg) (AgentsViewModel, tea.Cmd) { empty := m.input.Value() == "" if m.confirm != "" { id := m.confirm @@ -421,7 +421,7 @@ func (m AgentsViewModel) key(msg tea.KeyMsg) (AgentsViewModel, tea.Cmd) { m.say("kept") return m, nil } - if msg.Type == tea.KeyCtrlX { + if msg.String() == "ctrl+x" { n := m.nodes[m.selected] switch { case n == nil || n.id == agentsYou: @@ -433,19 +433,19 @@ func (m AgentsViewModel) key(msg tea.KeyMsg) (AgentsViewModel, tea.Cmd) { return m, nil } switch { - case msg.Type == tea.KeyEsc || msg.Type == tea.KeyCtrlC || msg.Type == tea.KeyCtrlO: - if !empty && msg.Type == tea.KeyEsc { + case msg.String() == "esc" || msg.String() == "ctrl+c" || msg.String() == "ctrl+o": + if !empty && msg.String() == "esc" { m.input.SetValue("") return m, nil } return m, func() tea.Msg { return AgentsDoneMsg{} } - case msg.Type == tea.KeyTab, empty && (msg.Type == tea.KeyRight || msg.Type == tea.KeyDown): + case msg.String() == "tab", empty && (msg.String() == "right" || msg.String() == "down"): m.cycle(1) return m, m.seedCmd() - case msg.Type == tea.KeyShiftTab, empty && (msg.Type == tea.KeyLeft || msg.Type == tea.KeyUp): + case msg.String() == "shift+tab", empty && (msg.String() == "left" || msg.String() == "up"): m.cycle(-1) return m, m.seedCmd() - case msg.Type == tea.KeyEnter: + case msg.String() == "enter": text := strings.TrimSpace(m.input.Value()) n := m.nodes[m.selected] if n == nil { diff --git a/cli/internal/tui/agents_view_test.go b/cli/internal/tui/agents_view_test.go index 6cdcef281..dfc006cde 100644 --- a/cli/internal/tui/agents_view_test.go +++ b/cli/internal/tui/agents_view_test.go @@ -6,7 +6,7 @@ import ( "albedo/cli/internal/daemon" - tea "github.com/charmbracelet/bubbletea" + tea "charm.land/bubbletea/v2" "github.com/charmbracelet/x/ansi" ) @@ -61,7 +61,7 @@ func TestAgentsViewSelectsAndAttaches(t *testing.T) { if m.selected == "lead" { t.Fatal("tab did not move the selection") } - _, cmd := m.key(tea.KeyMsg{Type: tea.KeyEnter}) + _, cmd := m.key(tea.KeyPressMsg{Code: tea.KeyEnter}) if cmd == nil { t.Fatal("enter on an empty input should attach") } @@ -130,7 +130,7 @@ func TestAgentsOpenFromTheCommandAndCtrlO(t *testing.T) { t.Fatal("/agents should open the agents view, not the session browser") } chat := NewChatModel(&daemon.Session{ID: "lead"}, nil) - _, cmd = chat.Update(tea.KeyMsg{Type: tea.KeyCtrlO}) + _, cmd = chat.Update(tea.KeyPressMsg{Code: 'o', Mod: tea.ModCtrl}) if cmd == nil { t.Fatal("ctrl+o did nothing") } @@ -197,22 +197,22 @@ func TestCodeLinesReadsPartialJSON(t *testing.T) { func TestAgentsDeleteAsksFirstAndSparesTheOpenSession(t *testing.T) { m := agentsFixture(t) - m, _ = m.key(tea.KeyMsg{Type: tea.KeyCtrlX}) + m, _ = m.key(tea.KeyPressMsg{Code: 'x', Mod: tea.ModCtrl}) if m.confirm != "" || !strings.Contains(ansi.Strip(m.View()), "session browser") { t.Fatal("the session the view opened from must not be deletable here") } m.selected = "coder" - m, _ = m.key(tea.KeyMsg{Type: tea.KeyCtrlX}) + m, _ = m.key(tea.KeyPressMsg{Code: 'x', Mod: tea.ModCtrl}) view := ansi.Strip(m.View()) if m.confirm != "coder" || !strings.Contains(view, "delete coder and the agent below it?") { t.Fatalf("ctrl+x should ask first:\n%s", view) } - m, cmd := m.key(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("n")}) + m, cmd := m.key(tea.KeyPressMsg{Code: 'n', Text: "n"}) if m.confirm != "" || cmd != nil { t.Fatal("any key but y keeps the agent") } - m, _ = m.key(tea.KeyMsg{Type: tea.KeyCtrlX}) - _, cmd = m.key(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("y")}) + m, _ = m.key(tea.KeyPressMsg{Code: 'x', Mod: tea.ModCtrl}) + _, cmd = m.key(tea.KeyPressMsg{Code: 'y', Text: "y"}) if cmd == nil { t.Fatal("y should delete") } diff --git a/cli/internal/tui/app.go b/cli/internal/tui/app.go index 62b5a9d9c..14aeb6c4a 100644 --- a/cli/internal/tui/app.go +++ b/cli/internal/tui/app.go @@ -12,7 +12,7 @@ import ( "strings" "time" - tea "github.com/charmbracelet/bubbletea" + tea "charm.land/bubbletea/v2" ) type AppState int @@ -200,7 +200,6 @@ func (m AppModel) Init() tea.Cmd { return tea.Batch( m.Chat.Init(), m.loadCommandCatalogCmd(m.CatalogGen), - mouseModeCmd(AppStateChat), ) case AppStateLogin: m.Login.BrowserOpener = m.BrowserOpener @@ -514,15 +513,6 @@ func (m *AppModel) openSession(s daemon.Session) tea.Cmd { ) } -func mouseModeCmd(state AppState) tea.Cmd { - return func() tea.Msg { - if state == AppStateChat { - return tea.EnableMouseCellMotion() - } - return tea.DisableMouse() - } -} - func (m *AppModel) AddNotice(message string) { if m.ActiveSession != nil { m.Chat.AddNotice(message) @@ -546,18 +536,7 @@ func (m *AppModel) ClearNotices() { } } -func (m AppModel) Update(msg tea.Msg) (result tea.Model, command tea.Cmd) { - previous := m.State - defer func() { - updated, ok := result.(AppModel) - if !ok { - return - } - result = updated - if updated.State != previous { - command = tea.Batch(command, mouseModeCmd(updated.State)) - } - }() +func (m AppModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { // First: forward chat lifecycle messages even while a modal is open. switch streamMsg := msg.(type) { case ChatEditorFinishedMsg: @@ -565,7 +544,7 @@ func (m AppModel) Update(msg tea.Msg) (result tea.Model, command tea.Cmd) { if m.ActiveSession != nil && streamMsg.SessionID == m.ActiveSession.ID { m.Chat, cmd = m.Chat.Update(msg) } - return m, tea.Batch(cmd, mouseModeCmd(m.State)) + return m, cmd case ChatClearCopyStatusMsg: var cmd tea.Cmd if m.ActiveSession != nil && streamMsg.SessionID == m.ActiveSession.ID { @@ -1196,7 +1175,17 @@ func (m AppModel) Update(msg tea.Msg) (result tea.Model, command tea.Cmd) { return m, cmd } -func (m AppModel) View() string { +// View captures the mouse only in chat, where it scrolls and selects; every +// other screen leaves it to the terminal. +func (m AppModel) View() tea.View { + v := tea.NewView(m.content()) + if m.State == AppStateChat { + v.MouseMode = tea.MouseModeCellMotion + } + return v +} + +func (m AppModel) content() string { var prefix strings.Builder if m.State == AppStateSessionPicker { for _, n := range m.Notices { diff --git a/cli/internal/tui/capability_pages.go b/cli/internal/tui/capability_pages.go index 201a3e479..ad68b3c04 100644 --- a/cli/internal/tui/capability_pages.go +++ b/cli/internal/tui/capability_pages.go @@ -13,7 +13,7 @@ import ( "sort" "strings" - tea "github.com/charmbracelet/bubbletea" + tea "charm.land/bubbletea/v2" "github.com/charmbracelet/x/ansi" ) @@ -359,16 +359,22 @@ func (m CapabilityPageModel) Update(msg tea.Msg) (CapabilityPageModel, tea.Cmd) m.Notice = "saved · session reloaded" m.Loading = true return m, tea.Batch(m.loadCmd(m.Generation), func() tea.Msg { return CapabilityPageChangedMsg{} }) - case tea.KeyMsg: + case tea.PasteMsg: + if m.Form == nil || m.Saving { + return m, nil + } + _, cmd := m.Form.update(msg) + return m, cmd + case tea.KeyPressMsg: if m.Saving { return m, nil } if m.ConfirmExtension { - if msg.Type == tea.KeyEsc { + if msg.String() == "esc" { m.ConfirmExtension = false return m, nil } - if msg.Type == tea.KeyEnter { + if msg.String() == "enter" { m.ConfirmExtension = false m.Saving = true m.Generation++ @@ -377,7 +383,7 @@ func (m CapabilityPageModel) Update(msg tea.Msg) (CapabilityPageModel, tea.Cmd) return m, nil } if m.Form != nil { - if msg.Type == tea.KeyEsc { + if msg.String() == "esc" { m.Form = nil m.Error = "" return m, nil @@ -398,71 +404,68 @@ func (m CapabilityPageModel) Update(msg tea.Msg) (CapabilityPageModel, tea.Cmd) } if m.ConfirmDelete { m.ConfirmDelete = false - if msg.Type == tea.KeyEnter && len(m.Items) > 0 { + if msg.String() == "enter" && len(m.Items) > 0 { m.Saving = true m.Generation++ return m, m.deleteMCPCmd(m.Items[m.Cursor].ID, m.Generation) } return m, nil } - if msg.Type == tea.KeyEsc || msg.Type == tea.KeyCtrlC { + if msg.String() == "esc" || msg.String() == "ctrl+c" { return m, func() tea.Msg { return CapabilityPageDoneMsg{} } } if m.Loading { return m, nil } - switch msg.Type { - case tea.KeyUp: + switch msg.String() { + case "up": if m.Cursor > 0 { m.Cursor-- } - case tea.KeyDown: + case "down": if m.Cursor < len(m.Items)-1 { m.Cursor++ } - case tea.KeyRunes: - switch msg.String() { - case "r": - m.Loading = true - m.Generation++ - return m, m.loadCmd(m.Generation) - case "g": - m.Global = true - case "s": - m.Global = false - case "E": - if !m.ExtensionEnabled { - m.ConfirmExtension = true - } - case "n": - if m.Kind == "mcp" { - m.openForm(false) - } - case "d": - if m.Kind == "mcp" && len(m.Items) > 0 { - m.ConfirmDelete = true - } - case "e": - // Re-enables a server switched off in extensions.json. - if m.Kind == "mcp" && len(m.Items) > 0 && m.Items[m.Cursor].Server.Enabled != nil && !*m.Items[m.Cursor].Server.Enabled { - item := m.Items[m.Cursor] - server := item.Server - server.Enabled = nil - credentials, err := config.ReadMCPCredentials(m.Home) - if err != nil { - m.Error = err.Error() - return m, nil - } - m.Saving = true - m.Generation++ - return m, m.saveMCPCmd(mcpSubmission{Name: item.ID, Server: server, Secrets: credentials.Servers[item.ID]}, m.Generation) + case "r": + m.Loading = true + m.Generation++ + return m, m.loadCmd(m.Generation) + case "g": + m.Global = true + case "s": + m.Global = false + case "E": + if !m.ExtensionEnabled { + m.ConfirmExtension = true + } + case "n": + if m.Kind == "mcp" { + m.openForm(false) + } + case "d": + if m.Kind == "mcp" && len(m.Items) > 0 { + m.ConfirmDelete = true + } + case "e": + // Re-enables a server switched off in extensions.json. + if m.Kind == "mcp" && len(m.Items) > 0 && m.Items[m.Cursor].Server.Enabled != nil && !*m.Items[m.Cursor].Server.Enabled { + item := m.Items[m.Cursor] + server := item.Server + server.Enabled = nil + credentials, err := config.ReadMCPCredentials(m.Home) + if err != nil { + m.Error = err.Error() + return m, nil } + m.Saving = true + m.Generation++ + return m, m.saveMCPCmd(mcpSubmission{Name: item.ID, Server: server, Secrets: credentials.Servers[item.ID]}, m.Generation) } - case tea.KeyEnter: + case "enter": if m.Kind == "mcp" && len(m.Items) > 0 { m.openForm(true) } - case tea.KeySpace: + case "space": if len(m.Items) > 0 { m.Saving = true m.Generation++ diff --git a/cli/internal/tui/capability_pages_test.go b/cli/internal/tui/capability_pages_test.go index e9e5cfc61..91f4fe34d 100644 --- a/cli/internal/tui/capability_pages_test.go +++ b/cli/internal/tui/capability_pages_test.go @@ -7,7 +7,7 @@ import ( "strings" "testing" - tea "github.com/charmbracelet/bubbletea" + tea "charm.land/bubbletea/v2" "github.com/charmbracelet/x/ansi" ) @@ -61,7 +61,7 @@ description: test m.Items = append(m.Items, capabilityItem{ID: strings.Repeat("a", i+1), Title: strings.Repeat("a", i+1)}) } for i := 0; i < 29; i++ { - m, _ = m.Update(tea.KeyMsg{Type: tea.KeyDown}) + m, _ = m.Update(tea.KeyPressMsg{Code: tea.KeyDown}) } if !strings.Contains(ansi.Strip(m.View()), strings.Repeat("a", 29)) { t.Fatal("selected row scrolled offscreen") diff --git a/cli/internal/tui/chat.go b/cli/internal/tui/chat.go index 9753e7e16..3fe7b829f 100644 --- a/cli/internal/tui/chat.go +++ b/cli/internal/tui/chat.go @@ -15,12 +15,11 @@ import ( "strings" "time" - "github.com/charmbracelet/bubbles/cursor" - "github.com/charmbracelet/bubbles/textarea" - "github.com/charmbracelet/bubbles/textinput" - "github.com/charmbracelet/bubbles/viewport" - tea "github.com/charmbracelet/bubbletea" - "github.com/charmbracelet/lipgloss" + "charm.land/bubbles/v2/textarea" + "charm.land/bubbles/v2/textinput" + "charm.land/bubbles/v2/viewport" + tea "charm.land/bubbletea/v2" + "charm.land/lipgloss/v2" "github.com/charmbracelet/x/ansi" ) @@ -337,8 +336,8 @@ func NewChatModel(session *daemon.Session, client *daemon.ChatClient) ChatModel ta.Prompt = promptMark ta.CharLimit = 0 ta.ShowLineNumbers = false - ta.SetPromptFunc(promptMarkWidth, func(lineIdx int) string { - if lineIdx == 0 { + ta.SetPromptFunc(promptMarkWidth, func(info textarea.PromptInfo) string { + if info.LineNumber == 0 { return promptMark } return strings.Repeat(" ", promptMarkWidth) @@ -347,17 +346,19 @@ func NewChatModel(session *daemon.Session, client *daemon.ChatClient) ChatModel ta.KeyMap.WordBackward.SetKeys("alt+left", "alt+b", "ctrl+left") ta.KeyMap.WordForward.SetKeys("alt+right", "alt+f", "ctrl+right") ta.SetHeight(6) - ta.FocusedStyle.Prompt = DefaultStyles.Prompt - ta.FocusedStyle.CursorLine = lipgloss.NewStyle() - ta.FocusedStyle.Placeholder = DefaultStyles.Faint - ta.BlurredStyle.Prompt = DefaultStyles.Prompt - ta.BlurredStyle.CursorLine = lipgloss.NewStyle() - ta.BlurredStyle.Placeholder = DefaultStyles.Faint - ta.Cursor.Style = DefaultStyles.Cursor - ta.Cursor.SetMode(cursor.CursorStatic) + st := ta.Styles() + st.Focused.Prompt = DefaultStyles.Prompt + st.Focused.CursorLine = lipgloss.NewStyle() + st.Focused.Placeholder = DefaultStyles.Faint + st.Blurred.Prompt = DefaultStyles.Prompt + st.Blurred.CursorLine = lipgloss.NewStyle() + st.Blurred.Placeholder = DefaultStyles.Faint + st.Cursor.Blink = false + st.Cursor.Color = nil + ta.SetStyles(st) ta.Focus() - vp := viewport.New(80, 20) + vp := viewport.New(viewport.WithWidth(80), viewport.WithHeight(20)) vp.YPosition = 0 bh := NewBoundedHistory(500, 2*1024*1024) @@ -409,7 +410,7 @@ func (m *ChatModel) syncViewportHeight() { if m == nil || m.History == nil || m.Height <= 0 { return } - m.Viewport.Height = max(1, m.Height-6-m.chromeRows()) + m.Viewport.SetHeight(max(1, m.Height-6-m.chromeRows())) m.refreshViewportContent() } @@ -514,7 +515,7 @@ func (m ChatModel) chromeRows() int { func (m *ChatModel) syncLayout() { m.TextArea.SetHeight(m.maxPromptHeight()) - m.Viewport.Height = max(1, m.Height-6-m.chromeRows()) + m.Viewport.SetHeight(max(1, m.Height-6-m.chromeRows())) m.refreshViewportContent() } @@ -539,12 +540,12 @@ func (m *ChatModel) SetSize(width, height int) { transcriptWidth -= m.sidebarWidth() + 2 } - m.Viewport.Width = transcriptWidth + m.Viewport.SetWidth(transcriptWidth) m.TextArea.SetWidth(available) m.TextArea.SetHeight(m.maxPromptHeight()) - m.RecoveryInput.Width = max(1, available-16) + m.RecoveryInput.SetWidth(max(1, available-16)) - m.Viewport.Height = max(1, height-6-m.chromeRows()) + m.Viewport.SetHeight(max(1, height-6-m.chromeRows())) // settled rows are rendered at the body width alone, so only a new body // width renders them again @@ -720,7 +721,7 @@ func (m *ChatModel) streamDelta(kind ActiveStreamKind, text string) { } func (m *ChatModel) refreshViewportContent() int { - if m.Viewport.Height != max(1, m.Height-6-m.chromeRows()) { + if m.Viewport.Height() != max(1, m.Height-6-m.chromeRows()) { m.SetSize(m.Width, m.Height) return m.scrollLimit } @@ -758,7 +759,7 @@ func (m *ChatModel) refreshViewportContent() int { allLines = append(allLines, m.pendingRows()...) totalLines := len(allLines) - vpHeight := max(1, m.Viewport.Height) + vpHeight := max(1, m.Viewport.Height()) maxScroll := max(0, totalLines-vpHeight) m.scrollLimit = maxScroll @@ -1029,9 +1030,9 @@ func (m ChatModel) update(msg tea.Msg) (ChatModel, tea.Cmd) { var cmds []tea.Cmd switch msg := msg.(type) { - case tea.KeyMsg: + case tea.KeyPressMsg: if m.WorkspaceRecovery != nil { - if msg.Type == tea.KeyEsc { + if msg.String() == "esc" { prompt := m.WorkspaceRecovery.Prompt img := m.WorkspaceRecovery.Image m.WorkspaceRecovery = nil @@ -1044,7 +1045,7 @@ func (m ChatModel) update(msg tea.Msg) (ChatModel, tea.Cmd) { m.refreshViewportContent() return m, nil } - if msg.Type == tea.KeyEnter { + if msg.String() == "enter" { m.RecoveryInput.CursorStart() replacement := strings.TrimSpace(m.RecoveryInput.Value()) if replacement != "" && !m.WorkspaceRecovery.Saving { @@ -1062,20 +1063,20 @@ func (m ChatModel) update(msg tea.Msg) (ChatModel, tea.Cmd) { // The selector owns keys while open, before chat navigation or composer input. if len(m.effortOptions) > 0 { - switch msg.Type { - case tea.KeyLeft, tea.KeyUp: + switch msg.String() { + case "left", "up": m.effortSelected = max(0, m.effortSelected-1) - case tea.KeyRight, tea.KeyDown: + case "right", "down": m.effortSelected = min(len(m.effortOptions)-1, m.effortSelected+1) - case tea.KeyEnter: + case "enter": level := m.effortOptions[m.effortSelected] m.effortOptions = nil m.syncLayout() return m, func() tea.Msg { return ChatExecuteCommandMsg{Name: "/effort", Args: level} } - case tea.KeyEsc: + case "esc": m.effortOptions = nil m.syncLayout() - case tea.KeyCtrlC: + case "ctrl+c": if m.streamCancel != nil { m.streamCancel() } @@ -1084,23 +1085,23 @@ func (m ChatModel) update(msg tea.Msg) (ChatModel, tea.Cmd) { return m, nil } - if msg.Type == tea.KeyLeft && m.TextArea.Value() == "" { + if msg.String() == "left" && m.TextArea.Value() == "" { return m, func() tea.Msg { return ChatBackToSessionsMsg{} } } - if msg.Type == tea.KeyCtrlC || (msg.Type == tea.KeyCtrlD && m.TextArea.Focused() && m.TextArea.Value() == "") { + if msg.String() == "ctrl+c" || (msg.String() == "ctrl+d" && m.TextArea.Focused() && m.TextArea.Value() == "") { if m.streamCancel != nil { m.streamCancel() } return m, func() tea.Msg { return ChatQuitMsg{} } } - if msg.Type == tea.KeyCtrlN { + if msg.String() == "ctrl+n" { return m, func() tea.Msg { return ChatNewSessionMsg{} } } - if msg.Type == tea.KeyCtrlO { + if msg.String() == "ctrl+o" { return m, func() tea.Msg { return ChatOpenAgentsMsg{} } } - if msg.Type == tea.KeyEsc && m.dragAnchor != nil { + if msg.String() == "esc" && m.dragAnchor != nil { m.dragAnchor = nil return m, nil } @@ -1121,7 +1122,7 @@ func (m ChatModel) update(msg tea.Msg) (ChatModel, tea.Cmd) { return m, tea.Batch(cmds...) } - if msg.Type == tea.KeyEsc { + if msg.String() == "esc" { if m.AttachedImage != nil { m.AttachedImage = nil m.CopyStatus = "image removed" @@ -1141,52 +1142,52 @@ func (m ChatModel) update(msg tea.Msg) (ChatModel, tea.Cmd) { } } - if msg.Type == tea.KeyCtrlV { + if msg.String() == "ctrl+v" { return m, PasteClipboardImageCmd(m.SessionID, m.Generation) } - if msg.Type == tea.KeyCtrlG { + if msg.String() == "ctrl+g" { return m, m.openEditorCmd() } - if msg.Type == tea.KeyPgUp { - m.scrollBy(-m.Viewport.Height) + if msg.String() == "pgup" { + m.scrollBy(-m.Viewport.Height()) return m, nil } - if msg.Type == tea.KeyPgDown { - m.scrollBy(m.Viewport.Height) + if msg.String() == "pgdown" { + m.scrollBy(m.Viewport.Height()) return m, nil } - if msg.Type == tea.KeyUp && m.TextArea.Line() == 0 && m.TextArea.LineInfo().RowOffset == 0 { + if msg.String() == "up" && m.TextArea.Line() == 0 && m.TextArea.LineInfo().RowOffset == 0 { m.scrollBy(-1) return m, nil } - if msg.Type == tea.KeyDown && m.TextArea.Line() >= m.TextArea.LineCount()-1 && m.TextArea.LineInfo().RowOffset >= m.TextArea.LineInfo().Height-1 { + if msg.String() == "down" && m.TextArea.Line() >= m.TextArea.LineCount()-1 && m.TextArea.LineInfo().RowOffset >= m.TextArea.LineInfo().Height-1 { m.scrollBy(1) return m, nil } - if msg.Type == tea.KeyShiftUp || msg.Type == tea.KeyShiftDown { - m.jumpToYou(msg.Type == tea.KeyShiftUp) + if msg.String() == "shift+up" || msg.String() == "shift+down" { + m.jumpToYou(msg.String() == "shift+up") return m, nil } - if msg.Type == tea.KeyCtrlHome { + if msg.String() == "ctrl+home" { m.Follow = false m.scrollOffset = 0 m.refreshViewportContent() return m, nil } - if msg.Type == tea.KeyCtrlEnd { + if msg.String() == "ctrl+end" { m.Follow = true m.refreshViewportContent() return m, nil } - if msg.Type == tea.KeyCtrlJ { + if msg.String() == "ctrl+j" { m.Flags.Diffs = !m.Flags.Diffs m.rebuildSettledLines() m.refreshViewportContent() return m, nil } - if msg.Type == tea.KeyCtrlK { + if msg.String() == "ctrl+k" { m.Flags.Compaction = !m.Flags.Compaction m.rebuildSettledLines() m.refreshViewportContent() @@ -1195,13 +1196,13 @@ func (m ChatModel) update(msg tea.Msg) (ChatModel, tea.Cmd) { // Bubbles wordLeft never terminates when everything before the cursor // is whitespace. Move to the input start directly in that case. - if msg.Type == tea.KeyCtrlLeft && m.wordBackwardAtStart() { + if msg.String() == "ctrl+left" && m.wordBackwardAtStart() { var cmd tea.Cmd - m.TextArea, cmd = m.TextArea.Update(tea.KeyMsg{Type: tea.KeyCtrlHome}) + m.TextArea, cmd = m.TextArea.Update(tea.KeyPressMsg{Code: tea.KeyHome, Mod: tea.ModCtrl}) return m, cmd } - if msg.Type == tea.KeyEnter && !msg.Alt { + if msg.String() == "enter" { trimmed := strings.TrimSpace(m.TextArea.Value()) if trimmed != "" { m.TextArea.Reset() @@ -1214,10 +1215,15 @@ func (m ChatModel) update(msg tea.Msg) (ChatModel, tea.Cmd) { case tea.MouseMsg: firstRow := 2 + m.Notices.ChromeRows() + mouse := msg.Mouse() point := func() Point { - return Point{Row: max(0, min(m.Viewport.Height-1, msg.Y-firstRow)), Col: max(0, min(m.Viewport.Width, msg.X-m.padding()))} + return Point{Row: max(0, min(m.Viewport.Height()-1, mouse.Y-firstRow)), Col: max(0, min(m.Viewport.Width(), mouse.X-m.padding()))} } - if msg.Action == tea.MouseActionRelease && m.dragAnchor != nil { + switch msg := msg.(type) { + case tea.MouseReleaseMsg: + if m.dragAnchor == nil { + return m, nil + } m.dragHead = point() sel := Selection{Anchor: *m.dragAnchor, Head: m.dragHead, Gutter: railWidth} m.dragAnchor = nil @@ -1233,29 +1239,28 @@ func (m ChatModel) update(msg tea.Msg) (ChatModel, tea.Cmd) { return m, m.clearCopyStatusCmd() } } - return m, nil - } - if msg.Action == tea.MouseActionMotion && m.dragAnchor != nil { - m.dragHead = point() - return m, nil - } - if msg.Action == tea.MouseActionPress && msg.Button == tea.MouseButtonLeft { - if msg.Y < firstRow || msg.Y >= firstRow+m.Viewport.Height { - return m, nil + case tea.MouseMotionMsg: + if m.dragAnchor != nil { + m.dragHead = point() + } + case tea.MouseClickMsg: + if msg.Button == tea.MouseLeft { + if mouse.Y < firstRow || mouse.Y >= firstRow+m.Viewport.Height() { + return m, nil + } + pt := point() + m.dragAnchor = &pt + m.dragHead = pt + } + case tea.MouseWheelMsg: + switch msg.Button { + case tea.MouseWheelUp: + m.scrollBy(-3) + case tea.MouseWheelDown: + m.scrollBy(3) } - pt := point() - m.dragAnchor = &pt - m.dragHead = pt - return m, nil - } - switch msg.Button { - case tea.MouseButtonWheelUp: - m.scrollBy(-3) - return m, nil - case tea.MouseButtonWheelDown: - m.scrollBy(3) - return m, nil } + return m, nil case ClipboardImagePastedMsg: if msg.SessionID != m.SessionID || msg.Generation != m.Generation { @@ -1362,13 +1367,14 @@ func (m ChatModel) update(msg tea.Msg) (ChatModel, tea.Cmd) { if m.AttachedImage == nil && msg.Image != nil { m.AttachedImage = msg.Image } - ti := textinput.New() + ti := newTextInput() ti.SetValue(wsErr.Workspace) ti.Focus() ti.Prompt = "new workspace › " - ti.PromptStyle = m.Styles.Prompt - ti.Cursor.Style = DefaultStyles.Cursor - ti.Cursor.SetMode(cursor.CursorStatic) + st := ti.Styles() + st.Focused.Prompt = m.Styles.Prompt + st.Blurred.Prompt = m.Styles.Prompt + ti.SetStyles(st) m.RecoveryInput = ti recoveryPrompt := msg.Prompt if msg.Continue { @@ -1458,20 +1464,20 @@ func (m ChatModel) update(msg tea.Msg) (ChatModel, tea.Cmd) { defer os.Remove(msg.Path) } if msg.SessionID != m.SessionID || msg.Generation != m.Generation { - return m, tea.EnableMouseCellMotion + return m, nil } if msg.Err != nil { m.AddError("editor error: " + msg.Err.Error()) - return m, tea.EnableMouseCellMotion + return m, nil } data, err := os.ReadFile(msg.Path) if err != nil { m.AddError("could not read edited prompt: " + err.Error()) - return m, tea.EnableMouseCellMotion + return m, nil } m.TextArea.SetValue(strings.TrimRight(string(data), "\r\n")) m.syncLayout() - return m, tea.EnableMouseCellMotion + return m, nil case ChatInterruptMsg: if msg.SessionID != m.SessionID || msg.Generation != m.Generation { @@ -2300,10 +2306,10 @@ func (m ChatModel) View() string { view = lipgloss.JoinHorizontal(lipgloss.Top, view, " ", m.renderGlances()) } content := strings.Split(view, "\n") - for len(content) < m.Viewport.Height { + for len(content) < m.Viewport.Height() { content = append(content, "") } - content = content[:min(len(content), m.Viewport.Height)] + content = content[:min(len(content), m.Viewport.Height())] if m.dragAnchor != nil { content = HighlightSelection(content, Selection{Anchor: *m.dragAnchor, Head: m.dragHead, Gutter: railWidth}) } @@ -2384,7 +2390,7 @@ func (m ChatModel) renderGlances() string { if len(g.Rows) == 0 { continue } - room := max(0, min(m.Viewport.Height, 12)-1) + room := max(0, min(m.Viewport.Height(), 12)-1) shown := min(room, len(g.Rows)) if len(g.Rows) > room { shown = max(0, room-1) diff --git a/cli/internal/tui/chat_navigation_test.go b/cli/internal/tui/chat_navigation_test.go index cd2902520..dbf8fd1c8 100644 --- a/cli/internal/tui/chat_navigation_test.go +++ b/cli/internal/tui/chat_navigation_test.go @@ -6,7 +6,7 @@ import ( "testing" "albedo/cli/internal/daemon" - tea "github.com/charmbracelet/bubbletea" + tea "charm.land/bubbletea/v2" "github.com/charmbracelet/x/ansi" ) @@ -16,9 +16,9 @@ func TestScrollDoesNotResumeFollowBeforeEndOfLiveOutput(t *testing.T) { msg tea.Msg step int }{ - {"arrow", tea.KeyMsg{Type: tea.KeyDown}, 1}, - {"page", tea.KeyMsg{Type: tea.KeyPgDown}, 13}, - {"wheel", tea.MouseMsg{Button: tea.MouseButtonWheelDown}, 3}, + {"arrow", tea.KeyPressMsg{Code: tea.KeyDown}, 1}, + {"page", tea.KeyPressMsg{Code: tea.KeyPgDown}, 13}, + {"wheel", tea.MouseWheelMsg{Button: tea.MouseWheelDown}, 3}, } { t.Run(down.name, func(t *testing.T) { m := NewChatModel(&daemon.Session{ID: "s"}, nil) @@ -41,7 +41,7 @@ func TestScrollDoesNotResumeFollowBeforeEndOfLiveOutput(t *testing.T) { if m.scrollOffset != before+down.step { t.Fatal("next refresh lost scroll position") } - m, _ = m.Update(tea.KeyMsg{Type: tea.KeyUp}) + m, _ = m.Update(tea.KeyPressMsg{Code: tea.KeyUp}) if m.scrollOffset != before+down.step-1 || m.Follow { t.Fatalf("up did not move one row: offset=%d follow=%v", m.scrollOffset, m.Follow) } @@ -58,8 +58,8 @@ func TestReadingPositionSurvivesIncomingTranscript(t *testing.T) { name string msg tea.Msg }{ - {"keyboard", tea.KeyMsg{Type: tea.KeyPgUp}}, - {"wheel", tea.MouseMsg{Button: tea.MouseButtonWheelUp}}, + {"keyboard", tea.KeyPressMsg{Code: tea.KeyPgUp}}, + {"wheel", tea.MouseWheelMsg{Button: tea.MouseWheelUp}}, } { t.Run(scroll.name, func(t *testing.T) { m := NewChatModel(&daemon.Session{ID: "s"}, nil) @@ -137,7 +137,7 @@ func TestCompactionHintLivesOnEventNotFooter(t *testing.T) { if flags.Compaction { want = "ctrl+k hide summary" } - if rendered := m.Renderer.RenderEntry(entry, flags, m.Viewport.Width); !strings.Contains(rendered, want) { + if rendered := m.Renderer.RenderEntry(entry, flags, m.Viewport.Width()); !strings.Contains(rendered, want) { t.Fatalf("compaction event missing %q: %q", want, rendered) } } diff --git a/cli/internal/tui/clipboard.go b/cli/internal/tui/clipboard.go index 0a2373a43..6d4c75173 100644 --- a/cli/internal/tui/clipboard.go +++ b/cli/internal/tui/clipboard.go @@ -18,8 +18,8 @@ import ( "strings" "time" + tea "charm.land/bubbletea/v2" "github.com/atotto/clipboard" - tea "github.com/charmbracelet/bubbletea" ) const ( diff --git a/cli/internal/tui/commands.go b/cli/internal/tui/commands.go index 87912e5b4..890a26061 100644 --- a/cli/internal/tui/commands.go +++ b/cli/internal/tui/commands.go @@ -4,7 +4,7 @@ import ( "albedo/cli/internal/daemon" "strings" - tea "github.com/charmbracelet/bubbletea" + tea "charm.land/bubbletea/v2" ) type ChatCommand struct { @@ -90,7 +90,7 @@ func (m CommandMenuModel) Matches(input string) []ChatCommand { } // OnKey handles navigation within the command popup. Returns true if consumed. -func (m *CommandMenuModel) OnKey(msg tea.KeyMsg, input string, replace func(string), submit func(string)) bool { +func (m *CommandMenuModel) OnKey(msg tea.KeyPressMsg, input string, replace func(string), submit func(string)) bool { matches := m.Matches(input) if len(matches) == 0 { return false @@ -104,24 +104,24 @@ func (m *CommandMenuModel) OnKey(msg tea.KeyMsg, input string, replace func(stri idx = 0 } - switch msg.Type { - case tea.KeyEsc: + switch msg.String() { + case "esc": m.Dismissed = input return true - case tea.KeyUp: + case "up": if idx > 0 { m.Selected = idx - 1 } return true - case tea.KeyDown: + case "down": if idx < len(matches)-1 { m.Selected = idx + 1 } return true - case tea.KeyTab: + case "tab": replace(matches[idx].Name) return true - case tea.KeyEnter: + case "enter": submit(matches[idx].Name) return true default: diff --git a/cli/internal/tui/context_inspector.go b/cli/internal/tui/context_inspector.go index 11281e2f1..8e0904bea 100644 --- a/cli/internal/tui/context_inspector.go +++ b/cli/internal/tui/context_inspector.go @@ -10,7 +10,7 @@ import ( "strings" "unicode/utf16" - tea "github.com/charmbracelet/bubbletea" + tea "charm.land/bubbletea/v2" "github.com/charmbracelet/x/ansi" "golang.org/x/text/language" "golang.org/x/text/message" @@ -241,8 +241,8 @@ func (m ContextInspectorModel) Update(msg tea.Msg) (ContextInspectorModel, tea.C } return m, nil - case tea.KeyMsg: - if msg.Type == tea.KeyEsc || msg.Type == tea.KeyCtrlC || msg.Type == tea.KeyCtrlD { + case tea.KeyPressMsg: + if msg.String() == "esc" || msg.String() == "ctrl+c" || msg.String() == "ctrl+d" { if m.Detail != nil { m.Detail = nil m.Generation++ @@ -259,8 +259,8 @@ func (m ContextInspectorModel) Update(msg tea.Msg) (ContextInspectorModel, tea.C visibleRows := max(1, m.Height-7) maxScroll := max(0, len(lines)-visibleRows) - switch msg.Type { - case tea.KeyLeft: + switch msg.String() { + case "left": if m.Detail.Page > 0 { m.Detail.Page-- m.Detail.Value = nil @@ -269,7 +269,7 @@ func (m ContextInspectorModel) Update(msg tea.Msg) (ContextInspectorModel, tea.C m.Generation++ return m, m.loadPageCmd(m.Detail.Section.ID, m.Detail.Page, m.Generation) } - case tea.KeyRight: + case "right": if m.Detail.Page+1 < m.Detail.Section.Pages { m.Detail.Page++ m.Detail.Value = nil @@ -278,17 +278,17 @@ func (m ContextInspectorModel) Update(msg tea.Msg) (ContextInspectorModel, tea.C m.Generation++ return m, m.loadPageCmd(m.Detail.Section.ID, m.Detail.Page, m.Generation) } - case tea.KeyUp: + case "up": if m.Detail.Scroll > 0 { m.Detail.Scroll-- } - case tea.KeyDown: + case "down": if m.Detail.Scroll < maxScroll { m.Detail.Scroll++ } - case tea.KeyPgUp: + case "pgup": m.Detail.Scroll = max(0, m.Detail.Scroll-visibleRows) - case tea.KeyPgDown: + case "pgdown": m.Detail.Scroll = min(maxScroll, m.Detail.Scroll+visibleRows) } return m, nil @@ -303,16 +303,16 @@ func (m ContextInspectorModel) Update(msg tea.Msg) (ContextInspectorModel, tea.C return m, m.loadSnapshotCmd(m.Generation) } - switch msg.Type { - case tea.KeyUp, tea.KeyCtrlP: + switch msg.String() { + case "up", "ctrl+p": if m.Cursor > 0 { m.Cursor-- } - case tea.KeyDown, tea.KeyCtrlN: + case "down", "ctrl+n": if m.Snapshot != nil && m.Cursor < len(m.Snapshot.Sections)-1 { m.Cursor++ } - case tea.KeyEnter: + case "enter": if m.Snapshot != nil && len(m.Snapshot.Sections) > m.Cursor { sec := m.Snapshot.Sections[m.Cursor] if sec.Pages > 0 { diff --git a/cli/internal/tui/effort_selector.go b/cli/internal/tui/effort_selector.go index d57fd7d83..207abfbaf 100644 --- a/cli/internal/tui/effort_selector.go +++ b/cli/internal/tui/effort_selector.go @@ -3,7 +3,7 @@ package tui import ( "strings" - "github.com/charmbracelet/lipgloss" + "charm.land/lipgloss/v2" "github.com/charmbracelet/x/ansi" ) diff --git a/cli/internal/tui/effort_selector_test.go b/cli/internal/tui/effort_selector_test.go index 37623710f..29656c2b2 100644 --- a/cli/internal/tui/effort_selector_test.go +++ b/cli/internal/tui/effort_selector_test.go @@ -6,7 +6,7 @@ import ( "albedo/cli/internal/config" "albedo/cli/internal/daemon" - tea "github.com/charmbracelet/bubbletea" + tea "charm.land/bubbletea/v2" "github.com/charmbracelet/x/ansi" ) @@ -16,7 +16,7 @@ func TestEffortSelectorStaysInChatAndCommits(t *testing.T) { app.Chat.SetSize(80, 22) updated, _ := app.Update(commandExecutedMsg{Name: "/effort", Available: []string{"low", "medium", "high", "xhigh", "max"}, Gen: app.CommandGen}) app = updated.(AppModel) - view := ansi.Strip(app.View()) + view := ansi.Strip(app.View().Content) if app.State != AppStateChat || app.Chat.effortSelected != 2 || !strings.Contains(view, "[high]") { t.Fatal("expected current tier selected within chat") } @@ -33,15 +33,15 @@ func TestEffortSelectorStaysInChatAndCommits(t *testing.T) { if strings.Contains(view, "ctrl+g editor") { t.Fatal("composer must be hidden while choosing effort") } - oldHeight := app.Chat.Viewport.Height - updated, _ = app.Update(tea.KeyMsg{Type: tea.KeyRight}) + oldHeight := app.Chat.Viewport.Height() + updated, _ = app.Update(tea.KeyPressMsg{Code: tea.KeyRight}) app = updated.(AppModel) - if app.Chat.effortSelected != 3 || !strings.Contains(ansi.Strip(app.View()), "[xhigh]") { + if app.Chat.effortSelected != 3 || !strings.Contains(ansi.Strip(app.View().Content), "[xhigh]") { t.Fatal("right did not select xhigh") } - updated, cmd := app.Update(tea.KeyMsg{Type: tea.KeyEnter}) + updated, cmd := app.Update(tea.KeyPressMsg{Code: tea.KeyEnter}) app = updated.(AppModel) - if len(app.Chat.effortOptions) != 0 || app.Chat.Viewport.Height != oldHeight+3 { + if len(app.Chat.effortOptions) != 0 || app.Chat.Viewport.Height() != oldHeight+3 { t.Fatal("selector did not close and restore viewport") } got, ok := cmd().(ChatExecuteCommandMsg) @@ -57,7 +57,7 @@ func TestEffortSelectorEscapeAndNarrowLayout(t *testing.T) { if line := m.effortSelectorView(); !strings.Contains(ansi.Strip(line), "[max]") || ansi.StringWidth(line) > m.chatWidth() { t.Fatalf("selected level clipped or line too wide: %q", line) } - m, cmd := m.Update(tea.KeyMsg{Type: tea.KeyEsc}) + m, cmd := m.Update(tea.KeyPressMsg{Code: tea.KeyEsc}) if cmd != nil || len(m.effortOptions) != 0 { t.Fatal("escape did not dismiss selector") } diff --git a/cli/internal/tui/effort_test.go b/cli/internal/tui/effort_test.go index 8cb1c3331..627af1fc0 100644 --- a/cli/internal/tui/effort_test.go +++ b/cli/internal/tui/effort_test.go @@ -6,7 +6,7 @@ import ( "path/filepath" "strings" - tea "github.com/charmbracelet/bubbletea" + tea "charm.land/bubbletea/v2" "testing" "github.com/charmbracelet/x/ansi" @@ -108,7 +108,7 @@ func TestDisplayPreferencesFollowChatsAndRestart(t *testing.T) { app.LoadPrefs(path) for _, command := range []string{"/t", "/v"} { app.Chat.TextArea.SetValue(command) - updated, _ := app.Update(tea.KeyMsg{Type: tea.KeyEnter}) + updated, _ := app.Update(tea.KeyPressMsg{Code: tea.KeyEnter}) app = updated.(AppModel) } if !app.Chat.Flags.Thinking || !app.Chat.Flags.Tools { @@ -128,7 +128,7 @@ func TestDisplayPreferencesFollowChatsAndRestart(t *testing.T) { t.Fatal("restart reset display choices") } restarted.Chat.TextArea.SetValue("/t") - updated, _ := restarted.Update(tea.KeyMsg{Type: tea.KeyEnter}) + updated, _ := restarted.Update(tea.KeyPressMsg{Code: tea.KeyEnter}) restarted = updated.(AppModel) if !restarted.Chat.Flags.Tools || restarted.Chat.Flags.Thinking { t.Fatal("thinking toggle also reset verbose") diff --git a/cli/internal/tui/extension_picker.go b/cli/internal/tui/extension_picker.go index 565ca110c..3d44d525b 100644 --- a/cli/internal/tui/extension_picker.go +++ b/cli/internal/tui/extension_picker.go @@ -7,7 +7,7 @@ import ( "fmt" "strings" - tea "github.com/charmbracelet/bubbletea" + tea "charm.land/bubbletea/v2" "github.com/charmbracelet/x/ansi" ) @@ -200,8 +200,8 @@ func (m ExtensionPickerModel) Update(msg tea.Msg) (ExtensionPickerModel, tea.Cmd m.Error = "" return m, func() tea.Msg { return ExtensionPickerChangedMsg{} } - case tea.KeyMsg: - if msg.Type == tea.KeyEsc || (msg.Type == tea.KeyCtrlC || msg.Type == tea.KeyCtrlD) { + case tea.KeyPressMsg: + if msg.String() == "esc" || msg.String() == "ctrl+c" || msg.String() == "ctrl+d" { if m.Confirming { m.Confirming = false m.Inheriting = false @@ -226,7 +226,7 @@ func (m ExtensionPickerModel) Update(msg tea.Msg) (ExtensionPickerModel, tea.Cmd } if m.Confirming { - if msg.Type == tea.KeyEnter && len(m.Extensions) > m.Cursor { + if msg.String() == "enter" && len(m.Extensions) > m.Cursor { ext := m.Extensions[m.Cursor] m.Saving = true m.Error = "" @@ -243,38 +243,35 @@ func (m ExtensionPickerModel) Update(msg tea.Msg) (ExtensionPickerModel, tea.Cmd return m, nil } - switch msg.Type { - case tea.KeyUp, tea.KeyCtrlP: + switch msg.String() { + case "up", "ctrl+p": if m.Cursor > 0 { m.Cursor-- } - case tea.KeyDown, tea.KeyCtrlN: + case "down", "ctrl+n": if m.Cursor < len(m.Extensions)-1 { m.Cursor++ } - case tea.KeySpace, tea.KeyEnter: + case "space", "enter": if len(m.Extensions) > 0 && m.Cursor < len(m.Extensions) { m.Error = "" m.Confirming = true } - case tea.KeyRunes: - switch msg.String() { - case "g": - if !m.NoGlobal { - m.Session = false - } - case "s": - m.Session = true - case "o": - if m.Cursor < len(m.Extensions) && m.Extensions[m.Cursor].Name == "webhooks" && m.Extensions[m.Cursor].Enabled { - return m, func() tea.Msg { return ChatOpenWebhooksPageMsg{} } - } - case "x": - if m.Session && !m.NoGlobal && m.Cursor < len(m.Extensions) && m.Extensions[m.Cursor].Overridden { - m.Error = "" - m.Confirming = true - m.Inheriting = true - } + case "g": + if !m.NoGlobal { + m.Session = false + } + case "s": + m.Session = true + case "o": + if m.Cursor < len(m.Extensions) && m.Extensions[m.Cursor].Name == "webhooks" && m.Extensions[m.Cursor].Enabled { + return m, func() tea.Msg { return ChatOpenWebhooksPageMsg{} } + } + case "x": + if m.Session && !m.NoGlobal && m.Cursor < len(m.Extensions) && m.Extensions[m.Cursor].Overridden { + m.Error = "" + m.Confirming = true + m.Inheriting = true } } } diff --git a/cli/internal/tui/extension_scope_test.go b/cli/internal/tui/extension_scope_test.go index 6da1515f4..9720af4da 100644 --- a/cli/internal/tui/extension_scope_test.go +++ b/cli/internal/tui/extension_scope_test.go @@ -4,7 +4,7 @@ import ( "strings" "testing" - tea "github.com/charmbracelet/bubbletea" + tea "charm.land/bubbletea/v2" "github.com/charmbracelet/x/ansi" ) @@ -24,22 +24,22 @@ func TestExtensionsOpenOnGlobalDefaultsAndScopeToSessionOnRequest(t *testing.T) } // x only drops a session choice, and only in session scope. - m, _ = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("x")}) + m, _ = m.Update(tea.KeyPressMsg{Code: 'x', Text: "x"}) if m.Confirming { t.Fatal("x must not act on global defaults") } - m, _ = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("s")}) + m, _ = m.Update(tea.KeyPressMsg{Code: 's', Text: "s"}) view = ansi.Strip(m.View()) if !m.Session || !strings.Contains(view, "on view this session") || !strings.Contains(view, "bash follows global") { t.Fatalf("session scope should mark own choices and inherited ones:\n%s", view) } - m, _ = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("x")}) + m, _ = m.Update(tea.KeyPressMsg{Code: 'x', Text: "x"}) if !m.Confirming || !m.Inheriting || !strings.Contains(ansi.Strip(m.View()), "follow the global default") { t.Fatalf("x should confirm dropping the session choice:\n%s", ansi.Strip(m.View())) } - m, _ = m.Update(tea.KeyMsg{Type: tea.KeyEsc}) - m, _ = m.Update(tea.KeyMsg{Type: tea.KeyDown}) - m, _ = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("x")}) + m, _ = m.Update(tea.KeyPressMsg{Code: tea.KeyEsc}) + m, _ = m.Update(tea.KeyPressMsg{Code: tea.KeyDown}) + m, _ = m.Update(tea.KeyPressMsg{Code: 'x', Text: "x"}) if m.Confirming { t.Fatal("x needs a session choice to drop") } @@ -47,7 +47,7 @@ func TestExtensionsOpenOnGlobalDefaultsAndScopeToSessionOnRequest(t *testing.T) // An older daemon only supports per-session choices. old := NewExtensionPickerModel(nil, "s") old, _ = old.Update(extensionsLoadedMsg{Extensions: []ExtensionItem{{Name: "bash", Enabled: true}}, NoGlobal: true}) - old, _ = old.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("g")}) + old, _ = old.Update(tea.KeyPressMsg{Code: 'g', Text: "g"}) if !old.Session { t.Fatal("without daemon support the page must stay on this session") } diff --git a/cli/internal/tui/login.go b/cli/internal/tui/login.go index 9bc458803..feb49b376 100644 --- a/cli/internal/tui/login.go +++ b/cli/internal/tui/login.go @@ -11,9 +11,8 @@ import ( "strings" "time" - "github.com/charmbracelet/bubbles/cursor" - "github.com/charmbracelet/bubbles/textinput" - tea "github.com/charmbracelet/bubbletea" + "charm.land/bubbles/v2/textinput" + tea "charm.land/bubbletea/v2" "github.com/charmbracelet/x/ansi" ) @@ -187,9 +186,8 @@ func (m LoginModel) openBrowser(urlStr string) { func NewLoginModel(conn *daemon.Connection, nameHint string) LoginModel { profiles, loadErr := config.LoadProfiles(config.HomeDir()) - ti := textinput.New() + ti := newTextInput() ti.Prompt = "" - ti.Cursor.SetMode(cursor.CursorStatic) m := LoginModel{ Conn: conn, @@ -218,13 +216,13 @@ func (m LoginModel) inputWidth() int { func (m *LoginModel) resetInput() { m.TextInput.Reset() m.TextInput.EchoMode = textinput.EchoNormal - m.TextInput.Width = m.inputWidth() + m.TextInput.SetWidth(m.inputWidth()) } func (m *LoginModel) SetSize(width, height int) { m.Width = width m.Height = height - m.TextInput.Width = m.inputWidth() + m.TextInput.SetWidth(m.inputWidth()) m.TextInput.SetValue(m.TextInput.Value()) m.ChoosePicker.SetSize(width, height) m.ProtocolPicker.SetSize(width, height) @@ -703,8 +701,8 @@ func (m LoginModel) Update(msg tea.Msg) (LoginModel, tea.Cmd) { return LoginDoneMsg{Name: msg.Name, Settings: msg.Settings} } - case tea.KeyMsg: - if m.Step == StepChoose && (msg.Type == tea.KeyDelete || msg.String() == "d") { + case tea.KeyPressMsg: + if m.Step == StepChoose && (msg.String() == "delete" || msg.String() == "d") { if item, ok := m.ChoosePicker.Highlighted(); ok { if target, ok := m.removalFor(item.ID); ok { return m, m.confirmRemoval(target) @@ -712,9 +710,9 @@ func (m LoginModel) Update(msg tea.Msg) (LoginModel, tea.Cmd) { } return m, nil } - if msg.Type == tea.KeyEsc || msg.Type == tea.KeyCtrlC || msg.Type == tea.KeyCtrlD { + if msg.String() == "esc" || msg.String() == "ctrl+c" || msg.String() == "ctrl+d" { pickerStep := m.Step == StepChoose || m.Step == StepProtocol || m.Step == StepModels || m.Step == StepOAuthModels || m.Step == StepRemove - if !pickerStep || msg.Type == tea.KeyCtrlD { + if !pickerStep || msg.String() == "ctrl+d" { cancel := m.Close() m.Generation++ return m, tea.Batch(cancel, func() tea.Msg { return LoginCancelMsg{} }) @@ -833,7 +831,7 @@ func (m LoginModel) Update(msg tea.Msg) (LoginModel, tea.Cmd) { return m, cmd case StepName: - if keyMsg, ok := msg.(tea.KeyMsg); ok && keyMsg.Type == tea.KeyEnter { + if keyMsg, ok := msg.(tea.KeyPressMsg); ok && keyMsg.String() == "enter" { val := strings.TrimSpace(m.TextInput.Value()) m.TextInput.SetCursor(0) name, err := config.ValidateProviderName(val) @@ -863,7 +861,7 @@ func (m LoginModel) Update(msg tea.Msg) (LoginModel, tea.Cmd) { } case StepBaseURL: - if keyMsg, ok := msg.(tea.KeyMsg); ok && keyMsg.Type == tea.KeyEnter { + if keyMsg, ok := msg.(tea.KeyPressMsg); ok && keyMsg.String() == "enter" { val := strings.TrimSpace(m.TextInput.Value()) m.TextInput.SetCursor(0) if val == "" { @@ -888,7 +886,7 @@ func (m LoginModel) Update(msg tea.Msg) (LoginModel, tea.Cmd) { } case StepAPIKey: - if keyMsg, ok := msg.(tea.KeyMsg); ok && keyMsg.Type == tea.KeyEnter { + if keyMsg, ok := msg.(tea.KeyPressMsg); ok && keyMsg.String() == "enter" { val := m.TextInput.Value() m.TextInput.SetCursor(0) if val == "" && m.Draft.APIKey != "" { @@ -915,7 +913,7 @@ func (m LoginModel) Update(msg tea.Msg) (LoginModel, tea.Cmd) { } case StepOAuth: - if keyMsg, ok := msg.(tea.KeyMsg); ok && keyMsg.Type == tea.KeyEnter { + if keyMsg, ok := msg.(tea.KeyPressMsg); ok && keyMsg.String() == "enter" { val := strings.TrimSpace(m.TextInput.Value()) if val != "" && m.LoginID != "" { m.Status = "exchanging authorization code…" @@ -925,7 +923,7 @@ func (m LoginModel) Update(msg tea.Msg) (LoginModel, tea.Cmd) { } case StepModel: - if keyMsg, ok := msg.(tea.KeyMsg); ok && keyMsg.Type == tea.KeyEnter { + if keyMsg, ok := msg.(tea.KeyPressMsg); ok && keyMsg.String() == "enter" { val := strings.TrimSpace(m.TextInput.Value()) m.TextInput.SetCursor(0) if err := validateModelID(val); err != nil { diff --git a/cli/internal/tui/login_test.go b/cli/internal/tui/login_test.go index fa8bb6af3..5d9d1fcec 100644 --- a/cli/internal/tui/login_test.go +++ b/cli/internal/tui/login_test.go @@ -13,7 +13,7 @@ import ( "albedo/cli/internal/config" "albedo/cli/internal/daemon" - tea "github.com/charmbracelet/bubbletea" + tea "charm.land/bubbletea/v2" ) const fakeToken = "fake-daemon-token" @@ -237,7 +237,7 @@ func TestLoginSignsInThroughTheDaemon(t *testing.T) { } m.TextInput.SetValue("codex") - m, cmd := m.Update(tea.KeyMsg{Type: tea.KeyEnter}) + m, cmd := m.Update(tea.KeyPressMsg{Code: tea.KeyEnter}) m, cmd = apply(t, m, cmd) if m.Step != StepOAuth || m.LoginID != "signin-1" { t.Fatalf("typing a sign-in provider should start it, step=%v error=%q", m.Step, m.Error) @@ -314,7 +314,7 @@ func TestLoginPastesInputAndShowsTheDaemonFailure(t *testing.T) { f.setStatus(daemon.SignInStatus{State: "failed", Message: "missing authorization code"}) m.TextInput.SetValue("code#state") - m, cmd := m.Update(tea.KeyMsg{Type: tea.KeyEnter}) + m, cmd := m.Update(tea.KeyPressMsg{Code: tea.KeyEnter}) m, cmd = apply(t, m, cmd) m, _ = apply(t, m, cmd) if len(f.input) != 1 || f.input[0] != "code#state" { @@ -340,7 +340,7 @@ func TestLoginCancelsSignInOnExitAndStaleResults(t *testing.T) { m := newLogin(t, f, "") m = startSignIn(t, m, f) - m, cmd := m.Update(tea.KeyMsg{Type: tea.KeyEsc}) + m, cmd := m.Update(tea.KeyPressMsg{Code: tea.KeyEsc}) if m.LoginID != "" || m.Step != StepOAuth { t.Fatalf("esc should end the sign-in, step=%v id=%q", m.Step, m.LoginID) } @@ -418,7 +418,7 @@ func TestLoginSelectsAndRemovesAccountsThroughTheDaemon(t *testing.T) { } m.ChoosePicker.Cursor = pickerIndex(t, m, "account:1") - m, _ = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("d")}) + m, _ = m.Update(tea.KeyPressMsg{Code: 'd', Text: "d"}) if m.Step != StepRemove || m.Removing.ID != "account:acct/2" || m.Removing.Provider != "codex" { t.Fatalf("d on an account should confirm its removal, step=%v removing=%+v", m.Step, m.Removing) } @@ -444,7 +444,7 @@ func TestLoginRemovesHighlightedProvider(t *testing.T) { if item, _ := m.ChoosePicker.Highlighted(); item.ID != "use:work" { t.Fatalf("expected the active provider highlighted, got %q", item.ID) } - m, _ = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("d")}) + m, _ = m.Update(tea.KeyPressMsg{Code: 'd', Text: "d"}) if m.Step != StepRemove || m.Removing.Kind != "provider" || m.Removing.ID != "work" { t.Fatalf("d should confirm removing the highlighted provider, got step=%v removing=%+v", m.Step, m.Removing) } @@ -453,7 +453,7 @@ func TestLoginRemovesHighlightedProvider(t *testing.T) { t.Fatalf("cancelling the confirmation should return to the chooser, step=%v", m.Step) } - m, _ = m.Update(tea.KeyMsg{Type: tea.KeyDelete}) + m, _ = m.Update(tea.KeyPressMsg{Code: tea.KeyDelete}) m, cmd := m.Update(PickerSelectMsg{ID: "remove"}) m, _ = apply(t, m, cmd) if _, ok := m.Profiles.Providers["work"]; ok || m.Profiles.Active != "local" { @@ -501,14 +501,14 @@ func TestLoginConfiguresAlibabaProvider(t *testing.T) { // Enter provider name m.TextInput.SetValue("my-ali") - m, cmd = m.Update(tea.KeyMsg{Type: tea.KeyEnter}) + m, cmd = m.Update(tea.KeyPressMsg{Code: tea.KeyEnter}) m, _ = apply(t, m, cmd) if m.Step != StepBaseURL { t.Fatalf("expected StepBaseURL, got step=%v", m.Step) } // Accept default base URL - m, cmd = m.Update(tea.KeyMsg{Type: tea.KeyEnter}) + m, cmd = m.Update(tea.KeyPressMsg{Code: tea.KeyEnter}) m, _ = apply(t, m, cmd) if m.Step != StepAPIKey { t.Fatalf("expected StepAPIKey, got step=%v", m.Step) @@ -516,7 +516,7 @@ func TestLoginConfiguresAlibabaProvider(t *testing.T) { // Enter API key m.TextInput.SetValue("sk-test-ali-key") - m, cmd = m.Update(tea.KeyMsg{Type: tea.KeyEnter}) + m, cmd = m.Update(tea.KeyPressMsg{Code: tea.KeyEnter}) m, _ = apply(t, m, cmd) // For Alibaba, StepProtocol is skipped straight to StepModels if m.Step != StepModels { diff --git a/cli/internal/tui/markdown.go b/cli/internal/tui/markdown.go index 60092c15f..3459776af 100644 --- a/cli/internal/tui/markdown.go +++ b/cli/internal/tui/markdown.go @@ -6,11 +6,11 @@ import ( "strings" "sync" + "charm.land/glamour/v2" + "charm.land/glamour/v2/ansi" + "charm.land/glamour/v2/styles" "github.com/alecthomas/chroma/v2" chromastyles "github.com/alecthomas/chroma/v2/styles" - "github.com/charmbracelet/glamour" - "github.com/charmbracelet/glamour/ansi" - "github.com/charmbracelet/glamour/styles" ) // hashComments are the languages whose line comments start with "#". diff --git a/cli/internal/tui/mcp_form.go b/cli/internal/tui/mcp_form.go index ea97d5ed5..9fa50cd8a 100644 --- a/cli/internal/tui/mcp_form.go +++ b/cli/internal/tui/mcp_form.go @@ -9,8 +9,8 @@ import ( "sort" "strings" - "github.com/charmbracelet/bubbles/textinput" - tea "github.com/charmbracelet/bubbletea" + "charm.land/bubbles/v2/textinput" + tea "charm.land/bubbletea/v2" "github.com/charmbracelet/x/ansi" ) @@ -59,7 +59,7 @@ func newMCPForm(editing string, server config.MCPServer, stored config.MCPServer f.Transport = "stdio" } for _, key := range []string{fieldURL, fieldCommand, fieldName, fieldToken, fieldHeader, fieldValue, fieldEnv} { - input := textinput.New() + input := newTextInput() input.Prompt = "" input.CharLimit = 4096 switch key { @@ -117,34 +117,38 @@ func (f *mcpForm) move(delta int) { f.focus() } -// update handles one key; submit reports that the form should be saved. -func (f *mcpForm) update(msg tea.KeyMsg) (submit bool, cmd tea.Cmd) { - switch msg.Type { - case tea.KeyTab, tea.KeyDown: - f.move(1) - return false, nil - case tea.KeyShiftTab, tea.KeyUp: - f.move(-1) - return false, nil - case tea.KeyCtrlS: - return true, nil - case tea.KeyEnter: - if f.Focus == len(f.fields())-1 { +// update handles one key or paste; submit reports that the form should be saved. +func (f *mcpForm) update(msg tea.Msg) (submit bool, cmd tea.Cmd) { + if key, ok := msg.(tea.KeyPressMsg); ok { + switch key.String() { + case "tab", "down": + f.move(1) + return false, nil + case "shift+tab", "up": + f.move(-1) + return false, nil + case "ctrl+s": return true, nil + case "enter": + if f.Focus == len(f.fields())-1 { + return true, nil + } + f.move(1) + return false, nil } - f.move(1) - return false, nil } if f.current() == fieldTransport { - switch msg.Type { - case tea.KeyLeft, tea.KeyRight, tea.KeySpace: - if f.Editing == "" { - if f.Transport == "http" { - f.Transport = "stdio" - } else { - f.Transport = "http" + if key, ok := msg.(tea.KeyPressMsg); ok { + switch key.String() { + case "left", "right", "space": + if f.Editing == "" { + if f.Transport == "http" { + f.Transport = "stdio" + } else { + f.Transport = "http" + } + f.suggestName() } - f.suggestName() } } return false, nil @@ -267,6 +271,7 @@ func (f *mcpForm) view(width int) []string { if f.Editing != "" { title = "edit " + f.Editing } + fitInputs(f.Inputs, width-16) rows := []string{DefaultStyles.Bold.Render(title)} for i, key := range f.fields() { mark := " " diff --git a/cli/internal/tui/mcp_form_test.go b/cli/internal/tui/mcp_form_test.go index dd39e52d0..b1ae485aa 100644 --- a/cli/internal/tui/mcp_form_test.go +++ b/cli/internal/tui/mcp_form_test.go @@ -14,17 +14,17 @@ import ( "albedo/cli/internal/config" "albedo/cli/internal/daemon" - tea "github.com/charmbracelet/bubbletea" + tea "charm.land/bubbletea/v2" "github.com/charmbracelet/x/ansi" ) func typeText(m CapabilityPageModel, text string) CapabilityPageModel { - m, _ = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune(text)}) + m, _ = m.Update(tea.KeyPressMsg{Code: tea.KeyExtended, Text: text}) return m } -func key(m CapabilityPageModel, k tea.KeyType) CapabilityPageModel { - m, _ = m.Update(tea.KeyMsg{Type: k}) +func key(m CapabilityPageModel, k rune) CapabilityPageModel { + m, _ = m.Update(tea.KeyPressMsg{Code: k}) return m } @@ -101,7 +101,7 @@ func TestEditingKeepsOrRemovesStoredSecrets(t *testing.T) { if err != nil || sub.Secrets.BearerToken != "old" || sub.Secrets.Headers["X-Key"] != "k" || sub.Server.Enabled == nil { t.Fatalf("a blank edit must keep stored secrets and other fields: %+v %v", sub, err) } - if !strings.Contains(strings.Join(f.view(100), "\n"), "stored · blank keeps it") { + if !strings.Contains(ansi.Strip(strings.Join(f.view(100), "\n")), "stored · blank keeps it") { t.Fatal("edit form should say a token is stored") } f.Inputs[fieldToken].SetValue("-") @@ -129,7 +129,7 @@ func TestFailedConnectionRestoresConfigAndKeepsTheForm(t *testing.T) { m.Conn = daemon.NewConnection(daemon.ConnectionSnapshot{Port: port, Token: "t", Version: 2}, "") m = typeText(m, "n") m = typeText(m, "https://mcp.linear.app/mcp") - m, cmd := m.Update(tea.KeyMsg{Type: tea.KeyCtrlS}) + m, cmd := m.Update(tea.KeyPressMsg{Code: 's', Mod: tea.ModCtrl}) if !m.Saving || cmd == nil { t.Fatal("ctrl+s should save") } diff --git a/cli/internal/tui/memory_profile_test.go b/cli/internal/tui/memory_profile_test.go index 6aafa7bb9..d42413cb7 100644 --- a/cli/internal/tui/memory_profile_test.go +++ b/cli/internal/tui/memory_profile_test.go @@ -3,9 +3,9 @@ package tui import ( "albedo/cli/internal/config" "albedo/cli/internal/daemon" + tea "charm.land/bubbletea/v2" "encoding/json" "fmt" - tea "github.com/charmbracelet/bubbletea" "os" "os/exec" "path/filepath" diff --git a/cli/internal/tui/model_picker.go b/cli/internal/tui/model_picker.go index 200f8f543..d175553a1 100644 --- a/cli/internal/tui/model_picker.go +++ b/cli/internal/tui/model_picker.go @@ -12,10 +12,9 @@ import ( "strings" "unicode" - "github.com/charmbracelet/bubbles/cursor" - "github.com/charmbracelet/bubbles/textinput" - tea "github.com/charmbracelet/bubbletea" - "github.com/charmbracelet/lipgloss" + "charm.land/bubbles/v2/textinput" + tea "charm.land/bubbletea/v2" + "charm.land/lipgloss/v2" "github.com/charmbracelet/x/ansi" "github.com/sahilm/fuzzy" ) @@ -111,12 +110,13 @@ func NewModelPickerModel(conn *daemon.Connection, profiles config.Profiles, mode }) } - search := textinput.New() + search := newTextInput() search.Prompt = "" search.Placeholder = "search models, or type an id" - search.PlaceholderStyle = DefaultStyles.Faint - search.Cursor.Style = DefaultStyles.Cursor - search.Cursor.SetMode(cursor.CursorStatic) + st := search.Styles() + st.Focused.Placeholder = DefaultStyles.Faint + st.Blurred.Placeholder = DefaultStyles.Faint + search.SetStyles(st) search.Focus() m := ModelPickerModel{ @@ -165,7 +165,7 @@ func mergeModels(seeds []string, listed []daemon.Model) []daemon.Model { func (m *ModelPickerModel) SetSize(width, height int) { m.Width = width m.Height = height - m.search.Width = max(1, width-6) + m.search.SetWidth(max(1, width-6)) } func (m ModelPickerModel) Init() tea.Cmd { @@ -397,14 +397,14 @@ func (m ModelPickerModel) Update(msg tea.Msg) (ModelPickerModel, tea.Cmd) { m.refilter(false) return m, nil - case tea.KeyMsg: + case tea.KeyPressMsg: if m.Saving { return m, nil } - switch msg.Type { - case tea.KeyEsc, tea.KeyCtrlC, tea.KeyCtrlD: + switch msg.String() { + case "esc", "ctrl+c", "ctrl+d": return m, func() tea.Msg { return ModelPickerCancelMsg{} } - case tea.KeyEnter: + case "enter": r, ok := m.highlighted() if !ok { return m, nil @@ -416,21 +416,21 @@ func (m ModelPickerModel) Update(msg tea.Msg) (ModelPickerModel, tea.Cmd) { m.Error = "" choice := ModelPickerSelectMsg{Model: r.model.ID, Provider: r.profile, Effort: m.effort(r)} return m, func() tea.Msg { return choice } - case tea.KeyUp, tea.KeyCtrlP: + case "up", "ctrl+p": m.move(-1) return m, nil - case tea.KeyDown, tea.KeyCtrlN: + case "down", "ctrl+n": m.move(1) return m, nil - case tea.KeyPgUp: + case "pgup": m.move(-max(1, m.Height/2)) return m, nil - case tea.KeyPgDown: + case "pgdown": m.move(max(1, m.Height/2)) return m, nil - case tea.KeyLeft, tea.KeyRight: + case "left", "right": // Arrows edit a typed search until you move into the list. - by := map[tea.KeyType]int{tea.KeyLeft: -1, tea.KeyRight: 1}[msg.Type] + by := map[string]int{"left": -1, "right": 1}[msg.String()] if (m.search.Value() == "" || m.browsing) && m.stepEffort(by) { return m, nil } diff --git a/cli/internal/tui/model_picker_test.go b/cli/internal/tui/model_picker_test.go index ffcea0459..7a3e93c6a 100644 --- a/cli/internal/tui/model_picker_test.go +++ b/cli/internal/tui/model_picker_test.go @@ -14,8 +14,8 @@ import ( "albedo/cli/internal/config" "albedo/cli/internal/daemon" - tea "github.com/charmbracelet/bubbletea" - "github.com/charmbracelet/lipgloss" + tea "charm.land/bubbletea/v2" + "charm.land/lipgloss/v2" "github.com/charmbracelet/x/ansi" ) @@ -44,18 +44,18 @@ func loadedPicker(t *testing.T) ModelPickerModel { return m } -func pickerKey(m ModelPickerModel, keys ...tea.KeyMsg) ModelPickerModel { +func pickerKey(m ModelPickerModel, keys ...tea.KeyPressMsg) ModelPickerModel { for _, k := range keys { m, _ = m.Update(k) } return m } -func typed(s string) tea.KeyMsg { return tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune(s)} } +func typed(s string) tea.KeyPressMsg { return tea.KeyPressMsg{Code: tea.KeyExtended, Text: s} } func chosen(t *testing.T, m ModelPickerModel) ModelPickerSelectMsg { t.Helper() - _, cmd := m.Update(tea.KeyMsg{Type: tea.KeyEnter}) + _, cmd := m.Update(tea.KeyPressMsg{Code: tea.KeyEnter}) if cmd == nil { t.Fatal("enter chose nothing") } @@ -95,7 +95,7 @@ func TestModelPickerGroupsProfilesWithTheSessionsFirst(t *testing.T) { func TestModelPickerKeepsTheCursorWhenAListingArrives(t *testing.T) { m := NewModelPickerModel(nil, pickerProfiles, "gpt-5", "work", "") - m = pickerKey(m, tea.KeyMsg{Type: tea.KeyDown}) + m = pickerKey(m, tea.KeyPressMsg{Code: tea.KeyDown}) before, _ := m.highlighted() m, _ = m.Update(modelCatalogLoadedMsg{Profile: "work", Models: []daemon.Model{{ID: "a"}, {ID: "b"}}}) if after, _ := m.highlighted(); after.key() != before.key() { @@ -108,26 +108,26 @@ func TestModelPickerArrowsStepEffortAndEnterSendsIt(t *testing.T) { if got := chosen(t, m); got.Effort != "high" || got.Model != "gpt-5" || got.Provider != "work" { t.Fatalf("unchanged choice %+v, want the session's high effort", got) } - m = pickerKey(m, tea.KeyMsg{Type: tea.KeyLeft}, tea.KeyMsg{Type: tea.KeyLeft}, tea.KeyMsg{Type: tea.KeyLeft}) + m = pickerKey(m, tea.KeyPressMsg{Code: tea.KeyLeft}, tea.KeyPressMsg{Code: tea.KeyLeft}, tea.KeyPressMsg{Code: tea.KeyLeft}) if got := chosen(t, m); got.Effort != "low" { t.Fatalf("effort %q after stepping down past the end, want low", got.Effort) } - m = pickerKey(m, tea.KeyMsg{Type: tea.KeyRight}) + m = pickerKey(m, tea.KeyPressMsg{Code: tea.KeyRight}) if got := chosen(t, m); got.Effort != "medium" { t.Fatalf("effort %q, want medium", got.Effort) } // Another row lacking the session's level shows the daemon's default, // and the first row keeps its pick. - m = pickerKey(m, tea.KeyMsg{Type: tea.KeyDown}, tea.KeyMsg{Type: tea.KeyDown}) + m = pickerKey(m, tea.KeyPressMsg{Code: tea.KeyDown}, tea.KeyPressMsg{Code: tea.KeyDown}) if got := chosen(t, m); got.Model != "o4-mini" || got.Effort != "medium" { t.Fatalf("choice %+v, want o4-mini at medium", got) } - m = pickerKey(m, tea.KeyMsg{Type: tea.KeyUp}, tea.KeyMsg{Type: tea.KeyUp}) + m = pickerKey(m, tea.KeyPressMsg{Code: tea.KeyUp}, tea.KeyPressMsg{Code: tea.KeyUp}) if got := chosen(t, m); got.Effort != "medium" { t.Fatalf("first row forgot its pick: %+v", got) } // A model without levels sends none. - m = pickerKey(m, tea.KeyMsg{Type: tea.KeyDown}, tea.KeyMsg{Type: tea.KeyRight}) + m = pickerKey(m, tea.KeyPressMsg{Code: tea.KeyDown}, tea.KeyPressMsg{Code: tea.KeyRight}) if got := chosen(t, m); got.Model != "gpt-4.1" || got.Effort != "" { t.Fatalf("choice %+v, want gpt-4.1 without effort", got) } @@ -139,11 +139,11 @@ func TestModelPickerArrowsEditASearchUntilYouBrowse(t *testing.T) { if got := strings.Join(rowIDs(m), " "); got != "codex/gpt-5-codex typed:work/codex typed:codex/codex" { t.Fatalf("search rows %q", got) } - m = pickerKey(m, tea.KeyMsg{Type: tea.KeyLeft}, typed("x")) + m = pickerKey(m, tea.KeyPressMsg{Code: tea.KeyLeft}, typed("x")) if m.search.Value() != "codexx" { t.Fatalf("left arrow did not reach the search: %q", m.search.Value()) } - m = pickerKey(m, tea.KeyMsg{Type: tea.KeyBackspace}, tea.KeyMsg{Type: tea.KeyUp}, tea.KeyMsg{Type: tea.KeyLeft}) + m = pickerKey(m, tea.KeyPressMsg{Code: tea.KeyBackspace}, tea.KeyPressMsg{Code: tea.KeyUp}, tea.KeyPressMsg{Code: tea.KeyLeft}) if got := chosen(t, m); got.Model != "gpt-5-codex" || got.Effort != "medium" { t.Fatalf("after browsing, left should lower high to medium: %+v", got) } @@ -217,7 +217,7 @@ func TestModelPickerOffersATypedIDToEveryProfileMissingIt(t *testing.T) { if got != "codex/gpt-5-codex typed:work/gpt-5-codex" { t.Fatalf("rows %q", got) } - m = pickerKey(m, tea.KeyMsg{Type: tea.KeyDown}) + m = pickerKey(m, tea.KeyPressMsg{Code: tea.KeyDown}) if got := chosen(t, m); got.Model != "gpt-5-codex" || got.Provider != "work" || got.Effort != "" { t.Fatalf("typed choice %+v", got) } @@ -252,7 +252,7 @@ func TestModelPickerViewShowsProfilesLadderAndDetails(t *testing.T) { if strings.Count(view, "‹") != 1 { t.Fatalf("arrows belong to the selected row only:\n%s", view) } - m = pickerKey(m, tea.KeyMsg{Type: tea.KeyDown}) + m = pickerKey(m, tea.KeyPressMsg{Code: tea.KeyDown}) if view := ansi.Strip(m.View()); !strings.Contains(view, "1.05m tokens") { t.Fatalf("details did not follow the cursor:\n%s", view) } @@ -310,9 +310,9 @@ func TestModelPickerListsWithDetailsAndSwitchesWithTheChosenEffort(t *testing.T) t.Fatalf("rows %q", got) } - updated, _ = app.Update(tea.KeyMsg{Type: tea.KeyLeft}) + updated, _ = app.Update(tea.KeyPressMsg{Code: tea.KeyLeft}) app = updated.(AppModel) - updated, cmd := app.Update(tea.KeyMsg{Type: tea.KeyEnter}) + updated, cmd := app.Update(tea.KeyPressMsg{Code: tea.KeyEnter}) app = updated.(AppModel) updated, cmd = app.Update(cmd()) app = updated.(AppModel) diff --git a/cli/internal/tui/mouse_repair.go b/cli/internal/tui/mouse_repair.go deleted file mode 100644 index fc7a9ca42..000000000 --- a/cli/internal/tui/mouse_repair.go +++ /dev/null @@ -1,96 +0,0 @@ -package tui - -import ( - "regexp" - "strconv" - - tea "github.com/charmbracelet/bubbletea" -) - -// sgrTail is what remains of an SGR mouse report once its "ESC [" was -// consumed on its own: "= r.want { - return r, tea.Quit - } - } - return r, nil -} - -// Bubble Tea's own reader, fed full 256-byte reads that end inside a report. -func TestBubbleTeaReaderSplitsAreRepaired(t *testing.T) { - var stream []byte - for i := 0; i < 60; i++ { - stream = append(stream, "\x1b[<64;19;5M"...) - } - run := func(filter bool) (mouse, keys int) { - model := &recorder{want: 60} - opts := []tea.ProgramOption{tea.WithInput(&chunked{data: stream, size: 256}), tea.WithoutRenderer(), tea.WithoutSignalHandler()} - if filter { - opts = append(opts, tea.WithFilter(RepairSplitMouse())) - } else { - model.want = 61 // each split adds a key - } - done := make(chan struct{}) - go func() { _, _ = tea.NewProgram(model, opts...).Run(); close(done) }() - <-done - for _, msg := range model.msgs { - switch msg.(type) { - case tea.MouseMsg: - mouse++ - case tea.KeyMsg: - keys++ - } - } - return mouse, keys - } - if mouse, keys := run(false); keys == 0 { - t.Fatalf("expected the unfiltered reader to split a report (mouse %d)", mouse) - } - if mouse, keys := run(true); mouse != 60 || keys != 0 { - t.Fatalf("filtered: %d mouse events, %d keys; want 60 and 0", mouse, keys) - } -} diff --git a/cli/internal/tui/notice_clear_test.go b/cli/internal/tui/notice_clear_test.go index 14e2d3b07..f2369955e 100644 --- a/cli/internal/tui/notice_clear_test.go +++ b/cli/internal/tui/notice_clear_test.go @@ -6,7 +6,7 @@ import ( "albedo/cli/internal/config" "albedo/cli/internal/daemon" - tea "github.com/charmbracelet/bubbletea" + tea "charm.land/bubbletea/v2" "github.com/charmbracelet/x/ansi" ) @@ -40,7 +40,7 @@ func TestNoticeClearedOnUserMessageSubmit(t *testing.T) { // Now user enters a new message and submits app.Chat.TextArea.SetValue("how's the weather?") - updated, _ = app.Update(tea.KeyMsg{Type: tea.KeyEnter}) + updated, _ = app.Update(tea.KeyPressMsg{Code: tea.KeyEnter}) app = updated.(AppModel) if len(app.Chat.Notices) != 0 { diff --git a/cli/internal/tui/older_history_test.go b/cli/internal/tui/older_history_test.go index 690e057de..99a274378 100644 --- a/cli/internal/tui/older_history_test.go +++ b/cli/internal/tui/older_history_test.go @@ -9,7 +9,7 @@ import ( "testing" "albedo/cli/internal/daemon" - tea "github.com/charmbracelet/bubbletea" + tea "charm.land/bubbletea/v2" "github.com/charmbracelet/x/ansi" ) @@ -65,7 +65,7 @@ func TestScrollingToTheTopLoadsOlderHistoryInPlace(t *testing.T) { m.Follow = false m.scrollOffset = 1 m.refreshViewportContent() - m, cmd := m.Update(tea.KeyMsg{Type: tea.KeyUp}) + m, cmd := m.Update(tea.KeyPressMsg{Code: tea.KeyUp}) if cmd == nil || !m.loadingOlder { t.Fatal("reaching the top did not ask for older history") } @@ -92,7 +92,7 @@ func TestScrollingToTheTopLoadsOlderHistoryInPlace(t *testing.T) { if !strings.Contains(ansi.Strip(m.Viewport.View()), "older question") { t.Fatal("older page not shown above") } - if _, cmd := m.Update(tea.KeyMsg{Type: tea.KeyUp}); cmd != nil { + if _, cmd := m.Update(tea.KeyPressMsg{Code: tea.KeyUp}); cmd != nil { t.Fatal("asked again with nothing older") } } diff --git a/cli/internal/tui/page_secret_test.go b/cli/internal/tui/page_secret_test.go index d5a462b52..120548364 100644 --- a/cli/internal/tui/page_secret_test.go +++ b/cli/internal/tui/page_secret_test.go @@ -4,8 +4,8 @@ import ( "strings" "testing" - "github.com/charmbracelet/bubbles/textinput" - tea "github.com/charmbracelet/bubbletea" + "charm.land/bubbles/v2/textinput" + tea "charm.land/bubbletea/v2" ) func TestPageSecretInputIsMasked(t *testing.T) { @@ -21,7 +21,7 @@ func TestPageSecretInputIsMasked(t *testing.T) { m.Doc = doc m.Busy = false m.SetSize(80, 24) - m, _ = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'k'}}) + m, _ = m.Update(tea.KeyPressMsg{Code: 'k', Text: "k"}) if m.Mode != modeText || m.TextInput.EchoMode != textinput.EchoPassword { t.Fatalf("secret action should mask input: %+v", m) } diff --git a/cli/internal/tui/page_view.go b/cli/internal/tui/page_view.go index 6740ce7a4..97bb7080b 100644 --- a/cli/internal/tui/page_view.go +++ b/cli/internal/tui/page_view.go @@ -7,10 +7,9 @@ import ( "fmt" "strings" - "github.com/charmbracelet/bubbles/cursor" - "github.com/charmbracelet/bubbles/textinput" - tea "github.com/charmbracelet/bubbletea" - "github.com/charmbracelet/lipgloss" + "charm.land/bubbles/v2/textinput" + tea "charm.land/bubbletea/v2" + "charm.land/lipgloss/v2" "github.com/charmbracelet/x/ansi" ) @@ -102,8 +101,7 @@ type PageViewModel struct { } func NewPageViewModel(conn *daemon.Connection, sessionID, command string) PageViewModel { - ti := textinput.New() - ti.Cursor.SetMode(cursor.CursorStatic) + ti := newTextInput() ti.Prompt = "" return PageViewModel{ Conn: conn, @@ -118,7 +116,7 @@ func NewPageViewModel(conn *daemon.Connection, sessionID, command string) PageVi func (m *PageViewModel) SetSize(width, height int) { m.Width = width m.Height = height - m.TextInput.Width = max(10, width-20) + m.TextInput.SetWidth(max(10, width-20)) } func (m PageViewModel) Init() tea.Cmd { @@ -358,8 +356,8 @@ func (m PageViewModel) Update(msg tea.Msg) (PageViewModel, tea.Cmd) { m.loadPageCmd(m.Generation), ) - case tea.KeyMsg: - if msg.Type == tea.KeyCtrlC || msg.Type == tea.KeyEsc { + case tea.KeyPressMsg: + if msg.String() == "ctrl+c" || msg.String() == "esc" { if m.Mode == modeBrowse { return m, func() tea.Msg { return PageCancelMsg{} } } @@ -384,7 +382,7 @@ func (m PageViewModel) Update(msg tea.Msg) (PageViewModel, tea.Cmd) { switch m.Mode { case modeConfirm: - if msg.Type == tea.KeyEnter && m.CurrentAction != nil { + if msg.String() == "enter" && m.CurrentAction != nil { act := *m.CurrentAction m.CurrentAction = nil m.Mode = modeBrowse @@ -429,12 +427,12 @@ func (m PageViewModel) Update(msg tea.Msg) (PageViewModel, tea.Cmd) { case modeChoice: if m.CurrentAction != nil && len(m.CurrentAction.Options) > 0 { numOpts := len(m.CurrentAction.Options) - switch msg.Type { - case tea.KeyLeft, tea.KeyUp: + switch msg.String() { + case "left", "up": m.ChoiceIndex = (m.ChoiceIndex - 1 + numOpts) % numOpts - case tea.KeyRight, tea.KeyDown: + case "right", "down": m.ChoiceIndex = (m.ChoiceIndex + 1) % numOpts - case tea.KeyEnter: + case "enter": act := *m.CurrentAction chosenOpt := act.Options[m.ChoiceIndex] m.CurrentAction = nil @@ -449,8 +447,8 @@ func (m PageViewModel) Update(msg tea.Msg) (PageViewModel, tea.Cmd) { return m, nil case modeText: - switch msg.Type { - case tea.KeyEnter: + switch msg.String() { + case "enter": val := strings.TrimSpace(m.TextInput.Value()) if val != "" && m.CurrentAction != nil { act := *m.CurrentAction @@ -471,12 +469,12 @@ func (m PageViewModel) Update(msg tea.Msg) (PageViewModel, tea.Cmd) { case modeBrowse: idx := m.currentIndex() - switch msg.Type { - case tea.KeyUp, tea.KeyCtrlP: + switch msg.String() { + case "up", "ctrl+p": if idx > 0 { m.SelectedID = m.Doc.Rows[idx-1].ID } - case tea.KeyDown, tea.KeyCtrlN: + case "down", "ctrl+n": if idx < len(m.Doc.Rows)-1 { m.SelectedID = m.Doc.Rows[idx+1].ID } diff --git a/cli/internal/tui/pending_test.go b/cli/internal/tui/pending_test.go index 6aa6a2371..14b449284 100644 --- a/cli/internal/tui/pending_test.go +++ b/cli/internal/tui/pending_test.go @@ -7,17 +7,13 @@ import ( "time" "albedo/cli/internal/daemon" - tea "github.com/charmbracelet/bubbletea" - "github.com/charmbracelet/lipgloss" + tea "charm.land/bubbletea/v2" "github.com/charmbracelet/x/ansi" - "github.com/muesli/termenv" ) // A message you send shows at once as a greyed-out copy where it will // settle, not as a "sending" row under the transcript. func TestPendingMessageIsAGreyedOutCopyInTheTranscript(t *testing.T) { - lipgloss.SetColorProfile(termenv.ANSI256) - t.Cleanup(func() { lipgloss.SetColorProfile(termenv.Ascii) }) m := NewChatModel(&daemon.Session{ID: "s"}, nil) m.Client = daemon.NewChatClient(daemon.ChatClientOptions{BaseURL: "http://127.0.0.1:1", AgentID: "s"}) m.SetSize(80, 30) @@ -48,8 +44,6 @@ func TestPendingMessageIsAGreyedOutCopyInTheTranscript(t *testing.T) { } func TestDotContinueDoesNotAppearInUI(t *testing.T) { - lipgloss.SetColorProfile(termenv.ANSI256) - t.Cleanup(func() { lipgloss.SetColorProfile(termenv.Ascii) }) m := NewChatModel(&daemon.Session{ID: "s"}, nil) m.Client = daemon.NewChatClient(daemon.ChatClientOptions{BaseURL: "http://127.0.0.1:1", AgentID: "s"}) m.SetSize(80, 30) diff --git a/cli/internal/tui/picker.go b/cli/internal/tui/picker.go index bc8391882..5b7cf4d8f 100644 --- a/cli/internal/tui/picker.go +++ b/cli/internal/tui/picker.go @@ -4,9 +4,8 @@ import ( "github.com/charmbracelet/x/ansi" "strings" - "github.com/charmbracelet/bubbles/cursor" - "github.com/charmbracelet/bubbles/textinput" - tea "github.com/charmbracelet/bubbletea" + "charm.land/bubbles/v2/textinput" + tea "charm.land/bubbletea/v2" ) type PickerItem struct { @@ -34,8 +33,7 @@ type PickerModel struct { } func NewPickerModel(title string, items []PickerItem, withSearch bool, initialSelection string) PickerModel { - ti := textinput.New() - ti.Cursor.SetMode(cursor.CursorStatic) + ti := newTextInput() ti.Placeholder = "" ti.Focus() ti.Prompt = "" @@ -72,7 +70,7 @@ func (m PickerModel) Highlighted() (PickerItem, bool) { func (m *PickerModel) SetSize(width, height int) { m.Width = width m.Height = height - m.SearchInput.Width = max(1, width-8) + m.SearchInput.SetWidth(max(1, width-8)) } func (m *PickerModel) applyFilter() { @@ -165,22 +163,22 @@ func (m PickerModel) Update(msg tea.Msg) (PickerModel, tea.Cmd) { var cmd tea.Cmd switch msg := msg.(type) { - case tea.KeyMsg: - switch msg.Type { - case tea.KeyEsc, tea.KeyCtrlC, tea.KeyCtrlD: + case tea.KeyPressMsg: + switch msg.String() { + case "esc", "ctrl+c", "ctrl+d": return m, func() tea.Msg { return PickerCancelMsg{} } - case tea.KeyEnter: + case "enter": if len(m.Filtered) > 0 && m.Cursor < len(m.Filtered) { selectedID := m.Filtered[m.Cursor].ID return m, func() tea.Msg { return PickerSelectMsg{ID: selectedID} } } return m, nil - case tea.KeyUp, tea.KeyCtrlP: + case "up", "ctrl+p": if m.Cursor > 0 { m.Cursor-- } return m, nil - case tea.KeyDown, tea.KeyCtrlN: + case "down", "ctrl+n": if m.Cursor < len(m.Filtered)-1 { m.Cursor++ } diff --git a/cli/internal/tui/prompt_multiline_test.go b/cli/internal/tui/prompt_multiline_test.go index a74dab5e6..78cbeaf46 100644 --- a/cli/internal/tui/prompt_multiline_test.go +++ b/cli/internal/tui/prompt_multiline_test.go @@ -7,7 +7,7 @@ import ( "testing" "albedo/cli/internal/daemon" - tea "github.com/charmbracelet/bubbletea" + tea "charm.land/bubbletea/v2" "github.com/charmbracelet/x/ansi" ) @@ -22,8 +22,8 @@ func TestPromptMultilineWrappingAndSeparators(t *testing.T) { t.Fatalf("expected initial promptHeight to be 1, got %d", m.promptHeight()) } expectedVpHeight := height - 6 - m.chromeRows() - if m.Viewport.Height != expectedVpHeight { - t.Fatalf("expected viewport height %d, got %d", expectedVpHeight, m.Viewport.Height) + if m.Viewport.Height() != expectedVpHeight { + t.Fatalf("expected viewport height %d, got %d", expectedVpHeight, m.Viewport.Height()) } // Verify view has top separator, prompt, bottom separator, and footer @@ -44,7 +44,7 @@ func TestPromptMultilineWrappingAndSeparators(t *testing.T) { // Now type long text that should wrap to multiple lines longText := "this is a very long prompt sentence that should definitely wrap across multiple lines in a sixty column terminal" for _, r := range longText { - m, _ = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{r}}) + m, _ = m.Update(tea.KeyPressMsg{Code: r, Text: string(r)}) } if m.promptHeight() <= 1 { @@ -53,8 +53,8 @@ func TestPromptMultilineWrappingAndSeparators(t *testing.T) { // Viewport height should have shrunk by (promptHeight - 1) expectedNewVpHeight := height - 6 - m.chromeRows() - if m.Viewport.Height != expectedNewVpHeight { - t.Fatalf("expected viewport height %d, got %d", expectedNewVpHeight, m.Viewport.Height) + if m.Viewport.Height() != expectedNewVpHeight { + t.Fatalf("expected viewport height %d, got %d", expectedNewVpHeight, m.Viewport.Height()) } // Rendered view must still exactly equal terminal height @@ -80,14 +80,14 @@ func TestPromptMultilineWrappingAndSeparators(t *testing.T) { } // Move cursor down one visual line - m, _ = m.Update(tea.KeyMsg{Type: tea.KeyDown}) + m, _ = m.Update(tea.KeyPressMsg{Code: tea.KeyDown}) if m.TextArea.LineInfo().RowOffset != 1 { t.Fatalf("expected rowOffset 1 after KeyDown, got %d", m.TextArea.LineInfo().RowOffset) } // Up key while not on row 0 should move up inside textarea, NOT scroll viewport beforeScroll := m.scrollOffset - m, _ = m.Update(tea.KeyMsg{Type: tea.KeyUp}) + m, _ = m.Update(tea.KeyPressMsg{Code: tea.KeyUp}) if m.TextArea.LineInfo().RowOffset != 0 { t.Fatalf("expected rowOffset 0 after KeyUp, got %d", m.TextArea.LineInfo().RowOffset) } @@ -96,12 +96,12 @@ func TestPromptMultilineWrappingAndSeparators(t *testing.T) { } // Submit should reset prompt back to 1 line and restore viewport height - m, _ = m.Update(tea.KeyMsg{Type: tea.KeyEnter}) + m, _ = m.Update(tea.KeyPressMsg{Code: tea.KeyEnter}) if m.promptHeight() != 1 { t.Fatalf("expected promptHeight to reset to 1 after Enter, got %d", m.promptHeight()) } - if m.Viewport.Height != expectedVpHeight { - t.Fatalf("expected viewport height restored to %d after Enter, got %d", expectedVpHeight, m.Viewport.Height) + if m.Viewport.Height() != expectedVpHeight { + t.Fatalf("expected viewport height restored to %d after Enter, got %d", expectedVpHeight, m.Viewport.Height()) } } @@ -111,16 +111,16 @@ func TestPromptAltEnterNewline(t *testing.T) { // Type first line for _, r := range "hello" { - m, _ = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{r}}) + m, _ = m.Update(tea.KeyPressMsg{Code: r, Text: string(r)}) } if m.promptHeight() != 1 { t.Fatalf("expected promptHeight 1, got %d", m.promptHeight()) } // Press Alt+Enter to insert a newline - m, _ = m.Update(tea.KeyMsg{Type: tea.KeyEnter, Alt: true}) + m, _ = m.Update(tea.KeyPressMsg{Code: tea.KeyEnter, Mod: tea.ModAlt}) for _, r := range "world" { - m, _ = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{r}}) + m, _ = m.Update(tea.KeyPressMsg{Code: r, Text: string(r)}) } if m.promptHeight() != 2 { @@ -139,7 +139,7 @@ func TestPromptWrappingInteractiveKeystrokesNoLossNoBlankBottom(t *testing.T) { text := "this is a line of text that wraps around right now" for _, r := range text { - m, _ = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{r}}) + m, _ = m.Update(tea.KeyPressMsg{Code: r, Text: string(r)}) // In interactive TUI, View() is rendered after every keystroke view := ansi.Strip(m.View()) lines := strings.Split(view, "\n") @@ -176,13 +176,13 @@ func TestPromptPast6LinesScrollsAndHasNoCharLimit(t *testing.T) { t.Fatalf("expected CharLimit to be 0 (unlimited), got %d", m.TextArea.CharLimit) } - altEnter := tea.KeyMsg{Type: tea.KeyEnter, Alt: true} + altEnter := tea.KeyPressMsg{Code: tea.KeyEnter, Mod: tea.ModAlt} // Type 10 lines (exceeds max 6 lines) for i := 1; i <= 10; i++ { lineText := fmt.Sprintf("line %d with plenty of characters to exceed 400 total chars across all lines", i) for _, r := range lineText { - m, _ = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{r}}) + m, _ = m.Update(tea.KeyPressMsg{Code: r, Text: string(r)}) } _ = m.View() if i < 10 { @@ -220,7 +220,7 @@ func TestPromptCtrlGAndEditorFinishedMsg(t *testing.T) { // Pressing Ctrl+G should return a non-nil tea.Cmd var cmd tea.Cmd - m, cmd = m.Update(tea.KeyMsg{Type: tea.KeyCtrlG}) + m, cmd = m.Update(tea.KeyPressMsg{Code: 'g', Mod: tea.ModCtrl}) if cmd == nil { t.Fatal("expected non-nil cmd from KeyCtrlG") } @@ -242,11 +242,9 @@ func TestPromptCtrlGAndEditorFinishedMsg(t *testing.T) { Path: tmp.Name(), Err: nil, }) - if finishCmd == nil { - t.Fatal("expected non-nil cmd restoring mouse mode after editor finished") - } - if finishCmd() != tea.EnableMouseCellMotion() { - t.Fatalf("expected EnableMouseCellMotion msg from editor finished cmd, got %#v", finishCmd()) + // the view declares the mouse mode, so returning from the editor needs no command + if finishCmd != nil { + t.Fatalf("expected nil cmd after editor finished, got %#v", finishCmd()) } // Verify temp file was removed @@ -266,7 +264,6 @@ func TestPromptCtrlGAndEditorFinishedMsg(t *testing.T) { } } - func TestPromptWrappingBoundaryExactMatch(t *testing.T) { input := "can you figure out how to make manual triggers from our ci auth properly with WIF? rn it doesnt..." for width := 40; width <= 130; width++ { @@ -275,7 +272,7 @@ func TestPromptWrappingBoundaryExactMatch(t *testing.T) { m.SetSize(width, height) for _, r := range input { - m, _ = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{r}}) + m, _ = m.Update(tea.KeyPressMsg{Code: r, Text: string(r)}) } view := ansi.Strip(m.View()) @@ -296,4 +293,3 @@ func TestPromptWrappingBoundaryExactMatch(t *testing.T) { } } } - diff --git a/cli/internal/tui/scroll_perf_test.go b/cli/internal/tui/scroll_perf_test.go index 20887548e..6f51219bc 100644 --- a/cli/internal/tui/scroll_perf_test.go +++ b/cli/internal/tui/scroll_perf_test.go @@ -16,7 +16,7 @@ import ( "testing" "time" - tea "github.com/charmbracelet/bubbletea" + tea "charm.land/bubbletea/v2" "github.com/mattn/go-isatty" ) @@ -340,7 +340,7 @@ func runScrollScenario(width, height int, streaming bool, sampleCount int) Scena // Warmup for i := 0; i < 20; i++ { - m, _ = m.Update(tea.MouseMsg{Button: tea.MouseButtonWheelUp}) + m, _ = m.Update(tea.MouseWheelMsg{Button: tea.MouseWheelUp}) _ = m.View() } @@ -386,24 +386,24 @@ func runScrollScenario(width, height int, streaming bool, sampleCount int) Scena // Dynamically generate action to guarantee continuous motion across full buffer var act tea.Msg - maxScroll := max(0, len(m.settledLines)-m.Viewport.Height) + maxScroll := max(0, len(m.settledLines)-m.Viewport.Height()) if scrollDirection < 0 { if m.scrollOffset <= 0 { scrollDirection = 1 - act = tea.MouseMsg{Button: tea.MouseButtonWheelDown} + act = tea.MouseWheelMsg{Button: tea.MouseWheelDown} } else if i%25 == 0 { - act = tea.KeyMsg{Type: tea.KeyPgUp} + act = tea.KeyPressMsg{Code: tea.KeyPgUp} } else { - act = tea.MouseMsg{Button: tea.MouseButtonWheelUp} + act = tea.MouseWheelMsg{Button: tea.MouseWheelUp} } } else { if m.scrollOffset >= maxScroll { scrollDirection = -1 - act = tea.MouseMsg{Button: tea.MouseButtonWheelUp} + act = tea.MouseWheelMsg{Button: tea.MouseWheelUp} } else if i%25 == 0 { - act = tea.KeyMsg{Type: tea.KeyPgDown} + act = tea.KeyPressMsg{Code: tea.KeyPgDown} } else { - act = tea.MouseMsg{Button: tea.MouseButtonWheelDown} + act = tea.MouseWheelMsg{Button: tea.MouseWheelDown} } } @@ -459,7 +459,7 @@ func runScrollScenario(width, height int, streaming bool, sampleCount int) Scena runtime.GC() runtime.ReadMemStats(&memBefore) allocs := testing.AllocsPerRun(benchRuns, func() { - testM, _ := allocSampleModel.Update(tea.KeyMsg{Type: tea.KeyPgUp}) + testM, _ := allocSampleModel.Update(tea.KeyPressMsg{Code: tea.KeyPgUp}) _ = testM.View() }) runtime.ReadMemStats(&memAfter) @@ -625,6 +625,9 @@ func runBubbleTeaProgramEmissionTest() (OutputSyscallResult, error) { wrapper, tea.WithInput(inBuf), tea.WithOutput(writer), + // A pipe reports a 0x0 window, where the renderer draws nothing; use + // the chat's size so emission stays measurable. + tea.WithWindowSize(120, 40), tea.WithFPS(120), tea.WithoutSignals(), tea.WithoutSignalHandler(), @@ -644,9 +647,9 @@ func runBubbleTeaProgramEmissionTest() (OutputSyscallResult, error) { for i := 0; i < totalEvents; i++ { <-ticker.C if i%2 == 0 { - p.Send(tea.KeyMsg{Type: tea.KeyPgUp}) + p.Send(tea.KeyPressMsg{Code: tea.KeyPgUp}) } else { - p.Send(tea.KeyMsg{Type: tea.KeyPgDown}) + p.Send(tea.KeyPressMsg{Code: tea.KeyPgDown}) } } @@ -814,7 +817,7 @@ func (w bubbleTeaBenchmarkWrapper) Init() tea.Cmd { } func (w bubbleTeaBenchmarkWrapper) Update(msg tea.Msg) (tea.Model, tea.Cmd) { - if _, ok := msg.(tea.KeyMsg); ok { + if _, ok := msg.(tea.KeyPressMsg); ok { w.eventsLeft-- if w.eventsLeft <= 0 { return w, tea.Quit @@ -825,8 +828,8 @@ func (w bubbleTeaBenchmarkWrapper) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return w, cmd } -func (w bubbleTeaBenchmarkWrapper) View() string { - return w.chat.View() +func (w bubbleTeaBenchmarkWrapper) View() tea.View { + return tea.NewView(w.chat.View()) } // Standard Go Benchmarks @@ -837,8 +840,8 @@ func BenchmarkScroll_UpdateView_120x40_Settled(b *testing.B) { m.SetSize(120, 40) buildRealisticHistory(&m) - upMsg := tea.KeyMsg{Type: tea.KeyPgUp} - downMsg := tea.KeyMsg{Type: tea.KeyPgDown} + upMsg := tea.KeyPressMsg{Code: tea.KeyPgUp} + downMsg := tea.KeyPressMsg{Code: tea.KeyPgDown} b.ResetTimer() b.ReportAllocs() @@ -858,8 +861,8 @@ func BenchmarkScroll_UpdateView_180x60_Settled(b *testing.B) { m.SetSize(180, 60) buildRealisticHistory(&m) - upMsg := tea.KeyMsg{Type: tea.KeyPgUp} - downMsg := tea.KeyMsg{Type: tea.KeyPgDown} + upMsg := tea.KeyPressMsg{Code: tea.KeyPgUp} + downMsg := tea.KeyPressMsg{Code: tea.KeyPgDown} b.ResetTimer() b.ReportAllocs() @@ -879,8 +882,8 @@ func BenchmarkScroll_UpdateView_120x40_Streaming(b *testing.B) { m.SetSize(120, 40) buildRealisticHistory(&m) - upMsg := tea.KeyMsg{Type: tea.KeyPgUp} - downMsg := tea.KeyMsg{Type: tea.KeyPgDown} + upMsg := tea.KeyPressMsg{Code: tea.KeyPgUp} + downMsg := tea.KeyPressMsg{Code: tea.KeyPgDown} b.ResetTimer() b.ReportAllocs() @@ -907,8 +910,8 @@ func BenchmarkScroll_UpdateView_180x60_Streaming(b *testing.B) { m.SetSize(180, 60) buildRealisticHistory(&m) - upMsg := tea.KeyMsg{Type: tea.KeyPgUp} - downMsg := tea.KeyMsg{Type: tea.KeyPgDown} + upMsg := tea.KeyPressMsg{Code: tea.KeyPgUp} + downMsg := tea.KeyPressMsg{Code: tea.KeyPgDown} b.ResetTimer() b.ReportAllocs() diff --git a/cli/internal/tui/session_viewer.go b/cli/internal/tui/session_viewer.go index cc74c902d..9818a6c89 100644 --- a/cli/internal/tui/session_viewer.go +++ b/cli/internal/tui/session_viewer.go @@ -7,7 +7,7 @@ import ( "strings" "time" - tea "github.com/charmbracelet/bubbletea" + tea "charm.land/bubbletea/v2" "github.com/charmbracelet/x/ansi" ) @@ -90,8 +90,10 @@ type SessionViewer struct { func NewSessionViewer(workspace string) SessionViewer { p := NewPickerModel("", sessionViewerActions(workspace), true, "new") p.SearchInput.Placeholder = "search sessions, models, folders…" - p.SearchInput.PlaceholderStyle = DefaultStyles.Faint - p.SearchInput.Cursor.Style = DefaultStyles.Cursor + st := p.SearchInput.Styles() + st.Focused.Placeholder = DefaultStyles.Faint + st.Blurred.Placeholder = DefaultStyles.Faint + p.SearchInput.SetStyles(st) return SessionViewer{ PickerModel: p, Workspace: workspace, @@ -119,7 +121,7 @@ func (m *SessionViewer) LoadPrefs(path string) { func (m *SessionViewer) SetSize(width, height int) { m.PickerModel.SetSize(width, height) - m.SearchInput.Width = max(1, width-8) + m.SearchInput.SetWidth(max(1, width-8)) } func (m SessionViewer) clock() time.Time { @@ -423,37 +425,37 @@ func (m SessionViewer) Update(msg tea.Msg) (SessionViewer, tea.Cmd) { return m, m.fetchPreview(msg.ID) } return m, nil - case tea.KeyMsg: + case tea.KeyPressMsg: if m.ConfirmDelete != "" { id := m.ConfirmDelete m.ConfirmDelete = "" - if msg.Type == tea.KeyRunes && string(msg.Runes) == "y" { + if msg.Text == "y" { return m, func() tea.Msg { return SessionDeleteMsg{ID: id} } } return m, nil } - if m.ArchiveView && msg.Type == tea.KeyEsc { + if m.ArchiveView && msg.String() == "esc" { m.CloseArchive() return m, nil } - switch msg.Type { - case tea.KeyCtrlD: + switch msg.String() { + case "ctrl+d": if m.ArchiveView { if item, ok := m.Highlighted(); ok { m.ConfirmDelete = item.ID } } return m, nil - case tea.KeyCtrlA: + case "ctrl+a": m.toggleArchive() return m, nil - case tea.KeyCtrlS: + case "ctrl+s": m.togglePin() return m, nil - case tea.KeyTab, tea.KeyShiftTab: + case "tab", "shift+tab": m.switchGroup() return m, m.previewAfter(before.ID) - case tea.KeyLeft, tea.KeyRight: + case "left", "right": // Arrows edit the query once there is one. if m.SearchInput.Value() == "" { m.switchGroup() diff --git a/cli/internal/tui/session_viewer_test.go b/cli/internal/tui/session_viewer_test.go index 7658e89eb..c51829141 100644 --- a/cli/internal/tui/session_viewer_test.go +++ b/cli/internal/tui/session_viewer_test.go @@ -8,7 +8,7 @@ import ( "testing" "time" - tea "github.com/charmbracelet/bubbletea" + tea "charm.land/bubbletea/v2" "github.com/charmbracelet/x/ansi" ) @@ -23,7 +23,7 @@ func TestSessionViewerSearchAndRefresh(t *testing.T) { if item, _ := m.Highlighted(); item.ID != "first" { t.Fatalf("initial selection: %q", item.ID) } - m, _ = m.Update(tea.KeyMsg{Type: tea.KeyDown}) + m, _ = m.Update(tea.KeyPressMsg{Code: tea.KeyDown}) if item, _ := m.Highlighted(); item.ID != "second" { t.Fatalf("navigation: %q", item.ID) } @@ -156,16 +156,16 @@ func TestSessionViewerFavouritesColumnAndPins(t *testing.T) { if item, _ := m.Highlighted(); item.ID != "today" { t.Fatalf("initial highlight: %s", item.ID) } - m, _ = m.Update(tea.KeyMsg{Type: tea.KeyTab}) + m, _ = m.Update(tea.KeyPressMsg{Code: tea.KeyTab}) if item, _ := m.Highlighted(); item.ID != "pin" { t.Fatalf("tab to favourites: %s", item.ID) } - m, _ = m.Update(tea.KeyMsg{Type: tea.KeyRight}) + m, _ = m.Update(tea.KeyPressMsg{Code: tea.KeyRight}) if item, _ := m.Highlighted(); item.ID != "today" { t.Fatalf("right to recent: %s", item.ID) } - m, _ = m.Update(tea.KeyMsg{Type: tea.KeyCtrlS}) + m, _ = m.Update(tea.KeyPressMsg{Code: 's', Mod: tea.ModCtrl}) if m.section["today"] != secPinned { t.Fatal("ctrl+s did not pin") } @@ -205,7 +205,7 @@ func TestSessionViewerPreviewFetchesOnSettleAndRenders(t *testing.T) { m.SetSize(120, 30) m.SetSessions(sessions, nil) - m, cmd := m.Update(tea.KeyMsg{Type: tea.KeyDown}) + m, cmd := m.Update(tea.KeyPressMsg{Code: tea.KeyDown}) if cmd == nil { t.Fatal("moving did not schedule a preview") } @@ -275,7 +275,7 @@ func TestSessionViewerArchiveRestoreAndDeleteConfirmation(t *testing.T) { m.LoadPrefs(path) m.SetSessions([]daemon.Session{{ID: "one", Title: "Keep me"}, {ID: "two", Title: "Archive me"}}, nil) m.focus("two") - m, _ = m.Update(tea.KeyMsg{Type: tea.KeyCtrlA}) + m, _ = m.Update(tea.KeyPressMsg{Code: 'a', Mod: tea.ModCtrl}) if item, _ := m.Highlighted(); item.ID != "one" { t.Fatalf("archiving jumped to %q instead of neighboring session", item.ID) } @@ -289,20 +289,20 @@ func TestSessionViewerArchiveRestoreAndDeleteConfirmation(t *testing.T) { if len(reloaded.Filtered) != 1 || reloaded.Filtered[0].ID != "two" { t.Fatalf("archive: %+v", reloaded.Filtered) } - reloaded, _ = reloaded.Update(tea.KeyMsg{Type: tea.KeyCtrlD}) + reloaded, _ = reloaded.Update(tea.KeyPressMsg{Code: 'd', Mod: tea.ModCtrl}) if reloaded.ConfirmDelete != "two" { t.Fatal("deletion must request confirmation") } - reloaded, cmd := reloaded.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'n'}}) + reloaded, cmd := reloaded.Update(tea.KeyPressMsg{Code: 'n', Text: "n"}) if cmd != nil || reloaded.ConfirmDelete != "" { t.Fatal("cancellation deleted session") } - reloaded, _ = reloaded.Update(tea.KeyMsg{Type: tea.KeyCtrlD}) - reloaded, cmd = reloaded.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'y'}}) + reloaded, _ = reloaded.Update(tea.KeyPressMsg{Code: 'd', Mod: tea.ModCtrl}) + reloaded, cmd = reloaded.Update(tea.KeyPressMsg{Code: 'y', Text: "y"}) if msg, ok := cmd().(SessionDeleteMsg); !ok || msg.ID != "two" { t.Fatalf("confirmation: %v", msg) } - reloaded, _ = reloaded.Update(tea.KeyMsg{Type: tea.KeyCtrlA}) + reloaded, _ = reloaded.Update(tea.KeyPressMsg{Code: 'a', Mod: tea.ModCtrl}) if reloaded.prefs.archived("two") || len(reloaded.Filtered) != 0 { t.Fatal("restore should remove from archive") } @@ -317,12 +317,12 @@ func TestSessionViewerArchiveKeepsNearbySelection(t *testing.T) { m.SetSessions([]daemon.Session{{ID: "one"}, {ID: "two"}, {ID: "three"}}, nil) m.focus("two") index := m.Cursor - m, _ = m.Update(tea.KeyMsg{Type: tea.KeyCtrlA}) + m, _ = m.Update(tea.KeyPressMsg{Code: 'a', Mod: tea.ModCtrl}) if item, _ := m.Highlighted(); item.ID != "three" || m.Cursor != index { t.Fatalf("expected next session at index %d, got %+v at %d", index, item, m.Cursor) } m.OpenArchive() - m, _ = m.Update(tea.KeyMsg{Type: tea.KeyCtrlA}) + m, _ = m.Update(tea.KeyPressMsg{Code: 'a', Mod: tea.ModCtrl}) if len(m.Filtered) != 0 || m.Cursor != 0 { t.Fatalf("empty archive cursor: %d", m.Cursor) } diff --git a/cli/internal/tui/session_viewer_view.go b/cli/internal/tui/session_viewer_view.go index e5702d2b8..2038eb4d1 100644 --- a/cli/internal/tui/session_viewer_view.go +++ b/cli/internal/tui/session_viewer_view.go @@ -7,7 +7,7 @@ import ( "strings" "time" - "github.com/charmbracelet/lipgloss" + "charm.land/lipgloss/v2" "github.com/charmbracelet/x/ansi" ) diff --git a/cli/internal/tui/theme.go b/cli/internal/tui/theme.go index 5bf8f7a56..f62bb22aa 100644 --- a/cli/internal/tui/theme.go +++ b/cli/internal/tui/theme.go @@ -2,11 +2,14 @@ package tui import ( "fmt" + "image/color" "os" "path/filepath" "strings" - "github.com/charmbracelet/lipgloss" + "charm.land/bubbles/v2/textinput" + tea "charm.land/bubbletea/v2" + "charm.land/lipgloss/v2" "github.com/charmbracelet/x/ansi" ) @@ -87,25 +90,45 @@ func useInk(detected ink) { DefaultStyles.Selected = lipgloss.NewStyle().Background(lipgloss.Color(detected.surface)) } +// newTextInput is a text input in the theme: plain text and prompt whether +// focused or not, and a reverse-video cursor that holds still, so an idle +// input never wakes the program to blink. +func newTextInput() textinput.Model { + ti := textinput.New() + s := ti.Styles() + s.Focused.Prompt, s.Focused.Text = lipgloss.NewStyle(), lipgloss.NewStyle() + s.Blurred = s.Focused + s.Cursor = textinput.CursorStyle{Shape: tea.CursorBlock} + ti.SetStyles(s) + return ti +} + +// fitInputs sizes form fields to the columns their rows leave for a value. +// A textinput without a width shows only the first rune of its placeholder. +func fitInputs(inputs map[string]*textinput.Model, width int) { + for _, input := range inputs { + input.SetWidth(max(1, width)) + } +} + const ( ansiReset = "\x1b[0m" ansiItalic = "\x1b[3m" ansiGray = "\x1b[90m" ) -// sgr is a foreground color as an escape sequence for the active color -// profile, or fallback when the ramp is unknown. +// sgr is a foreground color as an escape sequence, or fallback when the +// ramp is unknown. Bubble Tea downsamples it to the terminal's profile. func sgr(hex, fallback string) string { return sgrLayer(hex, fallback, false) } func sgrLayer(hex, fallback string, background bool) string { - if hex == "" { + if parseHex(hex) == nil { return fallback } - seq := lipgloss.ColorProfile().Color(hex).Sequence(background) - if seq == "" { - return "" + if background { + return ansi.NewStyle().BackgroundColor(lipgloss.Color(hex)).String() } - return "\x1b[" + seq + "m" + return ansi.NewStyle().ForegroundColor(lipgloss.Color(hex)).String() } // codeInk steps code down from prose so a reply that decorates every @@ -132,7 +155,7 @@ func keepBackground(s string) string { // gradient is the brand ramp at t in [0, 1], or nil when the terminal did // not report the colors it is mixed from. -func gradient(t float64) lipgloss.TerminalColor { +func gradient(t float64) color.Color { from, to := parseHex(transcriptInk.brandFrom), parseHex(transcriptInk.brandTo) if from == nil || to == nil { return nil diff --git a/cli/internal/tui/transcript.go b/cli/internal/tui/transcript.go index 1ee02a58b..419c57716 100644 --- a/cli/internal/tui/transcript.go +++ b/cli/internal/tui/transcript.go @@ -2,9 +2,9 @@ package tui import ( "albedo/cli/internal/daemon" + "charm.land/lipgloss/v2" "encoding/json" "fmt" - "github.com/charmbracelet/lipgloss" "github.com/charmbracelet/x/ansi" "regexp" "strconv" diff --git a/cli/internal/tui/tree_picker.go b/cli/internal/tui/tree_picker.go index 0c0839309..960bdc965 100644 --- a/cli/internal/tui/tree_picker.go +++ b/cli/internal/tui/tree_picker.go @@ -8,7 +8,7 @@ import ( "regexp" "strings" - tea "github.com/charmbracelet/bubbletea" + tea "charm.land/bubbletea/v2" ) var whitespaceRegex = regexp.MustCompile(`[\p{Cc}\p{Cf}\p{Z}]+`) @@ -184,8 +184,8 @@ func (m TreePickerModel) Update(msg tea.Msg) (TreePickerModel, tea.Cmd) { return TreeForkSuccessMsg{Session: branch} } - case tea.KeyMsg: - if msg.Type == tea.KeyEsc || msg.Type == tea.KeyCtrlC || msg.Type == tea.KeyCtrlD { + case tea.KeyPressMsg: + if msg.String() == "esc" || msg.String() == "ctrl+c" || msg.String() == "ctrl+d" { if m.Confirming { m.Confirming = false m.Error = "" @@ -199,7 +199,7 @@ func (m TreePickerModel) Update(msg tea.Msg) (TreePickerModel, tea.Cmd) { } if m.Confirming { - if msg.Type == tea.KeyEnter && len(m.Checkpoints) > m.Cursor { + if msg.String() == "enter" && len(m.Checkpoints) > m.Cursor { cp := m.Checkpoints[m.Cursor] m.Forking = true m.ForkError = "" @@ -210,16 +210,16 @@ func (m TreePickerModel) Update(msg tea.Msg) (TreePickerModel, tea.Cmd) { return m, nil } - switch msg.Type { - case tea.KeyUp, tea.KeyCtrlP: + switch msg.String() { + case "up", "ctrl+p": if m.Cursor > 0 { m.Cursor-- } - case tea.KeyDown, tea.KeyCtrlN: + case "down", "ctrl+n": if m.Cursor < len(m.Checkpoints)-1 { m.Cursor++ } - case tea.KeyLeft, tea.KeyPgUp: + case "left", "pgup": if m.PageIndex > 0 { m.PageIndex-- m.Loading = true @@ -227,7 +227,7 @@ func (m TreePickerModel) Update(msg tea.Msg) (TreePickerModel, tea.Cmd) { m.Generation++ return m, m.loadTreeCmd(m.Cursors[m.PageIndex], m.Generation) } - case tea.KeyRight, tea.KeyPgDown: + case "right", "pgdown": if m.HasMore && m.NextCursor != nil { next := *m.NextCursor m.Cursors = append(m.Cursors[:m.PageIndex+1], next) @@ -237,7 +237,7 @@ func (m TreePickerModel) Update(msg tea.Msg) (TreePickerModel, tea.Cmd) { m.Generation++ return m, m.loadTreeCmd(next, m.Generation) } - case tea.KeyEnter: + case "enter": if len(m.Checkpoints) > 0 && m.Cursor < len(m.Checkpoints) { m.ForkError = "" m.Confirming = true diff --git a/cli/internal/tui/webhooks_page.go b/cli/internal/tui/webhooks_page.go index e4024ec2e..c65462481 100644 --- a/cli/internal/tui/webhooks_page.go +++ b/cli/internal/tui/webhooks_page.go @@ -10,8 +10,8 @@ import ( "sort" "strings" - "github.com/charmbracelet/bubbles/textinput" - tea "github.com/charmbracelet/bubbletea" + "charm.land/bubbles/v2/textinput" + tea "charm.land/bubbletea/v2" "github.com/charmbracelet/x/ansi" ) @@ -299,7 +299,7 @@ func (m WebhooksPageModel) Update(msg tea.Msg) (WebhooksPageModel, tea.Cmd) { m.Loading = true m.Generation++ return m, m.loadCmd(m.Generation) - case tea.KeyMsg: + case tea.KeyPressMsg: if m.Saving { return m, nil } @@ -311,13 +311,13 @@ func (m WebhooksPageModel) Update(msg tea.Msg) (WebhooksPageModel, tea.Cmd) { } else { m.Error, m.Notice = "", "secret copied" } - case msg.Type == tea.KeyEnter || msg.Type == tea.KeyEsc: + case msg.String() == "enter" || msg.String() == "esc": m.Reveal = nil } return m, nil } if m.Form != nil { - if msg.Type == tea.KeyEsc { + if msg.String() == "esc" { m.Form = nil m.Error = "" return m, nil @@ -342,7 +342,7 @@ func (m WebhooksPageModel) Update(msg tea.Msg) (WebhooksPageModel, tea.Cmd) { confirm := m.Confirm m.Confirm = "" hook := m.selected() - if msg.Type != tea.KeyEnter || hook == nil { + if msg.String() != "enter" || hook == nil { return m, nil } if confirm == "delete" { @@ -350,7 +350,7 @@ func (m WebhooksPageModel) Update(msg tea.Msg) (WebhooksPageModel, tea.Cmd) { } return m.begin("new secret for "+hook.Name, [2]string{"rotate", hook.ID}) } - if msg.Type == tea.KeyEsc || msg.Type == tea.KeyCtrlC { + if msg.String() == "esc" || msg.String() == "ctrl+c" { return m, func() tea.Msg { return WebhooksPageDoneMsg{} } } if m.Loading { @@ -366,51 +366,54 @@ func (m WebhooksPageModel) Update(msg tea.Msg) (WebhooksPageModel, tea.Cmd) { return m, nil } hook := m.selected() - switch msg.Type { - case tea.KeyUp, tea.KeyCtrlP: + switch msg.String() { + case "up", "ctrl+p": m.Cursor = max(0, m.Cursor-1) - case tea.KeyDown, tea.KeyCtrlN: + case "down", "ctrl+n": m.Cursor = min(max(0, len(m.Hooks)-1), m.Cursor+1) - case tea.KeyEnter: + case "enter": if hook != nil { m.Error, m.Notice = "", "" m.Form = newWebhookForm(hook, m.Sessions, m.SessionID) } - case tea.KeySpace: + case "space": if hook != nil { if hook.Enabled { return m.begin(hook.Name+" off · deliveries now answer 404", [2]string{"disable", hook.ID}) } return m.begin(hook.Name+" on", [2]string{"enable", hook.ID}) } - case tea.KeyRunes: - switch msg.String() { - case "n": - m.Error, m.Notice = "", "" - m.Form = newWebhookForm(nil, m.Sessions, m.SessionID) - case "a": - if m.AgentManagement { - return m.begin("this session's agent can no longer manage its hooks", [2]string{"agent_off", ""}) - } - return m.begin("this session's agent can now manage its own hooks", [2]string{"agent_on", ""}) - case "d": - if hook != nil { - m.Confirm = "delete" - } - case "k": - if hook != nil { - m.Confirm = "rotate" - } - case "y": - if hook != nil { - if err := CopyText(m.address(*hook)); err != nil { - m.Error = "copy failed: " + err.Error() - } else { - m.Error, m.Notice = "", "url copied" - } + case "n": + m.Error, m.Notice = "", "" + m.Form = newWebhookForm(nil, m.Sessions, m.SessionID) + case "a": + if m.AgentManagement { + return m.begin("this session's agent can no longer manage its hooks", [2]string{"agent_off", ""}) + } + return m.begin("this session's agent can now manage its own hooks", [2]string{"agent_on", ""}) + case "d": + if hook != nil { + m.Confirm = "delete" + } + case "k": + if hook != nil { + m.Confirm = "rotate" + } + case "y": + if hook != nil { + if err := CopyText(m.address(*hook)); err != nil { + m.Error = "copy failed: " + err.Error() + } else { + m.Error, m.Notice = "", "url copied" } } } + case tea.PasteMsg: + if m.Saving || m.Reveal != nil || m.Form == nil { + return m, nil + } + _, cmd := m.Form.update(msg) + return m, cmd } return m, nil } @@ -583,7 +586,7 @@ var ( func newWebhookForm(editing *webhookEntry, sessions []daemon.Session, current string) *webhookForm { f := &webhookForm{Inputs: map[string]*textinput.Model{}, Sessions: sessions, Current: current, Chosen: current} for _, key := range hookFields { - input := textinput.New() + input := newTextInput() input.Prompt = "" input.CharLimit = 4096 f.Inputs[key] = &input @@ -652,39 +655,43 @@ func (f *webhookForm) chosenIndex(matches []daemon.Session) int { return -1 } -// update handles one key; submit reports that the form should be saved. -func (f *webhookForm) update(msg tea.KeyMsg) (submit bool, cmd tea.Cmd) { - switch msg.Type { - case tea.KeyTab, tea.KeyDown: - f.move(1) - return false, nil - case tea.KeyShiftTab, tea.KeyUp: - f.move(-1) - return false, nil - case tea.KeyCtrlS: - return true, nil - case tea.KeyEnter: - if f.Focus == len(hookFields)-1 { +// update handles one key or paste; submit reports that the form should be saved. +func (f *webhookForm) update(msg tea.Msg) (submit bool, cmd tea.Cmd) { + if key, ok := msg.(tea.KeyPressMsg); ok { + switch key.String() { + case "tab", "down": + f.move(1) + return false, nil + case "shift+tab", "up": + f.move(-1) + return false, nil + case "ctrl+s": return true, nil + case "enter": + if f.Focus == len(hookFields)-1 { + return true, nil + } + f.move(1) + return false, nil } - f.move(1) - return false, nil } if f.current() == hookFieldSession { - matches := f.matches() - if (msg.Type == tea.KeyLeft || msg.Type == tea.KeyRight) && len(matches) > 0 { - step := 1 - if msg.Type == tea.KeyLeft { - step = -1 - } - i := f.chosenIndex(matches) - if i < 0 { - i = 0 - } else { - i = (i + step + len(matches)) % len(matches) + if key, ok := msg.(tea.KeyPressMsg); ok && (key.String() == "left" || key.String() == "right") { + matches := f.matches() + if len(matches) > 0 { + step := 1 + if key.String() == "left" { + step = -1 + } + i := f.chosenIndex(matches) + if i < 0 { + i = 0 + } else { + i = (i + step + len(matches)) % len(matches) + } + f.Chosen = matches[i].ID + return false, nil } - f.Chosen = matches[i].ID - return false, nil } } input := f.Inputs[f.current()] @@ -744,6 +751,7 @@ func (f *webhookForm) view(width int) []string { if f.Editing != nil { title = "edit " + f.Editing.Name } + fitInputs(f.Inputs, width-14) rows := []string{DefaultStyles.Bold.Render(title)} indent := strings.Repeat(" ", 13) for i, key := range hookFields { diff --git a/cli/internal/tui/webhooks_page_test.go b/cli/internal/tui/webhooks_page_test.go index abc8ae52c..6aedb4de1 100644 --- a/cli/internal/tui/webhooks_page_test.go +++ b/cli/internal/tui/webhooks_page_test.go @@ -5,7 +5,7 @@ import ( "strings" "testing" - tea "github.com/charmbracelet/bubbletea" + tea "charm.land/bubbletea/v2" "github.com/charmbracelet/x/ansi" ) @@ -55,7 +55,7 @@ func TestWebhookFormSetsSignatureOnTheCreatedHook(t *testing.T) { func TestWebhookEditOnlySendsWhatChanged(t *testing.T) { m := loadedWebhooksPage(t) - m, _ = m.Update(tea.KeyMsg{Type: tea.KeyEnter}) + m, _ = m.Update(tea.KeyPressMsg{Code: tea.KeyEnter}) if m.Form == nil || m.Form.current() != hookFieldSecret || m.Form.Chosen != "s" { t.Fatal("enter should edit the selected hook, starting at its secret") } @@ -79,11 +79,11 @@ func TestGeneratedSecretIsShownUntilDismissed(t *testing.T) { if !strings.Contains(m.View(), "whsec_generated") { t.Fatal("generated secret was not shown") } - m, _ = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'d'}}) + m, _ = m.Update(tea.KeyPressMsg{Code: 'd', Text: "d"}) if m.Reveal == nil || m.Confirm != "" { t.Fatal("keys other than enter must not dismiss the secret") } - m, _ = m.Update(tea.KeyMsg{Type: tea.KeyEnter}) + m, _ = m.Update(tea.KeyPressMsg{Code: tea.KeyEnter}) if m.Reveal != nil || strings.Contains(m.View(), "whsec_generated") { t.Fatal("secret should be gone once dismissed") } @@ -99,24 +99,24 @@ func TestLongSessionTitlesKeepTheirPlace(t *testing.T) { func TestWebhookFormPicksTheSessionToWake(t *testing.T) { m := loadedWebhooksPage(t) - m, _ = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'n'}}) + m, _ = m.Update(tea.KeyPressMsg{Code: 'n', Text: "n"}) if m.Form.Chosen != "s" || !strings.Contains(ansi.Strip(m.View()), "session this session · infra bot · /srv/infra") { t.Fatalf("the form should default to the session it was opened from:\n%s", ansi.Strip(m.View())) } - m, _ = m.Update(tea.KeyMsg{Type: tea.KeyShiftTab}) + m, _ = m.Update(tea.KeyPressMsg{Code: tea.KeyTab, Mod: tea.ModShift}) for _, r := range "release" { - m, _ = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{r}}) + m, _ = m.Update(tea.KeyPressMsg{Code: r, Text: string(r)}) } if m.Form.Chosen != "t" { t.Fatalf("filtering should choose the matching session, got %q", m.Form.Chosen) } - m, _ = m.Update(tea.KeyMsg{Type: tea.KeyBackspace}) + m, _ = m.Update(tea.KeyPressMsg{Code: tea.KeyBackspace}) m.Form.Inputs[hookFieldSession].SetValue("") - m, _ = m.Update(tea.KeyMsg{Type: tea.KeyLeft}) + m, _ = m.Update(tea.KeyPressMsg{Code: tea.KeyLeft}) if m.Form.Chosen != "s" { t.Fatalf("← should step back to the first session, got %q", m.Form.Chosen) } - m, _ = m.Update(tea.KeyMsg{Type: tea.KeyRight}) + m, _ = m.Update(tea.KeyPressMsg{Code: tea.KeyRight}) m.Form.Inputs[hookFieldName].SetValue("notes") steps, notice, err := m.Form.steps() if err != nil || steps[0] != [2]string{"create_in", "t notes"} || !strings.Contains(notice, "release notes") { -- knotmirror 0.0.1