mirror of
https://github.com/charmbracelet/gum.git
synced 2024-09-11 06:16:03 +03:00
feat(spin): stdout streaming (#467)
This commit is contained in:
parent
4a00db207a
commit
6a275b423f
14
spin/spin.go
14
spin/spin.go
@ -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"
|
||||
@ -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()
|
||||
|
||||
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user