Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions internal/io/spinner.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import (
)

func SpinWhile(name string, action func()) error {
if isatty.IsTerminal(os.Stdout.Fd()) {
if !isatty.IsTerminal(os.Stdout.Fd()) {
// No TTY available, just run the action without spinner
action()

return nil
}

// TTY is available, use the spinner
return spinner.New().
Title(name).
Action(action).
Expand Down
21 changes: 21 additions & 0 deletions internal/io/spinner_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io

import (
"testing"
)

func TestSpinWhileWithoutTTY(t *testing.T) {
// Test that SpinWhile works without TTY
actionCalled := false
err := SpinWhile("Test action", func() {
actionCalled = true
})

if err != nil {
t.Errorf("SpinWhile should not return error: %v", err)
}

if !actionCalled {
t.Error("Action should have been called")
}
}