Skip to content

Commit

Permalink
Reset the buffer when constructing the spinner
Browse files Browse the repository at this point in the history
This needs to be done, otherwise the buffer will print null bytes at the
beginning of the first line.
  • Loading branch information
theckman committed Dec 15, 2021
1 parent 4b45330 commit d19965d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion spinner.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,11 @@ func New(cfg Config) (*Spinner, error) {
cfg.NotTTY = true
}

buf := bytes.NewBuffer(make([]byte, 2048))
buf.Reset()

s := &Spinner{
buffer: bytes.NewBuffer(make([]byte, 2048)),
buffer: buf,
mu: &sync.Mutex{},
frequency: cfg.Frequency,
status: uint32Ptr(0),
Expand Down
4 changes: 4 additions & 0 deletions spinner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ func TestNew(t *testing.T) {
t.Fatal("spinner is nil")
}

if n := spinner.buffer.Len(); n != 0 {
t.Fatalf("spinner.buffer.Len() = %d, want 0", n)
}

if spinner.colorAll != tt.cfg.ColorAll {
t.Fatalf("spinner.colorAll = %t, want %t", spinner.colorAll, tt.cfg.ColorAll)
}
Expand Down

0 comments on commit d19965d

Please sign in to comment.