-
Notifications
You must be signed in to change notification settings - Fork 355
Input suggestion problem #452
Comments
I have the same problem, tested by compiling with all the versions back til 2.2.13 which doesn't have the issue. This is the only PR in 2.2.14 My system:
|
If I remove this line Line 186 in a98a037
The answer is correctly printed after selecting a suggestion. However, the random answer (without selecting a suggestion) is not, it's printed one line after the prompt. For example
|
I customized the InputQuestionTemplate and removed "enter to select" from the shown message that the user uses the right arrow to select an item but it isn't a good solution. it must be fixed |
Hi, thanks for the reports! Please try to create some code that uses Survey that acts as a small reproduction case for the problem. For examples on how this can look like, please see the Even a screenshot from your terminal (before and after the line in question disappears) would be helpful. Additionally, when reporting these issues, please also tell us your OS and terminal emulator used. |
Code package main
import (
"fmt"
"os"
"strings"
"github.com/AlecAivazis/survey/v2"
)
func main() {
var answer string
suggests := []string{"Amelia", "Ava", "Elijah", "Emma", "Liam", "Mateo", "Noah", "Oliver", "Olivia", "Sophia"}
err := survey.AskOne(&survey.Input{
Message: "What is your name?",
Suggest: func(toComplete string) []string {
if len(toComplete) == 0 {
return suggests
}
var matches []string
for _, s := range suggests {
if strings.Contains(s, toComplete) {
matches = append(matches, s)
}
}
return matches
},
}, &answer)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
// print the answers
fmt.Printf("Hi %s.\n", answer)
} Env:
Stable version Screen.Recording.2022-09-29.at.08.17.20.movLast working version Screen.Recording.2022-09-29.at.08.23.10.mov |
Code: package main
import (
"fmt"
"path/filepath"
"github.com/AlecAivazis/survey/v2"
)
const questionCount = 2
var currentQuestion = 1
func main() {
var fileName, filePath string
fileNameQs := &survey.Input{Message: `File Name: ("sample")`}
_ = survey.AskOne(fileNameQs, &fileName, survey.WithValidator(survey.Required), survey.WithIcons(setupQuestionIcon))
filePathQs := &survey.Input{Message: `File Path: ("/home/snapp/go")`, Suggest: func(toComplete string) []string {
directories, _ := filepath.Glob(toComplete + "*")
return directories
},
}
_ = survey.AskOne(filePathQs, &filePath, survey.WithValidator(survey.Required), survey.WithIcons(setupQuestionIcon))
fmt.Printf("\nFile %s saved in %s\n", fileName, filePath)
}
func setupQuestionIcon(icon *survey.IconSet) {
icon.Question.Text = fmt.Sprintf("[%d/%d]", currentQuestion, questionCount)
currentQuestion++
} Env: Select an item by enter: Select an item by arrow or type: |
Thanks both! I managed to reproduce the problem. |
@mislav This problem still exists, when will it be fixed? |
When I select an item in the input suggestion with the enter button, the previous question is removed from CLI.
How can I fix it?
The text was updated successfully, but these errors were encountered: