From f18ad3863ff1e732d7474e1b431339c6f3562041 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diogo=20Ferr=C3=A3o?= Date: Wed, 8 May 2024 13:41:17 +0100 Subject: [PATCH 1/2] fix prompt for enter func --- internal/pkg/print/print.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/internal/pkg/print/print.go b/internal/pkg/print/print.go index 92fc9a4cb..ee4e2a25f 100644 --- a/internal/pkg/print/print.go +++ b/internal/pkg/print/print.go @@ -141,19 +141,13 @@ func (p *Printer) PromptForConfirmation(prompt string) error { // Returns nil only if the user (explicitly) press directly enter. // Returns ErrAborted if the user press anything else before pressing enter. func (p *Printer) PromptForEnter(prompt string) error { - reader := bufio.NewReaderSize(p.Cmd.InOrStdin(), 1) - + reader := bufio.NewReader(p.Cmd.InOrStdin()) p.Cmd.PrintErr(prompt) - answer, err := reader.ReadByte() + _, err := reader.ReadString('\n') if err != nil { return fmt.Errorf("read user response: %w", err) } - - // ASCII code for Enter (newline) is 10. - if answer == 10 { - return nil - } - return errAborted + return nil } // Shows the content in the command's stdout using the "less" command From a39068c2fb229257c54b229e9eb06fb5c956fba1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diogo=20Ferr=C3=A3o?= Date: Wed, 8 May 2024 16:25:35 +0100 Subject: [PATCH 2/2] update comments --- internal/pkg/print/print.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/internal/pkg/print/print.go b/internal/pkg/print/print.go index ee4e2a25f..04adf3243 100644 --- a/internal/pkg/print/print.go +++ b/internal/pkg/print/print.go @@ -138,8 +138,7 @@ func (p *Printer) PromptForConfirmation(prompt string) error { // Prompts the user for confirmation by pressing Enter. // -// Returns nil only if the user (explicitly) press directly enter. -// Returns ErrAborted if the user press anything else before pressing enter. +// Returns nil if the user presses Enter. func (p *Printer) PromptForEnter(prompt string) error { reader := bufio.NewReader(p.Cmd.InOrStdin()) p.Cmd.PrintErr(prompt)