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
|
package spin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/charmbracelet/gum/internal/exit"
|
"github.com/charmbracelet/gum/internal/exit"
|
||||||
"github.com/charmbracelet/gum/timeout"
|
"github.com/charmbracelet/gum/timeout"
|
||||||
|
"github.com/mattn/go-isatty"
|
||||||
|
|
||||||
"github.com/charmbracelet/bubbles/spinner"
|
"github.com/charmbracelet/bubbles/spinner"
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
@ -56,8 +58,12 @@ func commandStart(command []string) tea.Cmd {
|
|||||||
}
|
}
|
||||||
cmd := exec.Command(command[0], args...) //nolint:gosec
|
cmd := exec.Command(command[0], args...) //nolint:gosec
|
||||||
|
|
||||||
cmd.Stdout = &outbuf
|
if isatty.IsTerminal(os.Stdout.Fd()) {
|
||||||
cmd.Stderr = &errbuf
|
cmd.Stdout = &outbuf
|
||||||
|
cmd.Stderr = &errbuf
|
||||||
|
} else {
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
}
|
||||||
|
|
||||||
_ = cmd.Run()
|
_ = cmd.Run()
|
||||||
|
|
||||||
@ -82,8 +88,8 @@ func (m model) Init() tea.Cmd {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
func (m model) View() string {
|
func (m model) View() string {
|
||||||
if m.quitting {
|
if m.quitting && m.showOutput {
|
||||||
return ""
|
return strings.TrimPrefix(errbuf.String()+"\n"+outbuf.String(), "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
var str string
|
var str string
|
||||||
|
Loading…
Reference in New Issue
Block a user