Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input Suggestions #89

Closed
rusq opened this issue Dec 31, 2023 · 3 comments · Fixed by #93
Closed

Input Suggestions #89

rusq opened this issue Dec 31, 2023 · 3 comments · Fixed by #93

Comments

@rusq
Copy link

rusq commented Dec 31, 2023

Hi team, it's me again! I promise I will stop creating these after I finish the migration from Survey.

Is your feature request related to a problem? Please describe.
Survey inputs had an option to add an input "suggestion", user could press the [Tab] key and they would get the list of suggestions. This could be useful, if programme asks the user to input the existing filename (at least this is my use case).

I know that you already know what I'm writing about, but for completeness, here's the link.

Describe the solution you'd like
I would like to be able to specify the function that would make an input suggestion to the user.

When there's one and only one suggestion, the tab should complete the input to the suggested value.
When there's more than one suggestion there are two possible options: first one is to show the list of all, or "top N" items that match the prefix entered, or, cycle through suggestions on each press of the [Tab] key, just like cmd.exe prompt does in Windows.

Please keep in mind that I just started using Huh, so maybe there's some bubble-magic that I'm unaware of that allows to implement this easily?

Describe alternatives you've considered
The alternative that I have considered is not using the suggestions, or implement it myself, which I haven't gotten around to, as I'm quite new to the whole charm.sh framework.

Additional context
Here's how it's implemented in Survey (copy/pasting here for convenience):

file := ""
prompt := &survey.Input{
    Message: "inform a file to save:",
    Suggest: func (toComplete string) []string {
        files, _ := filepath.Glob(toComplete + "*")
        return files
    },
}
}
survey.AskOne(prompt, &file)

demo

Thank you for consideration.

@maaslalani
Copy link
Contributor

Hey @rusq, we have the concept of Suggestions within the textinput bubble and can definitely expose this functionality to huh. Great call!

https://github.com/charmbracelet/bubbles/blob/master/textinput/textinput.go#L260-L269

@maaslalani
Copy link
Contributor

Feature added in #93

@rusq
Copy link
Author

rusq commented Jan 4, 2024

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants