charmbracelet / huh

Build terminal forms and prompts 🤷🏻‍♀️
MIT License
4.31k stars 122 forks source link

Tab Complete for Input Fields #105

Closed ryan-timothy-albert closed 7 months ago

ryan-timothy-albert commented 9 months ago

I'm wondering if it's possible to support tab completion for input fields. Ideally it would be possible to use tab completion when entering values like it is outside of the form.

It may already be possible to configure this and I am missing something.

Thanks in Advance!

maaslalani commented 9 months ago

Hi, this is already possible on the latest huh@main! Introduced in:

We'll do a release soon which will make it available more widely but to try it out:

go get -u github.com/charmbracelet/huh@main

And then on your Input fields you can attach Suggestions:

huh.NewInput().Suggestions([]string{"foo", "bar", "baz"})
ryan-timothy-albert commented 9 months ago

Awesome I'll try that out thank you!

ryan-timothy-albert commented 9 months ago

Wondering if there is a general estimate on when that next release will be? Not urgent

maaslalani commented 9 months ago

Hey @ryan-timothy-albert! It should be next week!

ryan-timothy-albert commented 8 months ago

Hey @maaslalani

Harcoded suggestions are working well. One follow up question we have that's come from our users is if there are plans to hook into more dynamic autocompletion. i.e. someone starts to type ../open we can suggest files in that directory that start with open.

maaslalani commented 8 months ago

Hey @ryan-timothy-albert, thanks for re-opening this issue. We want to create a system in huh that lets you re-evaluate any part of the form based on the user input as well.

This should encompass passing in new suggestions to Suggestions.

ryan-timothy-albert commented 8 months ago

Hi @maaslalani

Thanks for the response. We do use the WithHideFunc internally. I'm totally following how this can help us populate suggestions based on live user input to a field though.

ryan-timothy-albert commented 7 months ago

Hey @maaslalani

So currently we are supporting dynamic autocomplete with a fork of the library see the following here.

Here is the callback function that we use pass into certain input fields.

I recognize there are some risks to exposing a callback like this from field_input especially if the user implements it incorrectly. I'm wondering if you'd be open to something like this in the main huh library, or perhaps a different approach to the problem.