Skip to content

Conversation

@sgsullivan
Copy link

Allows one to optionally have ControlC act like ControlD (close the prompt)

--

func dialogConfirmProceed() (proceed bool) {

        var haveAnswer bool

        f := func(d prompt.Document) []prompt.Suggest {
                s := []prompt.Suggest{
                        {Text: "yes", Description: "I understand continue"},
                        {Text: "no", Description: "I would like to cancel"},
                }
                return prompt.FilterHasPrefix(s, d.GetWordBeforeCursor(), true)
        }

        for !haveAnswer {
                fmt.Printf("Are you sure? ")
                answer := strings.ToLower(prompt.Input("> ", f, prompt.OptionShowCompletionAtStart(), prompt.OptionCloseOnControlC()))
                if answer == "yes" || answer == "no" || answer == "" {
                        haveAnswer = true
                        if answer == "yes" {
                                proceed = true
                        }
                }
        }

        return
}

Allows one to optionally have ControlC act like ControlD

--

func dialogConfirmProceed() (proceed bool) {

        var haveAnswer bool

        f := func(d prompt.Document) []prompt.Suggest {
                s := []prompt.Suggest{
                        {Text: "yes", Description: "I understand continue"},
                        {Text: "no", Description: "I would like to cancel"},
                }
                return prompt.FilterHasPrefix(s, d.GetWordBeforeCursor(), true)
        }

        for !haveAnswer {
                fmt.Printf("Are you sure? ")
                answer := strings.ToLower(prompt.Input("> ", f, prompt.OptionShowCompletionAtStart(), prompt.OptionCloseOnControlC()))
                if answer == "yes" || answer == "no" || answer == "" {
                        haveAnswer = true
                        if answer == "yes" {
                                proceed = true
                        }
                }
        }

        return
}
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 this pull request may close these issues.

1 participant