Skip to content

Commit

Permalink
Merge pull request #49 from theckman/reset_buffer
Browse files Browse the repository at this point in the history
Reset the buffer when constructing the spinner
  • Loading branch information
theckman committed Dec 15, 2021
2 parents 4b45330 + d19965d commit 5a67d42
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 5a67d42

Please sign in to comment.