Skip to content

Commit

Permalink
chore: improve spinner with --no-progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Racer159 committed May 29, 2024
1 parent 849a3b3 commit ffd2262
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/message/spinner.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"bufio"
"bytes"
"fmt"
"os"
"strings"

"github.com/defenseunicorns/pkg/helpers/v2"
Expand Down Expand Up @@ -56,7 +57,7 @@ var NewProgressSpinner = func(format string, a ...any) helpers.ProgressWriter {
func (p *Spinner) Write(raw []byte) (int, error) {
size := len(raw)
if NoProgress {
pterm.Printfln(" %s", string(raw))
os.Stderr.Write(raw)

return size, nil
}
Expand All @@ -66,7 +67,8 @@ func (p *Spinner) Write(raw []byte) (int, error) {
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
text := pterm.Sprintf(" %s", scanner.Text())
pterm.Fprinto(p.spinner.Writer, strings.Repeat(" ", pterm.GetTerminalWidth()))
// Clear the current line with the ANSI escape code
pterm.Fprinto(p.spinner.Writer, "\033[K")
pterm.Fprintln(p.spinner.Writer, text)
}

Expand Down

0 comments on commit ffd2262

Please sign in to comment.