diff --git a/go.mod b/go.mod index be0de55..4a4774c 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/charmbracelet/bubbletea v1.2.2 github.com/charmbracelet/lipgloss v1.0.0 github.com/charmbracelet/x/ansi v0.4.5 + github.com/charmbracelet/x/exp/golden v0.0.0-20240815200342-61de596daa2b github.com/charmbracelet/x/exp/strings v0.0.0-20240722160745-212f7b056ed0 github.com/mitchellh/hashstructure/v2 v2.0.2 ) @@ -15,6 +16,7 @@ require ( require ( github.com/atotto/clipboard v0.1.4 // indirect github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect + github.com/aymanbagabas/go-udiff v0.2.0 // indirect github.com/charmbracelet/x/term v0.2.1 // indirect github.com/dustin/go-humanize v1.0.1 // indirect github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect diff --git a/go.sum b/go.sum index 4442611..47e3b97 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,8 @@ github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z 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/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= @@ -14,6 +16,8 @@ github.com/charmbracelet/lipgloss v1.0.0 h1:O7VkGDvqEdGi93X+DeqsQ7PKHDgtQfF8j8/O github.com/charmbracelet/lipgloss v1.0.0/go.mod h1:U5fy9Z+C38obMs+T+tJqst9VGzlOYGj4ri9reL3qUlo= github.com/charmbracelet/x/ansi v0.4.5 h1:LqK4vwBNaXw2AyGIICa5/29Sbdq58GbGdFngSexTdRM= github.com/charmbracelet/x/ansi v0.4.5/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw= +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/x/exp/strings v0.0.0-20240722160745-212f7b056ed0 h1:qko3AQ4gK1MTS/de7F5hPGx6/k1u0w4TeYmBFwzYVP4= github.com/charmbracelet/x/exp/strings v0.0.0-20240722160745-212f7b056ed0/go.mod h1:pBhA0ybfXv6hDjQUZ7hk1lVxBiUbupdw5R31yPUViVQ= github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= diff --git a/group.go b/group.go index b4973b5..c22d8ef 100644 --- a/group.go +++ b/group.go @@ -297,7 +297,6 @@ func (g *Group) fullHeight() int { func (g *Group) getContent() (int, string) { var fields strings.Builder offset := 0 - gap := "\n\n" // if the focused field is requesting it be zoomed, only show that field. if g.selector.Selected().Zoom() { diff --git a/huh_test.go b/huh_test.go index 57288b3..83f9eef 100644 --- a/huh_test.go +++ b/huh_test.go @@ -13,6 +13,7 @@ import ( tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" "github.com/charmbracelet/x/ansi" + "github.com/charmbracelet/x/exp/golden" ) var pretty = lipgloss.NewStyle(). @@ -918,6 +919,35 @@ func TestAbort(t *testing.T) { } } +func TestLayoutGrid(t *testing.T) { + form := NewForm( + NewGroup( + NewInput().Title("First"), + NewInput().Title("Second"), + NewInput().Title("Third"), + ), + NewGroup( + NewInput().Title("Fourth"), + NewInput().Title("Fifth"), + NewInput().Title("Sixth"), + ), + NewGroup( + NewInput().Title("Seventh"), + NewInput().Title("Eigth"), + NewInput().Title("Nineth"), + NewInput().Title("Tenth"), + ), + NewGroup( + NewInput().Title("Eleventh"), + NewInput().Title("Twelveth"), + NewInput().Title("Thirteenth"), + ), + ).WithLayout(LayoutGrid(2, 2)).WithShowHelp(false) + want := ansi.Strip(form.View()) + t.Log(want) + golden.RequireEqual(t, []byte(want)) +} + // formProgram returns a new Form with a nil input and output, so it can be used as a test program. func formProgram() *Form { return NewForm(NewGroup(NewInput().Title("Foo"))). diff --git a/testdata/TestLayoutGrid.golden b/testdata/TestLayoutGrid.golden new file mode 100644 index 0000000..55fac68 --- /dev/null +++ b/testdata/TestLayoutGrid.golden @@ -0,0 +1,23 @@ + First Fourth + > > + + Second Fifth + > > + + Third Sixth + > > + + Seventh Eleventh + > > + + Eigth Twelveth + > > + + Nineth Thirteenth + > > + + Tenth + > + + + \ No newline at end of file