Skip to content

Commit

Permalink
feat: nicer form for did you mean (#145)
Browse files Browse the repository at this point in the history
* use huh.Confirm for did you mean prompt

* cleanup implementation

* formatting
  • Loading branch information
hay-kot committed May 13, 2024
1 parent 38c4eed commit 850c66f
Showing 1 changed file with 10 additions and 37 deletions.
47 changes: 10 additions & 37 deletions app/commands/prompts.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
package commands

import (
"fmt"
"strings"

"github.com/charmbracelet/huh"
"github.com/charmbracelet/lipgloss"
)

var (
bold = lipgloss.NewStyle().Bold(true)
colorRed = lipgloss.NewStyle().Foreground(lipgloss.Color("#dc2626"))
)

func httpAuthPrompt() (username string, password string, err error) {
Expand All @@ -37,34 +28,16 @@ func httpAuthPrompt() (username string, password string, err error) {
}

func didYouMeanPrompt(given, suggestion string) bool {
bldr := strings.Builder{}

// Couldn't find a scaffold named:
// 'foo'
//
// Did you mean:
// 'bar'?
//
// [y/n]:

bldr.WriteString("\n ")
bldr.WriteString(bold.Render(colorRed.Render("could not find a scaffold named")))
bldr.WriteString("\n ")
bldr.WriteString(given)
bldr.WriteString("\n\n")
bldr.WriteString(" ")
bldr.WriteString(bold.Render("did you mean"))
bldr.WriteString("\n ")
bldr.WriteString(suggestion)
bldr.WriteString("?\n\n ")
bldr.WriteString("[y/n]: ")
ok := true

out := bldr.String()

var resp string

fmt.Print(out)
fmt.Scanln(&resp)
err := huh.NewConfirm().
Title("Did You Mean " + suggestion + "?").
Description("Couldn't find '" + given + "'").
Value(&ok).
Run()
if err != nil {
return false
}

return resp == "y"
return ok
}

0 comments on commit 850c66f

Please sign in to comment.