Skip to content

Commit

Permalink
cmd/atlas/internal/cmdapi: disable bell voice in prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
a8m committed Jul 22, 2024
1 parent 3904d10 commit 2f21932
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions cmd/atlas/internal/cmdapi/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"ariga.io/atlas/sql/sqlclient"

"github.com/1lann/promptui"
"github.com/chzyer/readline"
"github.com/hashicorp/hcl/v2/hclwrite"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -755,7 +756,7 @@ func cmdPrompt(cmd *cobra.Command) *promptui.Select {
Label: "Are you sure?",
HideHelp: true,
Stdin: io.NopCloser(cmd.InOrStdin()),
Stdout: nopCloser{cmd.OutOrStdout()},
Stdout: nopBellCloser{cmd.OutOrStdout()},
}
}

Expand All @@ -770,9 +771,16 @@ func promptUser(cmd *cobra.Command) bool {
return result == answerApply
}

type nopCloser struct{ io.Writer }
type nopBellCloser struct{ io.Writer }

func (nopCloser) Close() error { return nil }
func (n nopBellCloser) Write(p []byte) (int, error) {
if len(p) == 1 && p[0] == readline.CharBell {
return 0, nil // Skip bell noise.
}
return n.Writer.Write(p)
}

func (nopBellCloser) Close() error { return nil }

func tasks(path string) ([]fmttask, error) {
var tasks []fmttask
Expand Down

0 comments on commit 2f21932

Please sign in to comment.