mirror of
https://github.com/charmbracelet/gum
synced 2026-03-14 21:55:45 +01:00
fix(spin): if not a tty, only print title, do not open tty for stdin (#763)
closes #328
This commit is contained in:
parent
2e53efc0ec
commit
cf2da6406c
2 changed files with 14 additions and 3 deletions
|
|
@ -26,16 +26,22 @@ func (o Options) Run() error {
|
|||
align: o.Align,
|
||||
showOutput: o.ShowOutput && isTTY,
|
||||
showError: o.ShowError,
|
||||
isTTY: isTTY,
|
||||
}
|
||||
|
||||
ctx, cancel := timeout.Context(o.Timeout)
|
||||
defer cancel()
|
||||
|
||||
tm, err := tea.NewProgram(
|
||||
m,
|
||||
opts := []tea.ProgramOption{
|
||||
tea.WithOutput(os.Stderr),
|
||||
tea.WithContext(ctx),
|
||||
).Run()
|
||||
}
|
||||
|
||||
if !isTTY {
|
||||
opts = append(opts, tea.WithInput(nil))
|
||||
}
|
||||
|
||||
tm, err := tea.NewProgram(m, opts...).Run()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to run action: %w", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ type model struct {
|
|||
align string
|
||||
command []string
|
||||
quitting bool
|
||||
isTTY bool
|
||||
status int
|
||||
stdout string
|
||||
stderr string
|
||||
|
|
@ -101,6 +102,10 @@ func (m model) Init() tea.Cmd {
|
|||
}
|
||||
|
||||
func (m model) View() string {
|
||||
if !m.isTTY {
|
||||
return m.title
|
||||
}
|
||||
|
||||
if m.quitting && m.showOutput {
|
||||
return strings.TrimPrefix(errbuf.String()+"\n"+outbuf.String(), "\n")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue