Skip to content

Commit

Permalink
Add output configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
tothszabi committed Dec 6, 2023
1 parent 76b3d8e commit a0e03da
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 6 additions & 2 deletions progress/spinner.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ func NewSpinner(message string, chars []string, delay time.Duration, writer io.W

// NewDefaultSpinner ...
func NewDefaultSpinner(message string) Spinner {
return NewDefaultSpinnerWithOutput(message, os.Stdout)
}

// NewDefaultSpinnerWithOutput ...
func NewDefaultSpinnerWithOutput(message string, output io.Writer) Spinner {
chars := []string{"⣾", "⣽", "⣻", "⢿", "⡿", "⣟", "⣯", "⣷"}
delay := 100 * time.Millisecond
writer := os.Stdout
return NewSpinner(message, chars, delay, writer)
return NewSpinner(message, chars, delay, output)
}

func (s *Spinner) erase() {
Expand Down
8 changes: 8 additions & 0 deletions progress/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package progress

import (
"fmt"
"io"
"os"
"strings"

Expand Down Expand Up @@ -30,6 +31,13 @@ func NewDefaultWrapper(message string) Wrapper {
return NewWrapper(spinner, interactiveMode)
}

// NewDefaultWrapperWithOutput ...
func NewDefaultWrapperWithOutput(message string, output io.Writer) Wrapper {
spinner := NewDefaultSpinnerWithOutput(message, output)
interactiveMode := OutputDeviceIsTerminal()
return NewWrapper(spinner, interactiveMode)
}

// WrapAction ...
func (w Wrapper) WrapAction(action func()) {
if w.interactiveMode {
Expand Down

0 comments on commit a0e03da

Please sign in to comment.