Skip to content

Commit 71af32c

Browse files
committed
fix(spin): properly redirect output
closes #690
1 parent c422e76 commit 71af32c

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

spin/spin.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ package spin
1616

1717
import (
1818
"io"
19+
"os"
1920
"os/exec"
2021
"strings"
2122
"syscall"
2223
"time"
2324

2425
"github.com/charmbracelet/gum/internal/exit"
2526
"github.com/charmbracelet/gum/timeout"
27+
"github.com/charmbracelet/x/term"
2628

2729
"github.com/charmbracelet/bubbles/spinner"
2830
tea "github.com/charmbracelet/bubbletea"
@@ -68,8 +70,12 @@ func commandStart(command []string) tea.Cmd {
6870
}
6971

7072
executing = exec.Command(command[0], args...) //nolint:gosec
71-
executing.Stdout = io.MultiWriter(&bothbuf, &outbuf)
72-
executing.Stderr = io.MultiWriter(&bothbuf, &errbuf)
73+
if term.IsTerminal(os.Stdout.Fd()) {
74+
executing.Stdout = io.MultiWriter(&bothbuf, &outbuf)
75+
executing.Stderr = io.MultiWriter(&bothbuf, &errbuf)
76+
} else {
77+
executing.Stdout = os.Stdout
78+
}
7379
_ = executing.Run()
7480
status := executing.ProcessState.ExitCode()
7581
if status == -1 {

0 commit comments

Comments
 (0)