diff --git a/go.mod b/go.mod index 79da2b4a..0ee04f95 100644 --- a/go.mod +++ b/go.mod @@ -69,7 +69,7 @@ require ( github.com/muesli/reflow v0.3.0 // indirect github.com/muesli/termenv v0.15.2 // indirect github.com/pkg/errors v0.9.1 - github.com/pterm/pterm v0.12.74 + github.com/pterm/pterm v0.12.78 github.com/rivo/uniseg v0.4.4 // indirect github.com/spf13/pflag v1.0.5 github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect diff --git a/go.sum b/go.sum index e0a6b1f4..62ae5c69 100644 --- a/go.sum +++ b/go.sum @@ -149,8 +149,8 @@ github.com/pterm/pterm v0.12.31/go.mod h1:32ZAWZVXD7ZfG0s8qqHXePte42kdz8ECtRyEej github.com/pterm/pterm v0.12.33/go.mod h1:x+h2uL+n7CP/rel9+bImHD5lF3nM9vJj80k9ybiiTTE= github.com/pterm/pterm v0.12.36/go.mod h1:NjiL09hFhT/vWjQHSj1athJpx6H8cjpHXNAK5bUw8T8= github.com/pterm/pterm v0.12.40/go.mod h1:ffwPLwlbXxP+rxT0GsgDTzS3y3rmpAO1NMjUkGTYf8s= -github.com/pterm/pterm v0.12.74 h1:fPsds9KisCyJh4NyY6bv8QJt3FLHceb5DxI6W0An9cc= -github.com/pterm/pterm v0.12.74/go.mod h1:+M33aZWQVpmLmLbvjykyGZ4gAfeebznRo8JMbabaxQU= +github.com/pterm/pterm v0.12.78 h1:QTWKaIAa4B32GKwqVXtu9m1DUMgWw3VRljMkMevX+b8= +github.com/pterm/pterm v0.12.78/go.mod h1:1v/gzOF1N0FsjbgTHZ1wVycRkKiatFvJSJC4IGaQAAo= github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= diff --git a/vendor/github.com/pterm/pterm/errors.go b/vendor/github.com/pterm/pterm/errors.go index a7d6fcc7..9260ab64 100644 --- a/vendor/github.com/pterm/pterm/errors.go +++ b/vendor/github.com/pterm/pterm/errors.go @@ -8,4 +8,7 @@ var ( // ErrHexCodeIsInvalid - the given HEX code is invalid. ErrHexCodeIsInvalid = errors.New("hex code is not valid") + + // ErrKeyWithoutValue - an odd number of arguments was passed to a pterm Logger's Args method. + ErrKeyWithoutValue = "ERROR: key_without_value" ) diff --git a/vendor/github.com/pterm/pterm/interactive_textinput_printer.go b/vendor/github.com/pterm/pterm/interactive_textinput_printer.go index 88535c51..1989fc80 100644 --- a/vendor/github.com/pterm/pterm/interactive_textinput_printer.go +++ b/vendor/github.com/pterm/pterm/interactive_textinput_printer.go @@ -6,6 +6,7 @@ import ( "atomicgo.dev/cursor" "atomicgo.dev/keyboard" "atomicgo.dev/keyboard/keys" + "github.com/mattn/go-runewidth" "github.com/pterm/pterm/internal" ) @@ -101,7 +102,7 @@ func (p InteractiveTextInputPrinter) Show(text ...string) (string, error) { area.StartOfLine() if !p.MultiLine { - cursor.Right(len(RemoveColorFromString(areaText))) + cursor.Right(runewidth.StringWidth(RemoveColorFromString(areaText))) } if p.DefaultValue != "" { diff --git a/vendor/github.com/pterm/pterm/logger.go b/vendor/github.com/pterm/pterm/logger.go index 26eea5b0..407f4d50 100644 --- a/vendor/github.com/pterm/pterm/logger.go +++ b/vendor/github.com/pterm/pterm/logger.go @@ -211,6 +211,8 @@ func (l Logger) Args(args ...any) []LoggerArgument { var loggerArgs []LoggerArgument // args are in the format of: key, value, key, value, key, value, ... + args = l.sanitizeArgs(args) + for i := 0; i < len(args); i += 2 { key := Sprint(args[i]) value := args[i+1] @@ -238,6 +240,20 @@ func (l Logger) ArgsFromMap(m map[string]any) []LoggerArgument { return loggerArgs } +// sanitizeArgs inserts an error message into an args slice if an odd number of arguments is provided. +func (l Logger) sanitizeArgs(args []any) []any { + numArgs := len(args) + if numArgs > 0 && numArgs%2 != 0 { + if numArgs > 1 { + lastArg := args[numArgs-1] + args = append(args[:numArgs-1], []any{ErrKeyWithoutValue, lastArg}...) + } else { + args = []any{ErrKeyWithoutValue, args[0]} + } + } + return args +} + func (l Logger) getCallerInfo() (path string, line int) { if !l.ShowCaller { return @@ -280,7 +296,7 @@ func (l Logger) print(level LogLevel, msg string, args []LoggerArgument) { loggerMutex.Lock() defer loggerMutex.Unlock() - _, _ = l.Writer.Write([]byte(line + "\n")) + Fprintln(l.Writer, line) } func (l Logger) renderColorful(level LogLevel, msg string, args []LoggerArgument) (result string) { diff --git a/vendor/github.com/pterm/pterm/panel_printer.go b/vendor/github.com/pterm/pterm/panel_printer.go index 709f7c80..090498e7 100644 --- a/vendor/github.com/pterm/pterm/panel_printer.go +++ b/vendor/github.com/pterm/pterm/panel_printer.go @@ -183,7 +183,7 @@ func (p PanelPrinter) Srender() (string, error) { // Render prints the Template to the terminal. func (p PanelPrinter) Render() error { s, _ := p.Srender() - Println(s) + Fprintln(p.Writer, s) return nil } diff --git a/vendor/github.com/pterm/pterm/print.go b/vendor/github.com/pterm/pterm/print.go index a58e5fa6..67b49c02 100644 --- a/vendor/github.com/pterm/pterm/print.go +++ b/vendor/github.com/pterm/pterm/print.go @@ -3,13 +3,17 @@ package pterm import ( "fmt" "io" + "os" "strings" "github.com/gookit/color" ) +var defaultWriter io.Writer = os.Stdout + // SetDefaultOutput sets the default output of pterm. func SetDefaultOutput(w io.Writer) { + defaultWriter = w color.SetOutput(w) } @@ -45,7 +49,7 @@ func Sprinto(a ...interface{}) string { // Spaces are added between operands when neither is a string. // It returns the number of bytes written and any write error encountered. func Print(a ...interface{}) { - Fprint(nil, a...) + Fprint(defaultWriter, a...) } // Println formats using the default formats for its operands and writes to standard output. diff --git a/vendor/github.com/pterm/pterm/progressbar_printer.go b/vendor/github.com/pterm/pterm/progressbar_printer.go index 1cf4a0c2..d2bb35c1 100644 --- a/vendor/github.com/pterm/pterm/progressbar_printer.go +++ b/vendor/github.com/pterm/pterm/progressbar_printer.go @@ -6,6 +6,7 @@ import ( "fmt" "io" "math" + "os" "strings" "time" @@ -32,6 +33,7 @@ var DefaultProgressbar = ProgressbarPrinter{ ShowElapsedTime: true, BarFiller: Gray("█"), MaxWidth: 80, + Writer: os.Stdout, } // ProgressbarPrinter shows a progress animation in the terminal. diff --git a/vendor/github.com/pterm/pterm/rgb.go b/vendor/github.com/pterm/pterm/rgb.go index a35dd1a0..7c00835a 100644 --- a/vendor/github.com/pterm/pterm/rgb.go +++ b/vendor/github.com/pterm/pterm/rgb.go @@ -136,13 +136,13 @@ func (p RGBStyle) Sprintln(a ...interface{}) string { // Sprintf formats according to a format specifier and returns the resulting string. func (p RGBStyle) Sprintf(format string, a ...interface{}) string { - return fmt.Sprintf(format, p.Sprint(a...)) + return p.Sprint(Sprintf(format, a...)) } // Sprintfln formats according to a format specifier and returns the resulting string. // Spaces are always added between operands and a newline is appended. func (p RGBStyle) Sprintfln(format string, a ...interface{}) string { - return fmt.Sprintf(format, p.Sprint(a...)) + "\n" + return p.Sprintf(format, a...) + "\n" } // GetValues returns the RGB values separately. diff --git a/vendor/modules.txt b/vendor/modules.txt index c76be9f9..8384743f 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -238,7 +238,7 @@ github.com/pjbgf/sha1cd/ubc # github.com/pkg/errors v0.9.1 ## explicit github.com/pkg/errors -# github.com/pterm/pterm v0.12.74 +# github.com/pterm/pterm v0.12.78 ## explicit; go 1.21 github.com/pterm/pterm github.com/pterm/pterm/internal