diff --git a/internal/io/spinner.go b/internal/io/spinner.go index 715db927..565d90cc 100644 --- a/internal/io/spinner.go +++ b/internal/io/spinner.go @@ -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). diff --git a/internal/io/spinner_test.go b/internal/io/spinner_test.go new file mode 100644 index 00000000..ae3c7788 --- /dev/null +++ b/internal/io/spinner_test.go @@ -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") + } +}