huh icon indicating copy to clipboard operation
huh copied to clipboard

Additional Field Types

Open wesen opened this issue 2 years ago • 7 comments

I have a framework to describe application's input parameters in YAML, and use that to generate CLI flags/REST endpoints/HTML forms and much more, and I was about to write a TUI widget to render them with bubbletea. Here are a list of the widgets I need to build to support my tool:

  • checkbox
  • integer/float/string/bool lists
  • date
  • file/multi-file select
  • key value entry

I was wondering if you had any plans to implement these (and thus a design in mind), or if I should just go ahead and build my own and keep them say, in a separate library?

Here's a proof of concept: https://asciinema.org/a/ndG2OO2XqjYtenE5x9LYLRKvh

Here's my framework: https://github.com/go-go-golems/glazed

wesen avatar Dec 14 '23 14:12 wesen

Date and File selects are definitely on the roadmap (no eta yet).

I'm curious what you expect checkboxes to look like? Perhaps they can be tweaked by the theme to get the style you want on a multi-select list. Maybe we can implement this as an alternative view on NewConfirm or its own field NewCheckbox.

integer/float/string/bool lists should be implemented on select and multi-selects by simply changing the generic type: see the the following example (which uses a custom enum and can be swapped for any type)

https://github.com/charmbracelet/huh/blob/main/examples/burger/main.go#L106-L112

maaslalani avatar Dec 14 '23 15:12 maaslalani

good idea on doing checkboxes with a multiselect list!

The lists I am talking about are dynamic, in that people can enter say, product ids, or a list of prices. I am using these forms mostly as search forms for ecommerce queries right now.

wesen avatar Dec 14 '23 18:12 wesen

I think we can consider adding lists as well, for now I would highly recommend using a NewText and allowing the user to enter each item on a new line or a NewInput and having the lists comma separated.

I think the UX of a list could be quite better since then you could dynamically display them and validate each item so we can consider adding it, it would also make editing for the user easier as they could delete items very easily.

maaslalani avatar Dec 14 '23 18:12 maaslalani

Yeah, that is a good first option, and I am not sure yet either what widget would work for me. Anyway, it's easy to add fields in my own package, it'll give you an opportunity to pick and choose.

wesen avatar Dec 14 '23 18:12 wesen

Also it would be nice to have "select" that operates like the confirm. with the buttons.

WTIGER001 avatar Apr 02 '24 21:04 WTIGER001

Also it would be nice to have "select" that operates like the confirm. with the buttons.

We've added an Inline option for Select which does something along these lines, not with buttons but rather with a horizontally scrolling options list with one option displayed at a time.

maaslalani avatar May 25 '24 17:05 maaslalani

Just an update on this issue, FilePicker field was added to Huh?!

maaslalani avatar May 25 '24 17:05 maaslalani