Skip to content

Commit

Permalink
feat(spin): stdout streaming (#467)
Browse files Browse the repository at this point in the history
  • Loading branch information
maaslalani authored Dec 21, 2023
1 parent 4a00db2 commit 6a275b4
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions spin/spin.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
package spin

import (
"os"
"os/exec"
"strings"
"time"

"github.com/charmbracelet/gum/internal/exit"
"github.com/charmbracelet/gum/timeout"
"github.com/mattn/go-isatty"

"github.com/charmbracelet/bubbles/spinner"
tea "github.com/charmbracelet/bubbletea"
Expand Down Expand Up @@ -56,8 +58,12 @@ func commandStart(command []string) tea.Cmd {
}
cmd := exec.Command(command[0], args...) //nolint:gosec

cmd.Stdout = &outbuf
cmd.Stderr = &errbuf
if isatty.IsTerminal(os.Stdout.Fd()) {
cmd.Stdout = &outbuf
cmd.Stderr = &errbuf
} else {
cmd.Stdout = os.Stdout
}

_ = cmd.Run()

Expand All @@ -82,8 +88,8 @@ func (m model) Init() tea.Cmd {
)
}
func (m model) View() string {
if m.quitting {
return ""
if m.quitting && m.showOutput {
return strings.TrimPrefix(errbuf.String()+"\n"+outbuf.String(), "\n")
}

var str string
Expand Down

0 comments on commit 6a275b4

Please sign in to comment.