Skip to content

Commit

Permalink
fix(spinner): direct spinner to stderr instead of stdout
Browse files Browse the repository at this point in the history
otherwise weird spinner output is printed to stuff that get's piped from the command line
  • Loading branch information
b5 committed Nov 14, 2018
1 parent 5f0bbae commit d32c227
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions streams.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ func (s IOStreams) SpinnerMsg(msg string) {
s.sp.Suffix = msg
}

// Close checks to see if any/all of in/out/errOut are closable,
// and if so closes them
func (s IOStreams) Close() error {
// TODO
return nil
}

// Print writes a msg to the Out stream
func (s IOStreams) Print(msg string) {
if s.SpinnerActive() {
Expand All @@ -59,24 +66,30 @@ func (s IOStreams) Print(msg string) {

// NewIOStreams creates streams
func NewIOStreams(in io.Reader, out, errOut io.Writer) IOStreams {
sp := spinner.New(spinner.CharSets[24], 100*time.Millisecond)
sp.Writer = errOut

return IOStreams{
In: in,
Out: out,
ErrOut: errOut,

sp: spinner.New(spinner.CharSets[24], 100*time.Millisecond),
sp: sp,
}
}

// NewStdIOStreams creates a standard set of streams, with in, out, and error mapped
// to os.Stdin, os.Stdout, and os.Stderr respectively
func NewStdIOStreams() IOStreams {
sp := spinner.New(spinner.CharSets[24], 100*time.Millisecond)
sp.Writer = os.Stderr

return IOStreams{
In: os.Stdin,
Out: os.Stdout,
ErrOut: os.Stderr,

sp: spinner.New(spinner.CharSets[24], 100*time.Millisecond),
sp: sp,
}
}

Expand Down

0 comments on commit d32c227

Please sign in to comment.