Skip to content

Commit

Permalink
term: fix: ErrPrintf, PrintErrF print duplicate newlines
Browse files Browse the repository at this point in the history
ErrPrintf and PrintErrF are calling Println which adds a newline to the
end of the string.
Printf-style method usually expect that the caller adds the newline.
Make the behavior more predictable, by not printing duplicate newlines
if the caller already provided one.
  • Loading branch information
fho committed May 30, 2024
1 parent da76657 commit 2857849
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions internal/command/term/streams.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package term
import (
"fmt"
"io"
"strings"
"sync"

"github.com/fatih/color"
Expand Down Expand Up @@ -60,7 +61,7 @@ func (s *Stream) ErrPrintln(err error, msg ...any) {
// ErrPrintf prints an error with an optional printf-style message.
// The method prints the error in the format: errorPrefix msg: err
func (s *Stream) ErrPrintf(err error, format string, a ...any) {
s.ErrPrintln(err, fmt.Sprintf(format, a...))
s.ErrPrintln(err, fmt.Sprintf(strings.TrimSuffix(format, "\n"), a...))
}

// PrintErrln prints as message that is prefixed with "ERROR: "
Expand All @@ -70,7 +71,7 @@ func (s *Stream) PrintErrln(msg ...any) {

// PrintErrf prints as message that is prefixed with "ERROR: "
func (s *Stream) PrintErrf(format string, a ...any) {
s.Println(ErrorPrefix, fmt.Sprintf(format, a...))
s.Printf(ErrorPrefix+" "+format, a...)
}

// PrintSep prints a separator line
Expand Down

0 comments on commit 2857849

Please sign in to comment.