huh icon indicating copy to clipboard operation
huh copied to clipboard

Preserve form after user submission

Open Naatan opened this issue 1 year ago • 1 comments

Is your feature request related to a problem? Please describe. I want the form to remain visible after the user has provided their input. At the moment it drops the form, which makes for a confusing user experience.

Describe the solution you'd like Some sort of option I can toggle to have it not delete the rendered form when it is done.

Describe alternatives you've considered Open to other solutions so long as they achieve the desired outcome.

Additional context Dug through code and docs but could not find any obvious way to achieve what I am describing.

Naatan avatar Apr 08 '24 17:04 Naatan

@Naatan Have you tried using the.WithAccessible(true) feature on huh forms? This will preserve the form and drop to new lines on the terminal

Using that will result in the following:

package main

import (
	"log"

	"github.com/charmbracelet/huh"
)

func main() {
	form := huh.NewForm(
		huh.NewGroup(
			huh.NewSelect[string]().
				Options(huh.NewOptions("Italian", "Greek", "Indian", "Japanese", "American")...).
				Title("Favorite Cuisine?"),
		),

		huh.NewGroup(
			huh.NewInput().
				Title("Favorite Meal?").
				Placeholder("Breakfast"),
		),
	).WithAccessible(true)

	err := form.Run()
	if err != nil {
		log.Fatal(err)
	}
}

The following above will result in the previous forms being saved along with the user input and it dropping to new lines image

MatthewWaring avatar Jun 17 '24 18:06 MatthewWaring