diff --git a/README.md b/README.md index e361fb51..f10944d2 100644 --- a/README.md +++ b/README.md @@ -436,8 +436,10 @@ func NewModel() Model { } } -func (m Model) Init() tea.Cmd { - return m.form.Init() +func (m Model) Init() (tea.Model, tea.Cmd) { + form, cmd := m.form.Init() + m.form = form.(*huh.Form) + return m, cmd } func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { @@ -470,14 +472,14 @@ Tea example][example]. [example]: https://github.com/charmbracelet/huh/blob/main/examples/bubbletea/main.go ## `Huh?` in the Wild -For some `Huh?` programs in production, see: -* [glyphs](https://github.com/maaslalani/glyphs): a unicode symbol picker -* [meteor](https://github.com/stefanlogue/meteor): a highly customisable conventional commit message tool -* [freeze](https://github.com/charmbracelet/freeze): a tool for generating images of code and terminal output -* [gum](https://github.com/charmbracelet/gum): a tool for glamorous shell scripts -* [savvy](https://github.com/getsavvyinc/savvy-cli): the easiest way to create, share, and run runbooks in the terminal +For some `Huh?` programs in production, see: +- [glyphs](https://github.com/maaslalani/glyphs): a unicode symbol picker +- [meteor](https://github.com/stefanlogue/meteor): a highly customisable conventional commit message tool +- [freeze](https://github.com/charmbracelet/freeze): a tool for generating images of code and terminal output +- [gum](https://github.com/charmbracelet/gum): a tool for glamorous shell scripts +- [savvy](https://github.com/getsavvyinc/savvy-cli): the easiest way to create, share, and run runbooks in the terminal ## Feedback diff --git a/examples/accessibility/main.go b/examples/accessibility/main.go index af356363..20ad6f74 100644 --- a/examples/accessibility/main.go +++ b/examples/accessibility/main.go @@ -3,7 +3,7 @@ package main import ( "log" - "github.com/charmbracelet/huh" + "github.com/charmbracelet/huh/v2" ) func main() { diff --git a/examples/bubbletea/main.go b/examples/bubbletea/main.go index 75c6b4a5..507246c1 100644 --- a/examples/bubbletea/main.go +++ b/examples/bubbletea/main.go @@ -5,8 +5,8 @@ import ( "os" "strings" - tea "github.com/charmbracelet/bubbletea" - "github.com/charmbracelet/huh" + tea "github.com/charmbracelet/bubbletea/v2" + "github.com/charmbracelet/huh/v2" "github.com/charmbracelet/lipgloss" ) @@ -106,8 +106,10 @@ func NewModel() Model { return m } -func (m Model) Init() tea.Cmd { - return m.form.Init() +func (m Model) Init() (tea.Model, tea.Cmd) { + form, cmd := m.form.Init() + m.form = form.(*huh.Form) + return m, cmd } func min(x, y int) int { diff --git a/examples/burger/main.go b/examples/burger/main.go index e8b88c57..26d93bec 100644 --- a/examples/burger/main.go +++ b/examples/burger/main.go @@ -8,8 +8,8 @@ import ( "strings" "time" - "github.com/charmbracelet/huh" - "github.com/charmbracelet/huh/spinner" + "github.com/charmbracelet/huh/v2" + "github.com/charmbracelet/huh/v2/spinner" "github.com/charmbracelet/lipgloss" xstrings "github.com/charmbracelet/x/exp/strings" ) diff --git a/examples/conditional/main.go b/examples/conditional/main.go index 98de37e1..34f6550c 100644 --- a/examples/conditional/main.go +++ b/examples/conditional/main.go @@ -4,7 +4,7 @@ import ( "fmt" "os" - "github.com/charmbracelet/huh" + "github.com/charmbracelet/huh/v2" ) type consumable int diff --git a/examples/dynamic/dynamic-all/main.go b/examples/dynamic/dynamic-all/main.go index a5c75c0d..a26dbe83 100644 --- a/examples/dynamic/dynamic-all/main.go +++ b/examples/dynamic/dynamic-all/main.go @@ -4,7 +4,7 @@ import ( "log" "strconv" - "github.com/charmbracelet/huh" + "github.com/charmbracelet/huh/v2" ) func main() { diff --git a/examples/dynamic/dynamic-count/main.go b/examples/dynamic/dynamic-count/main.go index 4223f6fd..398dd57f 100644 --- a/examples/dynamic/dynamic-count/main.go +++ b/examples/dynamic/dynamic-count/main.go @@ -6,7 +6,7 @@ import ( "log" "strconv" - "github.com/charmbracelet/huh" + "github.com/charmbracelet/huh/v2" ) func main() { diff --git a/examples/dynamic/dynamic-country/main.go b/examples/dynamic/dynamic-country/main.go index 76b56f0d..9043a359 100644 --- a/examples/dynamic/dynamic-country/main.go +++ b/examples/dynamic/dynamic-country/main.go @@ -6,7 +6,7 @@ import ( "github.com/charmbracelet/log" - "github.com/charmbracelet/huh" + "github.com/charmbracelet/huh/v2" ) func main() { diff --git a/examples/dynamic/dynamic-increment/main.go b/examples/dynamic/dynamic-increment/main.go index 87322631..a907b884 100644 --- a/examples/dynamic/dynamic-increment/main.go +++ b/examples/dynamic/dynamic-increment/main.go @@ -4,7 +4,7 @@ import ( "fmt" "time" - "github.com/charmbracelet/huh" + "github.com/charmbracelet/huh/v2" ) func main() { diff --git a/examples/dynamic/dynamic-markdown/main.go b/examples/dynamic/dynamic-markdown/main.go index c353db98..ff197bed 100644 --- a/examples/dynamic/dynamic-markdown/main.go +++ b/examples/dynamic/dynamic-markdown/main.go @@ -4,7 +4,7 @@ import ( "log" "github.com/charmbracelet/glamour" - "github.com/charmbracelet/huh" + "github.com/charmbracelet/huh/v2" ) func main() { diff --git a/examples/dynamic/dynamic-name/main.go b/examples/dynamic/dynamic-name/main.go index 99bdca53..e9e62095 100644 --- a/examples/dynamic/dynamic-name/main.go +++ b/examples/dynamic/dynamic-name/main.go @@ -4,7 +4,7 @@ import ( "fmt" "log" - "github.com/charmbracelet/huh" + "github.com/charmbracelet/huh/v2" ) func main() { diff --git a/examples/dynamic/dynamic-suggestions/main.go b/examples/dynamic/dynamic-suggestions/main.go index b161f604..bf6e9de9 100644 --- a/examples/dynamic/dynamic-suggestions/main.go +++ b/examples/dynamic/dynamic-suggestions/main.go @@ -4,8 +4,8 @@ import ( "fmt" "log" - "github.com/charmbracelet/huh" - "github.com/charmbracelet/huh/spinner" + "github.com/charmbracelet/huh/v2" + "github.com/charmbracelet/huh/v2/spinner" ) func main() { diff --git a/examples/filepicker/main.go b/examples/filepicker/main.go index ca786168..3ec3137d 100644 --- a/examples/filepicker/main.go +++ b/examples/filepicker/main.go @@ -1,7 +1,7 @@ package main import ( - "github.com/charmbracelet/huh" + "github.com/charmbracelet/huh/v2" ) func main() { diff --git a/examples/gh/create.go b/examples/gh/create.go index eb19568b..2e82335f 100644 --- a/examples/gh/create.go +++ b/examples/gh/create.go @@ -5,8 +5,8 @@ import ( "log" "os" - "github.com/charmbracelet/huh" - "github.com/charmbracelet/huh/spinner" + "github.com/charmbracelet/huh/v2" + "github.com/charmbracelet/huh/v2/spinner" "github.com/charmbracelet/lipgloss" ) diff --git a/examples/git/main.go b/examples/git/main.go index 06a94f97..70702c46 100644 --- a/examples/git/main.go +++ b/examples/git/main.go @@ -1,7 +1,7 @@ package main import ( - "github.com/charmbracelet/huh" + "github.com/charmbracelet/huh/v2" ) // types is the possible commit types specified by the conventional commit spec. diff --git a/examples/go.mod b/examples/go.mod index a6a4af35..d4e2061c 100644 --- a/examples/go.mod +++ b/examples/go.mod @@ -3,11 +3,11 @@ module examples go 1.22 require ( - github.com/charmbracelet/bubbles v0.20.0 - github.com/charmbracelet/bubbletea v1.1.1 + github.com/charmbracelet/bubbles/v2 v2.0.0-alpha.1 + github.com/charmbracelet/bubbletea/v2 v2.0.0-alpha.1 github.com/charmbracelet/glamour v0.8.0 - github.com/charmbracelet/huh v0.0.0-00010101000000-000000000000 - github.com/charmbracelet/huh/spinner v0.0.0-00010101000000-000000000000 + github.com/charmbracelet/huh/v2 v2.0.0-00010101000000-000000000000 + github.com/charmbracelet/huh/v2/spinner v0.0.0-00010101000000-000000000000 github.com/charmbracelet/lipgloss v0.13.0 github.com/charmbracelet/log v0.4.0 github.com/charmbracelet/ssh v0.0.0-20240725163421-eb71b85b27aa @@ -22,6 +22,7 @@ require ( github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect github.com/aymerick/douceur v0.2.0 // indirect github.com/catppuccin/go v0.2.0 // indirect + github.com/charmbracelet/bubbletea v1.1.1 // indirect github.com/charmbracelet/harmonica v0.2.0 // indirect github.com/charmbracelet/keygen v0.5.1 // indirect github.com/charmbracelet/x/ansi v0.3.2 // indirect @@ -30,6 +31,7 @@ require ( github.com/charmbracelet/x/input v0.2.0 // indirect github.com/charmbracelet/x/term v0.2.0 // indirect github.com/charmbracelet/x/termios v0.1.0 // indirect + github.com/charmbracelet/x/windows v0.2.0 // indirect github.com/creack/pty v1.1.21 // indirect github.com/dlclark/regexp2 v1.11.0 // indirect github.com/dustin/go-humanize v1.0.1 // indirect @@ -59,6 +61,6 @@ require ( golang.org/x/text v0.18.0 // indirect ) -replace github.com/charmbracelet/huh => ../ +replace github.com/charmbracelet/huh/v2 => ../ -replace github.com/charmbracelet/huh/spinner => ../spinner +replace github.com/charmbracelet/huh/v2/spinner => ../spinner diff --git a/examples/go.sum b/examples/go.sum index ec8f274d..b0386290 100644 --- a/examples/go.sum +++ b/examples/go.sum @@ -18,10 +18,12 @@ github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuP github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4= github.com/catppuccin/go v0.2.0 h1:ktBeIrIP42b/8FGiScP9sgrWOss3lw0Z5SktRoithGA= github.com/catppuccin/go v0.2.0/go.mod h1:8IHJuMGaUUjQM82qBrGNBv7LFq6JI3NnQCF6MOlZjpc= -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/bubbles/v2 v2.0.0-alpha.1 h1:4Am/U9zvRBZ5iSIDeNioGrc9N9+4U2AjiRJBttAwUVc= +github.com/charmbracelet/bubbles/v2 v2.0.0-alpha.1/go.mod h1:rq09SZbh77FFBMvKi5k2vGXJ7K4u0GjLqmUby3K3los= github.com/charmbracelet/bubbletea v1.1.1 h1:KJ2/DnmpfqFtDNVTvYZ6zpPFL9iRCRr0qqKOCvppbPY= github.com/charmbracelet/bubbletea v1.1.1/go.mod h1:9Ogk0HrdbHolIKHdjfFpyXJmiCzGwy+FesYkZr7hYU4= +github.com/charmbracelet/bubbletea/v2 v2.0.0-alpha.1 h1:OZtpLCsuuPplC+1oyUo+/eAN7e9MC2UyZWKlKrVlUnw= +github.com/charmbracelet/bubbletea/v2 v2.0.0-alpha.1/go.mod h1:j0gn4ft5CE7NDYNZjAA3hBM8t2OPjI8urxuAD0oR4w8= github.com/charmbracelet/glamour v0.8.0 h1:tPrjL3aRcQbn++7t18wOpgLyl8wrOHUEDS7IZ68QtZs= github.com/charmbracelet/glamour v0.8.0/go.mod h1:ViRgmKkf3u5S7uakt2czJ272WSg2ZenlYEZXT2x7Bjw= github.com/charmbracelet/harmonica v0.2.0 h1:8NxJWRWg/bzKqqEaaeFNipOu77YR5t8aSwG4pgaUBiQ= @@ -52,6 +54,8 @@ github.com/charmbracelet/x/term v0.2.0 h1:cNB9Ot9q8I711MyZ7myUR5HFWL/lc3OpU8jZ4h github.com/charmbracelet/x/term v0.2.0/go.mod h1:GVxgxAbjUrmpvIINHIQnJJKpMlHiZ4cktEQCN6GWyF0= github.com/charmbracelet/x/termios v0.1.0 h1:y4rjAHeFksBAfGbkRDmVinMg7x7DELIGAFbdNvxg97k= github.com/charmbracelet/x/termios v0.1.0/go.mod h1:H/EVv/KRnrYjz+fCYa9bsKdqF3S8ouDK0AZEbG7r+/U= +github.com/charmbracelet/x/windows v0.2.0 h1:ilXA1GJjTNkgOm94CLPeSz7rar54jtFatdmoiONPuEw= +github.com/charmbracelet/x/windows v0.2.0/go.mod h1:ZibNFR49ZFqCXgP76sYanisxRyC+EYrBE7TTknD8s1s= github.com/creack/pty v1.1.21 h1:1/QdRyBaHHJP61QkWMXlOIBfsgdDeeKfK8SYVUWJKf0= github.com/creack/pty v1.1.21/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= diff --git a/examples/gum/main.go b/examples/gum/main.go index eb17a395..560cbd30 100644 --- a/examples/gum/main.go +++ b/examples/gum/main.go @@ -4,7 +4,7 @@ import ( "fmt" "os" - "github.com/charmbracelet/huh" + "github.com/charmbracelet/huh/v2" ) func main() { diff --git a/examples/help/main.go b/examples/help/main.go index 28ac6031..1d38eae4 100644 --- a/examples/help/main.go +++ b/examples/help/main.go @@ -1,6 +1,6 @@ package main -import "github.com/charmbracelet/huh" +import "github.com/charmbracelet/huh/v2" func main() { f := huh.NewForm( diff --git a/examples/hide/main.go b/examples/hide/main.go index 66c542a5..943c080d 100644 --- a/examples/hide/main.go +++ b/examples/hide/main.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/charmbracelet/huh" + "github.com/charmbracelet/huh/v2" ) func main() { diff --git a/examples/layout/columns/main.go b/examples/layout/columns/main.go index 62217fa4..3c41b6b4 100644 --- a/examples/layout/columns/main.go +++ b/examples/layout/columns/main.go @@ -1,6 +1,6 @@ package main -import "github.com/charmbracelet/huh" +import "github.com/charmbracelet/huh/v2" func main() { form := huh.NewForm( diff --git a/examples/layout/default/main.go b/examples/layout/default/main.go index 0ea2ba67..920b8c09 100644 --- a/examples/layout/default/main.go +++ b/examples/layout/default/main.go @@ -1,6 +1,6 @@ package main -import "github.com/charmbracelet/huh" +import "github.com/charmbracelet/huh/v2" func main() { form := huh.NewForm( diff --git a/examples/layout/grid/main.go b/examples/layout/grid/main.go index 55c5283f..02c98f2a 100644 --- a/examples/layout/grid/main.go +++ b/examples/layout/grid/main.go @@ -1,6 +1,6 @@ package main -import "github.com/charmbracelet/huh" +import "github.com/charmbracelet/huh/v2" func main() { form := huh.NewForm( diff --git a/examples/layout/stack/main.go b/examples/layout/stack/main.go index 34b7a801..1cbabe24 100644 --- a/examples/layout/stack/main.go +++ b/examples/layout/stack/main.go @@ -1,6 +1,6 @@ package main -import "github.com/charmbracelet/huh" +import "github.com/charmbracelet/huh/v2" func main() { form := huh.NewForm( diff --git a/examples/multiple-groups/main.go b/examples/multiple-groups/main.go index fb1353ad..85320634 100644 --- a/examples/multiple-groups/main.go +++ b/examples/multiple-groups/main.go @@ -4,7 +4,7 @@ import ( "fmt" "os" - "github.com/charmbracelet/huh" + "github.com/charmbracelet/huh/v2" ) func main() { diff --git a/examples/readme/confirm/main.go b/examples/readme/confirm/main.go index ebbb3360..7541575b 100644 --- a/examples/readme/confirm/main.go +++ b/examples/readme/confirm/main.go @@ -1,7 +1,7 @@ package main import ( - "github.com/charmbracelet/huh" + "github.com/charmbracelet/huh/v2" ) func main() { diff --git a/examples/readme/input/main.go b/examples/readme/input/main.go index 69eebcc0..886b0cf2 100644 --- a/examples/readme/input/main.go +++ b/examples/readme/input/main.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/charmbracelet/huh" + "github.com/charmbracelet/huh/v2" ) func isFood(_ string) error { diff --git a/examples/readme/main/main.go b/examples/readme/main/main.go index 068046e5..bb9cd6e2 100644 --- a/examples/readme/main/main.go +++ b/examples/readme/main/main.go @@ -3,7 +3,7 @@ package main import ( "log" - "github.com/charmbracelet/huh" + "github.com/charmbracelet/huh/v2" ) // TODO: ensure input is not plagiarized. diff --git a/examples/readme/multiselect/main.go b/examples/readme/multiselect/main.go index 5f66840b..6fe1863a 100644 --- a/examples/readme/multiselect/main.go +++ b/examples/readme/multiselect/main.go @@ -1,6 +1,6 @@ package main -import "github.com/charmbracelet/huh" +import "github.com/charmbracelet/huh/v2" func main() { var toppings []string diff --git a/examples/readme/note/main.go b/examples/readme/note/main.go index cc6511c4..262506e9 100644 --- a/examples/readme/note/main.go +++ b/examples/readme/note/main.go @@ -1,6 +1,6 @@ package main -import "github.com/charmbracelet/huh" +import "github.com/charmbracelet/huh/v2" func main() { note := huh.NewNote().Description( diff --git a/examples/readme/select/main.go b/examples/readme/select/main.go index f5c81aa5..850e1080 100644 --- a/examples/readme/select/main.go +++ b/examples/readme/select/main.go @@ -1,6 +1,6 @@ package main -import "github.com/charmbracelet/huh" +import "github.com/charmbracelet/huh/v2" func main() { var country string diff --git a/examples/readme/select/scroll/scroll.go b/examples/readme/select/scroll/scroll.go index 20e0907e..d0d7db65 100644 --- a/examples/readme/select/scroll/scroll.go +++ b/examples/readme/select/scroll/scroll.go @@ -1,6 +1,6 @@ package main -import "github.com/charmbracelet/huh" +import "github.com/charmbracelet/huh/v2" type Pokemon struct { id int diff --git a/examples/readme/text/main.go b/examples/readme/text/main.go index c0ff7e2c..9f51c0a7 100644 --- a/examples/readme/text/main.go +++ b/examples/readme/text/main.go @@ -1,6 +1,6 @@ package main -import "github.com/charmbracelet/huh" +import "github.com/charmbracelet/huh/v2" // TODO: ensure input is not plagiarized. func checkForPlagiarism(s string) error { return nil } diff --git a/examples/scroll/main.go b/examples/scroll/main.go index cb14cfc5..d5ab81bb 100644 --- a/examples/scroll/main.go +++ b/examples/scroll/main.go @@ -1,6 +1,6 @@ package main -import "github.com/charmbracelet/huh" +import "github.com/charmbracelet/huh/v2" func main() { form := huh.NewForm( diff --git a/examples/skip/main.go b/examples/skip/main.go index b5553b4e..3d8d9fb9 100644 --- a/examples/skip/main.go +++ b/examples/skip/main.go @@ -1,7 +1,7 @@ package main import ( - "github.com/charmbracelet/huh" + "github.com/charmbracelet/huh/v2" ) func main() { diff --git a/examples/ssh-form/main.go b/examples/ssh-form/main.go index cc991a38..094e66ab 100644 --- a/examples/ssh-form/main.go +++ b/examples/ssh-form/main.go @@ -12,8 +12,8 @@ import ( "syscall" "time" - tea "github.com/charmbracelet/bubbletea" - "github.com/charmbracelet/huh" + tea "github.com/charmbracelet/bubbletea/v2" + "github.com/charmbracelet/huh/v2" "github.com/charmbracelet/lipgloss" "github.com/charmbracelet/log" "github.com/charmbracelet/ssh" @@ -102,11 +102,13 @@ type model struct { loggedIn bool } -func (m model) Init() tea.Cmd { +func (m model) Init() (tea.Model, tea.Cmd) { if m.form == nil { - return nil + return m, nil } - return m.form.Init() + form, cmd := m.form.Init() + m.form = form.(*huh.Form) + return m, cmd } func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { diff --git a/examples/stickers/main.go b/examples/stickers/main.go index 91052110..ce104e41 100644 --- a/examples/stickers/main.go +++ b/examples/stickers/main.go @@ -1,7 +1,7 @@ package main import ( - "github.com/charmbracelet/huh" + "github.com/charmbracelet/huh/v2" ) func main() { diff --git a/examples/tea-options/main.go b/examples/tea-options/main.go index 05aae201..6b310df3 100644 --- a/examples/tea-options/main.go +++ b/examples/tea-options/main.go @@ -3,8 +3,8 @@ package main import ( "fmt" - tea "github.com/charmbracelet/bubbletea" - "github.com/charmbracelet/huh" + tea "github.com/charmbracelet/bubbletea/v2" + "github.com/charmbracelet/huh/v2" ) func main() { diff --git a/examples/theme/main.go b/examples/theme/main.go index 14cb37c1..6ede9cc6 100644 --- a/examples/theme/main.go +++ b/examples/theme/main.go @@ -4,7 +4,7 @@ import ( "fmt" "os" - "github.com/charmbracelet/huh" + "github.com/charmbracelet/huh/v2" ) func main() { diff --git a/examples/timer/main.go b/examples/timer/main.go index 811d6661..07ab4dbb 100644 --- a/examples/timer/main.go +++ b/examples/timer/main.go @@ -5,9 +5,9 @@ import ( "strings" "time" - "github.com/charmbracelet/bubbles/progress" - tea "github.com/charmbracelet/bubbletea" - "github.com/charmbracelet/huh" + "github.com/charmbracelet/bubbles/v2/progress" + tea "github.com/charmbracelet/bubbletea/v2" + "github.com/charmbracelet/huh/v2" "github.com/charmbracelet/lipgloss" ) @@ -50,8 +50,10 @@ type Model struct { progress progress.Model } -func (m Model) Init() tea.Cmd { - return m.form.Init() +func (m Model) Init() (tea.Model, tea.Cmd) { + form, cmd := m.form.Init() + m.form = form.(*huh.Form) + return m, cmd } const tickInterval = time.Second / 2 diff --git a/field_confirm.go b/field_confirm.go index 708033fc..5acaf4a1 100644 --- a/field_confirm.go +++ b/field_confirm.go @@ -4,9 +4,9 @@ import ( "fmt" "strings" - "github.com/charmbracelet/bubbles/key" - tea "github.com/charmbracelet/bubbletea" - "github.com/charmbracelet/huh/accessibility" + "github.com/charmbracelet/bubbles/v2/key" + tea "github.com/charmbracelet/bubbletea/v2" + "github.com/charmbracelet/huh/v2/accessibility" "github.com/charmbracelet/lipgloss" ) @@ -154,8 +154,8 @@ func (c *Confirm) KeyBinds() []key.Binding { } // Init initializes the confirm field. -func (c *Confirm) Init() tea.Cmd { - return nil +func (c *Confirm) Init() (tea.Model, tea.Cmd) { + return c, nil } // Update updates the confirm field. diff --git a/field_filepicker.go b/field_filepicker.go index 5f1bb5ce..2eec5d71 100644 --- a/field_filepicker.go +++ b/field_filepicker.go @@ -8,10 +8,10 @@ import ( xstrings "github.com/charmbracelet/x/exp/strings" - "github.com/charmbracelet/bubbles/filepicker" - "github.com/charmbracelet/bubbles/key" - tea "github.com/charmbracelet/bubbletea" - "github.com/charmbracelet/huh/accessibility" + "github.com/charmbracelet/bubbles/v2/filepicker" + "github.com/charmbracelet/bubbles/v2/key" + tea "github.com/charmbracelet/bubbletea/v2" + "github.com/charmbracelet/huh/v2/accessibility" "github.com/charmbracelet/lipgloss" ) @@ -47,7 +47,7 @@ func NewFilePicker() *FilePicker { fp.ShowSize = false fp.AutoHeight = false - if cmd := fp.Init(); cmd != nil { + if _, cmd := fp.Init(); cmd != nil { fp, _ = fp.Update(cmd()) } @@ -61,7 +61,7 @@ func NewFilePicker() *FilePicker { // CurrentDirectory sets the directory of the file field. func (f *FilePicker) CurrentDirectory(directory string) *FilePicker { f.picker.CurrentDirectory = directory - if cmd := f.picker.Init(); cmd != nil { + if _, cmd := f.picker.Init(); cmd != nil { f.picker, _ = f.picker.Update(cmd()) } return f @@ -179,7 +179,9 @@ func (f *FilePicker) Zoom() bool { // Focus focuses the file field. func (f *FilePicker) Focus() tea.Cmd { f.focused = true - return f.picker.Init() + var cmd tea.Cmd + f.picker, cmd = f.picker.Init() + return cmd } // Blur blurs the file field. @@ -196,8 +198,10 @@ func (f *FilePicker) KeyBinds() []key.Binding { } // Init initializes the file field. -func (f *FilePicker) Init() tea.Cmd { - return f.picker.Init() +func (f *FilePicker) Init() (tea.Model, tea.Cmd) { + var cmd tea.Cmd + f.picker, cmd = f.picker.Init() + return f, cmd } // Update updates the file field. @@ -212,7 +216,9 @@ func (f *FilePicker) Update(msg tea.Msg) (tea.Model, tea.Cmd) { break } f.setPicking(true) - return f, f.picker.Init() + var cmd tea.Cmd + f.picker, cmd = f.picker.Init() + return f, cmd case key.Matches(msg, f.keymap.Close): f.setPicking(false) return f, NextField diff --git a/field_input.go b/field_input.go index 3510d527..8e0e8d0e 100644 --- a/field_input.go +++ b/field_input.go @@ -4,10 +4,10 @@ import ( "fmt" "strings" - "github.com/charmbracelet/bubbles/key" - "github.com/charmbracelet/bubbles/textinput" - tea "github.com/charmbracelet/bubbletea" - "github.com/charmbracelet/huh/accessibility" + "github.com/charmbracelet/bubbles/v2/key" + "github.com/charmbracelet/bubbles/v2/textinput" + tea "github.com/charmbracelet/bubbletea/v2" + "github.com/charmbracelet/huh/v2/accessibility" "github.com/charmbracelet/lipgloss" ) @@ -263,9 +263,9 @@ func (i *Input) KeyBinds() []key.Binding { } // Init initializes the input field. -func (i *Input) Init() tea.Cmd { +func (i *Input) Init() (tea.Model, tea.Cmd) { i.textinput.Blur() - return nil + return i, nil } // Update updates the input field. diff --git a/field_multiselect.go b/field_multiselect.go index faa33ee5..4e1ed58d 100644 --- a/field_multiselect.go +++ b/field_multiselect.go @@ -5,12 +5,12 @@ import ( "strings" "time" - "github.com/charmbracelet/bubbles/key" - "github.com/charmbracelet/bubbles/spinner" - "github.com/charmbracelet/bubbles/textinput" - "github.com/charmbracelet/bubbles/viewport" - tea "github.com/charmbracelet/bubbletea" - "github.com/charmbracelet/huh/accessibility" + "github.com/charmbracelet/bubbles/v2/key" + "github.com/charmbracelet/bubbles/v2/spinner" + "github.com/charmbracelet/bubbles/v2/textinput" + "github.com/charmbracelet/bubbles/v2/viewport" + tea "github.com/charmbracelet/bubbletea/v2" + "github.com/charmbracelet/huh/v2/accessibility" "github.com/charmbracelet/lipgloss" ) @@ -247,8 +247,8 @@ func (m *MultiSelect[T]) KeyBinds() []key.Binding { } // Init initializes the multi-select field. -func (m *MultiSelect[T]) Init() tea.Cmd { - return nil +func (m *MultiSelect[T]) Init() (tea.Model, tea.Cmd) { + return m, nil } // Update updates the multi-select field. diff --git a/field_note.go b/field_note.go index c93125f0..8c02030f 100644 --- a/field_note.go +++ b/field_note.go @@ -4,8 +4,8 @@ import ( "fmt" "strings" - "github.com/charmbracelet/bubbles/key" - tea "github.com/charmbracelet/bubbletea" + "github.com/charmbracelet/bubbles/v2/key" + tea "github.com/charmbracelet/bubbletea/v2" ) // Note is a note field. @@ -157,7 +157,7 @@ func (n *Note) KeyBinds() []key.Binding { } // Init initializes the note field. -func (n *Note) Init() tea.Cmd { return nil } +func (n *Note) Init() (tea.Model, tea.Cmd) { return n, nil } // Update updates the note field. func (n *Note) Update(msg tea.Msg) (tea.Model, tea.Cmd) { diff --git a/field_select.go b/field_select.go index 81e57d9e..beb96e35 100644 --- a/field_select.go +++ b/field_select.go @@ -5,12 +5,12 @@ import ( "strings" "time" - "github.com/charmbracelet/bubbles/key" - "github.com/charmbracelet/bubbles/spinner" - "github.com/charmbracelet/bubbles/textinput" - "github.com/charmbracelet/bubbles/viewport" - tea "github.com/charmbracelet/bubbletea" - "github.com/charmbracelet/huh/accessibility" + "github.com/charmbracelet/bubbles/v2/key" + "github.com/charmbracelet/bubbles/v2/spinner" + "github.com/charmbracelet/bubbles/v2/textinput" + "github.com/charmbracelet/bubbles/v2/viewport" + tea "github.com/charmbracelet/bubbletea/v2" + "github.com/charmbracelet/huh/v2/accessibility" "github.com/charmbracelet/lipgloss" ) @@ -298,8 +298,8 @@ func (s *Select[T]) KeyBinds() []key.Binding { } // Init initializes the select field. -func (s *Select[T]) Init() tea.Cmd { - return nil +func (s *Select[T]) Init() (tea.Model, tea.Cmd) { + return s, nil } // Update updates the select field. diff --git a/field_text.go b/field_text.go index a5c3a40c..5a559f9c 100644 --- a/field_text.go +++ b/field_text.go @@ -6,10 +6,10 @@ import ( "os/exec" "strings" - "github.com/charmbracelet/bubbles/key" - "github.com/charmbracelet/bubbles/textarea" - tea "github.com/charmbracelet/bubbletea" - "github.com/charmbracelet/huh/accessibility" + "github.com/charmbracelet/bubbles/v2/key" + "github.com/charmbracelet/bubbles/v2/textarea" + tea "github.com/charmbracelet/bubbletea/v2" + "github.com/charmbracelet/huh/v2/accessibility" "github.com/charmbracelet/lipgloss" ) @@ -243,9 +243,9 @@ func (t *Text) KeyBinds() []key.Binding { type updateValueMsg []byte // Init initializes the text field. -func (t *Text) Init() tea.Cmd { +func (t *Text) Init() (tea.Model, tea.Cmd) { t.textarea.Blur() - return nil + return t, nil } // Update updates the text field. diff --git a/form.go b/form.go index e1afb0d2..96bd4da1 100644 --- a/form.go +++ b/form.go @@ -9,10 +9,10 @@ import ( "sync" "time" - "github.com/charmbracelet/bubbles/help" - "github.com/charmbracelet/bubbles/key" - tea "github.com/charmbracelet/bubbletea" - "github.com/charmbracelet/huh/internal/selector" + "github.com/charmbracelet/bubbles/v2/help" + "github.com/charmbracelet/bubbles/v2/key" + tea "github.com/charmbracelet/bubbletea/v2" + "github.com/charmbracelet/huh/v2/internal/selector" ) const defaultWidth = 80 @@ -130,7 +130,7 @@ func NewForm(groups ...*Group) *Form { // Each field implements the Bubble Tea Model interface. type Field interface { // Bubble Tea Model - Init() tea.Cmd + Init() (tea.Model, tea.Cmd) Update(tea.Msg) (tea.Model, tea.Cmd) View() string @@ -480,13 +480,13 @@ func (f *Form) PrevField() tea.Cmd { } // Init initializes the form. -func (f *Form) Init() tea.Cmd { +func (f *Form) Init() (tea.Model, tea.Cmd) { cmds := make([]tea.Cmd, f.selector.Total()) f.selector.Range(func(i int, group *Group) bool { if i == 0 { group.active = true } - cmds[i] = group.Init() + _, cmds[i] = group.Init() return true }) @@ -494,7 +494,7 @@ func (f *Form) Init() tea.Cmd { cmds = append(cmds, nextGroup) } - return tea.Batch(cmds...) + return f, tea.Batch(cmds...) } // Update updates the form. @@ -566,7 +566,8 @@ func (f *Form) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } } f.selector.Selected().active = true - return f, f.selector.Selected().Init() + _, cmd := f.selector.Selected().Init() + return f, cmd case prevGroupMsg: if len(group.Errors()) > 0 { @@ -581,7 +582,8 @@ func (f *Form) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } f.selector.Selected().active = true - return f, f.selector.Selected().Init() + _, cmd := f.selector.Selected().Init() + return f, cmd } m, cmd := group.Update(msg) diff --git a/go.mod b/go.mod index bf43157a..b8fd580f 100644 --- a/go.mod +++ b/go.mod @@ -1,11 +1,11 @@ -module github.com/charmbracelet/huh +module github.com/charmbracelet/huh/v2 go 1.21 require ( github.com/catppuccin/go v0.2.0 - github.com/charmbracelet/bubbles v0.20.0 - github.com/charmbracelet/bubbletea v1.1.1 + github.com/charmbracelet/bubbles/v2 v2.0.0-alpha.1 + github.com/charmbracelet/bubbletea/v2 v2.0.0-alpha.1 github.com/charmbracelet/lipgloss v0.13.0 github.com/charmbracelet/x/ansi v0.3.2 github.com/charmbracelet/x/exp/strings v0.0.0-20240722160745-212f7b056ed0 @@ -16,17 +16,16 @@ require ( github.com/atotto/clipboard v0.1.4 // indirect github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect github.com/charmbracelet/x/term v0.2.0 // indirect + github.com/charmbracelet/x/windows v0.2.0 // indirect github.com/dustin/go-humanize v1.0.1 // indirect - github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect github.com/mattn/go-isatty v0.0.20 // indirect - github.com/mattn/go-localereader v0.0.1 // indirect github.com/mattn/go-runewidth v0.0.16 // indirect github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect github.com/muesli/cancelreader v0.2.2 // indirect github.com/muesli/termenv v0.15.3-0.20240618155329-98d742f6907a // indirect github.com/rivo/uniseg v0.4.7 // indirect + github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect golang.org/x/sync v0.8.0 // indirect golang.org/x/sys v0.25.0 // indirect - golang.org/x/text v0.18.0 // indirect ) diff --git a/go.sum b/go.sum index 78dad43e..e48e2dc8 100644 --- a/go.sum +++ b/go.sum @@ -6,10 +6,10 @@ github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiE github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= github.com/catppuccin/go v0.2.0 h1:ktBeIrIP42b/8FGiScP9sgrWOss3lw0Z5SktRoithGA= github.com/catppuccin/go v0.2.0/go.mod h1:8IHJuMGaUUjQM82qBrGNBv7LFq6JI3NnQCF6MOlZjpc= -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.1.1 h1:KJ2/DnmpfqFtDNVTvYZ6zpPFL9iRCRr0qqKOCvppbPY= -github.com/charmbracelet/bubbletea v1.1.1/go.mod h1:9Ogk0HrdbHolIKHdjfFpyXJmiCzGwy+FesYkZr7hYU4= +github.com/charmbracelet/bubbles/v2 v2.0.0-alpha.1 h1:4Am/U9zvRBZ5iSIDeNioGrc9N9+4U2AjiRJBttAwUVc= +github.com/charmbracelet/bubbles/v2 v2.0.0-alpha.1/go.mod h1:rq09SZbh77FFBMvKi5k2vGXJ7K4u0GjLqmUby3K3los= +github.com/charmbracelet/bubbletea/v2 v2.0.0-alpha.1 h1:OZtpLCsuuPplC+1oyUo+/eAN7e9MC2UyZWKlKrVlUnw= +github.com/charmbracelet/bubbletea/v2 v2.0.0-alpha.1/go.mod h1:j0gn4ft5CE7NDYNZjAA3hBM8t2OPjI8urxuAD0oR4w8= github.com/charmbracelet/lipgloss v0.13.0 h1:4X3PPeoWEDCMvzDvGmTajSyYPcZM4+y8sCA/SsA3cjw= github.com/charmbracelet/lipgloss v0.13.0/go.mod h1:nw4zy0SBX/F/eAO1cWdcvy6qnkDUxr8Lw7dvFrAIbbY= github.com/charmbracelet/x/ansi v0.3.2 h1:wsEwgAN+C9U06l9dCVMX0/L3x7ptvY1qmjMwyfE6USY= @@ -18,16 +18,14 @@ github.com/charmbracelet/x/exp/strings v0.0.0-20240722160745-212f7b056ed0 h1:qko github.com/charmbracelet/x/exp/strings v0.0.0-20240722160745-212f7b056ed0/go.mod h1:pBhA0ybfXv6hDjQUZ7hk1lVxBiUbupdw5R31yPUViVQ= github.com/charmbracelet/x/term v0.2.0 h1:cNB9Ot9q8I711MyZ7myUR5HFWL/lc3OpU8jZ4hwm0x0= github.com/charmbracelet/x/term v0.2.0/go.mod h1:GVxgxAbjUrmpvIINHIQnJJKpMlHiZ4cktEQCN6GWyF0= +github.com/charmbracelet/x/windows v0.2.0 h1:ilXA1GJjTNkgOm94CLPeSz7rar54jtFatdmoiONPuEw= +github.com/charmbracelet/x/windows v0.2.0/go.mod h1:ZibNFR49ZFqCXgP76sYanisxRyC+EYrBE7TTknD8s1s= github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= -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/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= github.com/lucasb-eyer/go-colorful v1.2.0/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.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc= github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mitchellh/hashstructure/v2 v2.0.2 h1:vGKWl0YJqUNxE8d+h8f6NJLcCJrgbhC4NcD46KavDd4= @@ -41,11 +39,12 @@ github.com/muesli/termenv v0.15.3-0.20240618155329-98d742f6907a/go.mod h1:hxSnBB 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/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no= +github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM= +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/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= -golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= diff --git a/group.go b/group.go index d890751b..2fa0a604 100644 --- a/group.go +++ b/group.go @@ -3,10 +3,10 @@ package huh import ( "strings" - "github.com/charmbracelet/bubbles/help" - "github.com/charmbracelet/bubbles/viewport" - tea "github.com/charmbracelet/bubbletea" - "github.com/charmbracelet/huh/internal/selector" + "github.com/charmbracelet/bubbles/v2/help" + "github.com/charmbracelet/bubbles/v2/viewport" + tea "github.com/charmbracelet/bubbletea/v2" + "github.com/charmbracelet/huh/v2/internal/selector" "github.com/charmbracelet/lipgloss" ) @@ -187,7 +187,7 @@ func PrevField() tea.Msg { } // Init initializes the group. -func (g *Group) Init() tea.Cmd { +func (g *Group) Init() (tea.Model, tea.Cmd) { var cmds []tea.Cmd if g.selector.Selected().Skip() { @@ -196,7 +196,7 @@ func (g *Group) Init() tea.Cmd { } else if g.selector.OnFirst() { cmds = append(cmds, g.nextField()...) } - return tea.Batch(cmds...) + return g, tea.Batch(cmds...) } if g.active { @@ -204,7 +204,7 @@ func (g *Group) Init() tea.Cmd { cmds = append(cmds, cmd) } g.buildView() - return tea.Batch(cmds...) + return g, tea.Batch(cmds...) } // nextField moves to the next field. diff --git a/huh_test.go b/huh_test.go index 57288b3b..30aa3037 100644 --- a/huh_test.go +++ b/huh_test.go @@ -10,7 +10,7 @@ import ( "testing" "time" - tea "github.com/charmbracelet/bubbletea" + tea "github.com/charmbracelet/bubbletea/v2" "github.com/charmbracelet/lipgloss" "github.com/charmbracelet/x/ansi" ) @@ -106,7 +106,8 @@ func TestForm(t *testing.T) { ), ) - f.Update(f.Init()) + _, cmd := f.Init() + f.Update(cmd) view := ansi.Strip(f.View()) @@ -141,8 +142,10 @@ func TestForm(t *testing.T) { } // Attempt to select hard shell and retrieve error. - m, _ := f.Update(keys('j')) - m, _ = m.Update(tea.KeyMsg{Type: tea.KeyTab}) + m, _ := f.Update(keypress('j')) + m, _ = m.Update(tea.KeyPressMsg(tea.Key{ + Code: tea.KeyTab, + })) view = ansi.Strip(m.View()) if !strings.Contains(view, "* we're out of hard shells, sorry") { @@ -150,9 +153,11 @@ func TestForm(t *testing.T) { t.Error("Expected form to show out of hard shells error") } - m, _ = m.Update(keys('k')) + m, _ = m.Update(keypress('k')) - m, cmd := m.Update(tea.KeyMsg{Type: tea.KeyEnter}) + m, cmd = m.Update(tea.KeyPressMsg(tea.Key{ + Code: tea.KeyEnter, + })) m = batchUpdate(m, cmd) view = ansi.Strip(m.View()) @@ -163,7 +168,9 @@ func TestForm(t *testing.T) { } // batchMsg + nextGroup - m, cmd = m.Update(tea.KeyMsg{Type: tea.KeyEnter}) + m, cmd = m.Update(tea.KeyPressMsg(tea.Key{ + Code: tea.KeyEnter, + })) m = batchUpdate(m, cmd) view = ansi.Strip(m.View()) @@ -199,8 +206,8 @@ func TestForm(t *testing.T) { t.Error("Expected form to preselect tomatoes") } - m, _ = m.Update(keys('j')) - m, _ = m.Update(keys('j')) + m, _ = m.Update(keypress('j')) + m, _ = m.Update(keypress('j')) view = ansi.Strip(m.View()) if !strings.Contains(view, "> • Corn") { @@ -208,7 +215,7 @@ func TestForm(t *testing.T) { t.Error("Expected form to change selection to corn") } - m, _ = m.Update(keys('x')) + m, _ = m.Update(keypress('x')) view = ansi.Strip(m.View()) if !strings.Contains(view, "> ✓ Corn") { @@ -216,7 +223,9 @@ func TestForm(t *testing.T) { t.Error("Expected form to change selection to corn") } - m = batchUpdate(m.Update(tea.KeyMsg{Type: tea.KeyEnter})) + m = batchUpdate(m.Update(tea.KeyPressMsg(tea.Key{ + Code: tea.KeyEnter, + }))) view = ansi.Strip(m.View()) if !strings.Contains(view, "What's your name?") { @@ -249,7 +258,9 @@ func TestForm(t *testing.T) { // // enter next • shift+tab back // - m.Update(keys('G', 'l', 'e', 'n')) + for _, msg := range typeText("Glen") { + m.Update(msg) + } view = ansi.Strip(m.View()) if !strings.Contains(view, "Glen") { t.Log(pretty.Render(view)) @@ -278,7 +289,8 @@ func TestForm(t *testing.T) { func TestInput(t *testing.T) { field := NewInput() f := NewForm(NewGroup(field)) - f.Update(f.Init()) + _, cmd := f.Init() + f.Update(cmd) view := ansi.Strip(f.View()) @@ -288,8 +300,10 @@ func TestInput(t *testing.T) { } // Type Huh in the form. - m, _ := f.Update(keys('H', 'u', 'h')) - f = m.(*Form) + for _, msg := range typeText("Huh") { + m, _ := f.Update(msg) + f = m.(*Form) + } view = ansi.Strip(f.View()) if !strings.Contains(view, "Huh") { @@ -315,7 +329,8 @@ func TestInlineInput(t *testing.T) { Inline(true) f := NewForm(NewGroup(field)).WithWidth(40) - f.Update(f.Init()) + _, cmd := f.Init() + f.Update(cmd) view := ansi.Strip(f.View()) @@ -325,8 +340,10 @@ func TestInlineInput(t *testing.T) { } // Type Huh in the form. - m, _ := f.Update(keys('H', 'u', 'h')) - f = m.(*Form) + for _, msg := range typeText("Huh") { + m, _ := f.Update(msg) + f = m.(*Form) + } view = ansi.Strip(f.View()) if !strings.Contains(view, "Huh") { @@ -352,11 +369,14 @@ func TestInlineInput(t *testing.T) { func TestText(t *testing.T) { field := NewText() f := NewForm(NewGroup(field)) - f.Update(f.Init()) + _, cmd := f.Init() + f.Update(cmd) // Type Huh in the form. - m, _ := f.Update(keys('H', 'u', 'h')) - f = m.(*Form) + for _, msg := range typeText("Huh") { + m, _ := f.Update(msg) + f = m.(*Form) + } view := ansi.Strip(f.View()) if !strings.Contains(view, "Huh") { @@ -377,10 +397,11 @@ func TestText(t *testing.T) { func TestConfirm(t *testing.T) { field := NewConfirm().Title("Are you sure?") f := NewForm(NewGroup(field)) - f.Update(f.Init()) + _, cmd := f.Init() + f.Update(cmd) // Type Huh in the form. - m, _ := f.Update(keys('H')) + m, _ := f.Update(keypress('H')) f = m.(*Form) view := ansi.Strip(f.View()) @@ -409,15 +430,13 @@ func TestConfirm(t *testing.T) { } // Toggle left - m, _ = f.Update(tea.KeyMsg{Type: tea.KeyLeft}) - + _, _ = f.Update(tea.KeyPressMsg(tea.Key{Code: tea.KeyLeft})) if field.GetValue() != true { t.Error("Expected field value to be true") } // Toggle right - m, _ = f.Update(tea.KeyMsg{Type: tea.KeyRight}) - + _, _ = f.Update(tea.KeyPressMsg(tea.Key{Code: tea.KeyRight})) if field.GetValue() != false { t.Error("Expected field value to be false") } @@ -426,7 +445,8 @@ func TestConfirm(t *testing.T) { func TestSelect(t *testing.T) { field := NewSelect[string]().Options(NewOptions("Foo", "Bar", "Baz")...).Title("Which one?") f := NewForm(NewGroup(field)) - f.Update(f.Init()) + _, cmd := f.Init() + f.Update(cmd) view := ansi.Strip(f.View()) @@ -446,7 +466,7 @@ func TestSelect(t *testing.T) { } // Move selection cursor down - m, _ := f.Update(tea.KeyMsg{Type: tea.KeyDown}) + m, _ := f.Update(tea.KeyPressMsg(tea.Key{Code: tea.KeyDown})) f = m.(*Form) view = ansi.Strip(f.View()) @@ -467,8 +487,8 @@ func TestSelect(t *testing.T) { } // Submit - m, _ = f.Update(tea.KeyMsg{Type: tea.KeyEnter}) - f = m.(*Form) + m, _ = f.Update(tea.KeyPressMsg(tea.Key{Code: tea.KeyEnter})) + _ = m.(*Form) if field.GetValue() != "Bar" { t.Error("Expected field value to be Bar") @@ -478,7 +498,8 @@ func TestSelect(t *testing.T) { func TestMultiSelect(t *testing.T) { field := NewMultiSelect[string]().Options(NewOptions("Foo", "Bar", "Baz")...).Title("Which one?") f := NewForm(NewGroup(field)) - f.Update(f.Init()) + _, cmd := f.Init() + f.Update(cmd) view := ansi.Strip(f.View()) @@ -498,7 +519,7 @@ func TestMultiSelect(t *testing.T) { } // Move selection cursor down - m, _ := f.Update(keys('j')) + m, _ := f.Update(keypress('j')) view = ansi.Strip(m.View()) if strings.Contains(view, "> • Foo") { @@ -512,7 +533,7 @@ func TestMultiSelect(t *testing.T) { } // Toggle - m, _ = f.Update(keys('x')) + m, _ = f.Update(keypress('x')) view = ansi.Strip(m.View()) if !strings.Contains(view, "> ✓ Bar") { @@ -526,8 +547,8 @@ func TestMultiSelect(t *testing.T) { } // Submit - m, _ = f.Update(tea.KeyMsg{Type: tea.KeyEnter}) - f = m.(*Form) + m, _ = f.Update(tea.KeyPressMsg(tea.Key{Code: tea.KeyEnter})) + _ = m.(*Form) value := field.GetValue() if value, ok := value.([]string); !ok { @@ -556,10 +577,14 @@ func TestMultiSelectFiltering(t *testing.T) { t.Run(tc.name, func(t *testing.T) { field := NewMultiSelect[string]().Options(NewOptions("Foo", "Bar", "Baz")...).Title("Which one?").Filterable(tc.filtering) f := NewForm(NewGroup(field)) - f.Update(f.Init()) + _, cmd := f.Init() + f.Update(cmd) // Filter for values starting with a 'B' only. - f.Update(keys('/')) - f.Update(keys('B')) + f.Update(tea.KeyPressMsg(tea.Key{ + Code: '/', + })) + m, _ := f.Update(keypress('B')) + f = m.(*Form) view := ansi.Strip(f.View()) // When we're filtering, the list should change. @@ -577,7 +602,8 @@ func TestMultiSelectFiltering(t *testing.T) { t.Run("Remove filter option from help menu.", func(t *testing.T) { field := NewMultiSelect[string]().Options(NewOptions("Foo", "Bar", "Baz")...).Title("Which one?").Filterable(false) f := NewForm(NewGroup(field)) - f.Update(f.Init()) + _, cmd := f.Init() + f.Update(cmd) view := ansi.Strip(f.View()) if strings.Contains(view, "filter") { t.Log(pretty.Render(view)) @@ -619,7 +645,8 @@ func TestSelectPageNavigation(t *testing.T) { NewSelect[string]().Options(opts...).Title("Choose"), } { f := NewForm(NewGroup(field)).WithHeight(10) - f.Update(f.Init()) + _, cmd := f.Init() + f.Update(cmd) view := ansi.Strip(f.View()) if !reFirst.MatchString(view) { @@ -627,21 +654,21 @@ func TestSelectPageNavigation(t *testing.T) { t.Error("Wrong item selected") } - m, _ := f.Update(keys('G')) + m, _ := f.Update(keypress('G')) view = ansi.Strip(m.View()) if !reLast.MatchString(view) { t.Log(pretty.Render(view)) t.Error("Wrong item selected") } - m, _ = f.Update(keys('g')) + m, _ = f.Update(keypress('g')) view = ansi.Strip(m.View()) if !reFirst.MatchString(view) { t.Log(pretty.Render(view)) t.Error("Wrong item selected") } - m, _ = f.Update(tea.KeyMsg{Type: tea.KeyCtrlD}) + m, _ = f.Update(tea.KeyPressMsg(tea.Key{Mod: tea.ModCtrl, Code: 'd'})) view = ansi.Strip(m.View()) if !reHalfDown.MatchString(view) { t.Log(pretty.Render(view)) @@ -649,9 +676,9 @@ func TestSelectPageNavigation(t *testing.T) { } // sends multiple to verify it stays within boundaries - f.Update(tea.KeyMsg{Type: tea.KeyCtrlU}) - f.Update(tea.KeyMsg{Type: tea.KeyCtrlU}) - m, _ = f.Update(tea.KeyMsg{Type: tea.KeyCtrlU}) + f.Update(tea.KeyPressMsg(tea.Key{Mod: tea.ModCtrl, Code: 'u'})) + f.Update(tea.KeyPressMsg(tea.Key{Mod: tea.ModCtrl, Code: 'u'})) + m, _ = f.Update(tea.KeyPressMsg(tea.Key{Mod: tea.ModCtrl, Code: 'u'})) view = ansi.Strip(m.View()) if !reFirst.MatchString(view) { t.Log(pretty.Render(view)) @@ -659,12 +686,12 @@ func TestSelectPageNavigation(t *testing.T) { } // verify it stays within boundaries - f.Update(tea.KeyMsg{Type: tea.KeyCtrlD}) - f.Update(tea.KeyMsg{Type: tea.KeyCtrlD}) - f.Update(tea.KeyMsg{Type: tea.KeyCtrlD}) - f.Update(tea.KeyMsg{Type: tea.KeyCtrlD}) - f.Update(tea.KeyMsg{Type: tea.KeyCtrlD}) - m, _ = f.Update(tea.KeyMsg{Type: tea.KeyCtrlD}) + f.Update(tea.KeyPressMsg(tea.Key{Mod: tea.ModCtrl, Code: 'd'})) + f.Update(tea.KeyPressMsg(tea.Key{Mod: tea.ModCtrl, Code: 'd'})) + f.Update(tea.KeyPressMsg(tea.Key{Mod: tea.ModCtrl, Code: 'd'})) + f.Update(tea.KeyPressMsg(tea.Key{Mod: tea.ModCtrl, Code: 'd'})) + f.Update(tea.KeyPressMsg(tea.Key{Mod: tea.ModCtrl, Code: 'd'})) + m, _ = f.Update(tea.KeyPressMsg(tea.Key{Mod: tea.ModCtrl, Code: 'd'})) view = ansi.Strip(m.View()) if !reLast.MatchString(view) { t.Log(pretty.Render(view)) @@ -675,7 +702,8 @@ func TestSelectPageNavigation(t *testing.T) { func TestFile(t *testing.T) { field := NewFilePicker().Title("Which file?") - cmd := field.Init() + _, cmd := field.Init() + field.Update(cmd) field.Update(cmd()) view := ansi.Strip(field.View()) @@ -702,7 +730,9 @@ func TestHideGroup(t *testing.T) { WithHide(true), ) - f = batchUpdate(f, f.Init()).(*Form) + _, cmd := f.Init() + f.Update(cmd) + f = batchUpdate(f, cmd).(*Form) if v := f.View(); !strings.Contains(v, "Bar") { t.Log(pretty.Render(v)) @@ -744,7 +774,9 @@ func TestHideGroupLastAndFirstGroupsNotHidden(t *testing.T) { NewGroup(NewNote().Description("Baz")), ) - f = batchUpdate(f, f.Init()).(*Form) + _, cmd := f.Init() + f.Update(cmd) + f = batchUpdate(f, cmd).(*Form) if v := ansi.Strip(f.View()); !strings.Contains(v, "Bar") { t.Log(pretty.Render(v)) @@ -780,7 +812,9 @@ func TestPrevGroup(t *testing.T) { NewGroup(NewNote().Description("Baz")), ) - f = batchUpdate(f, f.Init()).(*Form) + _, cmd := f.Init() + f.Update(cmd) + f = batchUpdate(f, cmd).(*Form) f.Update(nextGroup()) f.Update(nextGroup()) f.Update(prevGroup()) @@ -795,7 +829,8 @@ func TestPrevGroup(t *testing.T) { func TestNote(t *testing.T) { field := NewNote().Title("Taco").Description("How may we take your order?").Next(true) f := NewForm(NewGroup(field)) - f.Update(f.Init()) + _, cmd := f.Init() + f.Update(cmd) view := ansi.Strip(f.View()) @@ -828,7 +863,8 @@ func TestDynamicHelp(t *testing.T) { NewInput().Title("Dynamic Help"), ), ) - f.Update(f.Init()) + _, cmd := f.Init() + f.Update(cmd) view := ansi.Strip(f.View()) @@ -853,7 +889,9 @@ func TestSkip(t *testing.T) { ), ).WithWidth(25) - f = batchUpdate(f, f.Init()).(*Form) + _, cmd := f.Init() + f.Update(cmd) + f = batchUpdate(f, cmd).(*Form) view := ansi.Strip(f.View()) if !strings.Contains(view, "┃ First") { @@ -910,7 +948,7 @@ func TestAbort(t *testing.T) { // Since the context is cancelled, the program should exit immediately. cancel() // Tell the form to abort. - f.Update(tea.KeyMsg{Type: tea.KeyCtrlC}) + f.Update(tea.KeyPressMsg(tea.Key{Mod: tea.ModCtrl, Code: 'c'})) // Run the program. err := f.RunWithContext(ctx) if err == nil || !errors.Is(err, ErrUserAborted) { @@ -935,13 +973,22 @@ func batchUpdate(m tea.Model, cmd tea.Cmd) tea.Model { return m } msg = cmd() - m, cmd = m.Update(msg) + m, _ = m.Update(msg) return m } -func keys(runes ...rune) tea.KeyMsg { - return tea.KeyMsg{ - Type: tea.KeyRunes, - Runes: runes, +func keypress(r rune) tea.KeyMsg { + return tea.KeyPressMsg(tea.Key{ + Text: string(r), + Code: r, + ShiftedCode: r, + }) +} + +func typeText(s string) []tea.KeyMsg { + keys := make([]tea.KeyMsg, 0, len(s)) + for _, r := range s { + keys = append(keys, keypress(r)) } + return keys } diff --git a/keymap.go b/keymap.go index 24a3bc34..f514247f 100644 --- a/keymap.go +++ b/keymap.go @@ -1,6 +1,6 @@ package huh -import "github.com/charmbracelet/bubbles/key" +import "github.com/charmbracelet/bubbles/v2/key" // KeyMap is the keybindings to navigate the form. type KeyMap struct { diff --git a/spinner/examples/accessible/main.go b/spinner/examples/accessible/main.go index 2a542359..13253551 100644 --- a/spinner/examples/accessible/main.go +++ b/spinner/examples/accessible/main.go @@ -5,7 +5,7 @@ import ( "log" "time" - "github.com/charmbracelet/huh/spinner" + "github.com/charmbracelet/huh/v2/spinner" ) func main() { diff --git a/spinner/examples/context/main.go b/spinner/examples/context/main.go index ca9bb618..3d3c71f7 100644 --- a/spinner/examples/context/main.go +++ b/spinner/examples/context/main.go @@ -5,7 +5,7 @@ import ( "fmt" "time" - "github.com/charmbracelet/huh/spinner" + "github.com/charmbracelet/huh/v2/spinner" ) func main() { diff --git a/spinner/examples/loading/main.go b/spinner/examples/loading/main.go index 34b7cb95..11025545 100644 --- a/spinner/examples/loading/main.go +++ b/spinner/examples/loading/main.go @@ -4,7 +4,7 @@ import ( "fmt" "time" - "github.com/charmbracelet/huh/spinner" + "github.com/charmbracelet/huh/v2/spinner" ) func main() { diff --git a/spinner/examples/static/main.go b/spinner/examples/static/main.go index febbe4e9..f6e59ce6 100644 --- a/spinner/examples/static/main.go +++ b/spinner/examples/static/main.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/charmbracelet/huh/spinner" + "github.com/charmbracelet/huh/v2/spinner" ) func main() { diff --git a/spinner/go.mod b/spinner/go.mod index 74f2c557..6b7fc6a2 100644 --- a/spinner/go.mod +++ b/spinner/go.mod @@ -1,27 +1,26 @@ -module github.com/charmbracelet/huh/spinner +module github.com/charmbracelet/huh/v2/spinner go 1.19 require ( - github.com/charmbracelet/bubbles v0.20.0 - github.com/charmbracelet/bubbletea v1.1.1 + github.com/charmbracelet/bubbles/v2 v2.0.0-alpha.1 + github.com/charmbracelet/bubbletea/v2 v2.0.0-alpha.1 github.com/charmbracelet/lipgloss v0.13.0 github.com/muesli/termenv v0.15.2 ) require ( github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect - github.com/charmbracelet/x/ansi v0.2.3 // indirect + github.com/charmbracelet/x/ansi v0.3.2 // indirect github.com/charmbracelet/x/term v0.2.0 // indirect - github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect + github.com/charmbracelet/x/windows v0.2.0 // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect github.com/mattn/go-isatty v0.0.20 // indirect - github.com/mattn/go-localereader v0.0.1 // indirect github.com/mattn/go-runewidth v0.0.16 // indirect github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect github.com/muesli/cancelreader v0.2.2 // indirect github.com/rivo/uniseg v0.4.7 // indirect + github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect golang.org/x/sync v0.8.0 // indirect - golang.org/x/sys v0.24.0 // indirect - golang.org/x/text v0.16.0 // indirect + golang.org/x/sys v0.25.0 // indirect ) diff --git a/spinner/go.sum b/spinner/go.sum index 9a46f67a..d187ca3f 100644 --- a/spinner/go.sum +++ b/spinner/go.sum @@ -1,23 +1,21 @@ 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/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.1.1 h1:KJ2/DnmpfqFtDNVTvYZ6zpPFL9iRCRr0qqKOCvppbPY= -github.com/charmbracelet/bubbletea v1.1.1/go.mod h1:9Ogk0HrdbHolIKHdjfFpyXJmiCzGwy+FesYkZr7hYU4= +github.com/charmbracelet/bubbles/v2 v2.0.0-alpha.1 h1:4Am/U9zvRBZ5iSIDeNioGrc9N9+4U2AjiRJBttAwUVc= +github.com/charmbracelet/bubbles/v2 v2.0.0-alpha.1/go.mod h1:rq09SZbh77FFBMvKi5k2vGXJ7K4u0GjLqmUby3K3los= +github.com/charmbracelet/bubbletea/v2 v2.0.0-alpha.1 h1:OZtpLCsuuPplC+1oyUo+/eAN7e9MC2UyZWKlKrVlUnw= +github.com/charmbracelet/bubbletea/v2 v2.0.0-alpha.1/go.mod h1:j0gn4ft5CE7NDYNZjAA3hBM8t2OPjI8urxuAD0oR4w8= github.com/charmbracelet/lipgloss v0.13.0 h1:4X3PPeoWEDCMvzDvGmTajSyYPcZM4+y8sCA/SsA3cjw= github.com/charmbracelet/lipgloss v0.13.0/go.mod h1:nw4zy0SBX/F/eAO1cWdcvy6qnkDUxr8Lw7dvFrAIbbY= -github.com/charmbracelet/x/ansi v0.2.3 h1:VfFN0NUpcjBRd4DnKfRaIRo53KRgey/nhOoEqosGDEY= -github.com/charmbracelet/x/ansi v0.2.3/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw= +github.com/charmbracelet/x/ansi v0.3.2 h1:wsEwgAN+C9U06l9dCVMX0/L3x7ptvY1qmjMwyfE6USY= +github.com/charmbracelet/x/ansi v0.3.2/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw= github.com/charmbracelet/x/term v0.2.0 h1:cNB9Ot9q8I711MyZ7myUR5HFWL/lc3OpU8jZ4hwm0x0= github.com/charmbracelet/x/term v0.2.0/go.mod h1:GVxgxAbjUrmpvIINHIQnJJKpMlHiZ4cktEQCN6GWyF0= -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/charmbracelet/x/windows v0.2.0 h1:ilXA1GJjTNkgOm94CLPeSz7rar54jtFatdmoiONPuEw= +github.com/charmbracelet/x/windows v0.2.0/go.mod h1:ZibNFR49ZFqCXgP76sYanisxRyC+EYrBE7TTknD8s1s= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= github.com/lucasb-eyer/go-colorful v1.2.0/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.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc= github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI= @@ -29,11 +27,11 @@ github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1n 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/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no= +github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM= +golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E= golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= -golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= -golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= +golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= +golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= diff --git a/spinner/spinner.go b/spinner/spinner.go index ced0a27a..fde05af5 100644 --- a/spinner/spinner.go +++ b/spinner/spinner.go @@ -8,8 +8,8 @@ import ( "strings" "time" - "github.com/charmbracelet/bubbles/spinner" - tea "github.com/charmbracelet/bubbletea" + "github.com/charmbracelet/bubbles/v2/spinner" + tea "github.com/charmbracelet/bubbletea/v2" "github.com/charmbracelet/lipgloss" "github.com/muesli/termenv" ) @@ -108,8 +108,8 @@ func New() *Spinner { } // Init initializes the spinner. -func (s *Spinner) Init() tea.Cmd { - return s.spinner.Tick +func (s *Spinner) Init() (tea.Model, tea.Cmd) { + return s, s.spinner.Tick } // Update updates the spinner. diff --git a/spinner/spinner_test.go b/spinner/spinner_test.go index 2e62f8d1..ee033db7 100644 --- a/spinner/spinner_test.go +++ b/spinner/spinner_test.go @@ -6,8 +6,8 @@ import ( "strings" "testing" - "github.com/charmbracelet/bubbles/spinner" - tea "github.com/charmbracelet/bubbletea" + "github.com/charmbracelet/bubbles/v2/spinner" + tea "github.com/charmbracelet/bubbletea/v2" "github.com/charmbracelet/lipgloss" ) @@ -75,7 +75,7 @@ func TestSpinnerStyleMethods(t *testing.T) { func TestSpinnerInit(t *testing.T) { s := New() - cmd := s.Init() + _, cmd := s.Init() if cmd == nil { t.Errorf("Init did not return a valid command") @@ -84,7 +84,7 @@ func TestSpinnerInit(t *testing.T) { func TestSpinnerUpdate(t *testing.T) { s := New() - cmd := s.Init() + _, cmd := s.Init() if cmd == nil { t.Errorf("Init did not return a valid command") } @@ -99,7 +99,10 @@ func TestSpinnerUpdate(t *testing.T) { } // Simulate key press - _, cmd = s.Update(tea.KeyMsg{Type: tea.KeyCtrlC}) + _, cmd = s.Update(tea.KeyPressMsg(tea.Key{ + Mod: tea.ModCtrl, + Code: 'c', + })) if cmd == nil { t.Errorf("Update did not handle key press correctly") } diff --git a/theme.go b/theme.go index 32982a1b..3114d81c 100644 --- a/theme.go +++ b/theme.go @@ -2,7 +2,7 @@ package huh import ( catppuccin "github.com/catppuccin/go" - "github.com/charmbracelet/bubbles/help" + "github.com/charmbracelet/bubbles/v2/help" "github.com/charmbracelet/lipgloss" )