Skip to content
Myr

fix: spin when not a tty (#813)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* fix: spin when not a tty * fix: typo

authored by Carlos Alexandro Becker · committed by GitHub · parent 7e3216e · Browse files · 1 file+10 added−13 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+10 added−13 removed

  • other:+10 added−13 removed

1 file+10 added−13 removed

modified:spin/command.go+10 added-13 removed
12 unmodified lines
1314// Run provides a shell script interface for the spinner bubble.15// https://github.com/charmbracelet/bubbles/spinner16func (o Options) Run() error {17 isTTY := term.IsTerminal(os.Stdout.Fd())17 isOutTTY := term.IsTerminal(os.Stdout.Fd())18 isErrTTY := term.IsTerminal(os.Stderr.Fd())1920 s := spinner.New()21 s.Style = o.SpinnerStyle.ToLipgloss()22 s.Spinner = spinnerMap[o.Spinner]
1 unmodified line
24 spinner: s,25 title: o.TitleStyle.ToLipgloss().Render(o.Title),26 command: o.Command,27 align: o.Align,27 showStdout: (o.ShowOutput || o.ShowStdout) && isTTY,28 showStderr: (o.ShowOutput || o.ShowStderr) && isTTY,28 showStdout: (o.ShowOutput || o.ShowStdout) && isOutTTY,29 showStderr: (o.ShowOutput || o.ShowStderr) && isErrTTY,30 showError: o.ShowError,30 isTTY: isTTY,31 isTTY: isErrTTY,32 }3334 ctx, cancel := timeout.Context(o.Timeout)35 defer cancel()3636 opts := []tea.ProgramOption{37 tm, err := tea.NewProgram(38 m,39 tea.WithOutput(os.Stderr),40 tea.WithContext(ctx),39 }4041 if !isTTY {42 opts = append(opts, tea.WithInput(nil))43 }4445 tm, err := tea.NewProgram(m, opts...).Run()41 tea.WithInput(nil),42 ).Run()43 if err != nil {44 return fmt.Errorf("unable to run action: %w", err)45 }46
4 unmodified lines
51 if m.status == 0 {52 if o.ShowOutput {53 // BubbleTea writes the View() to stderr.54 // If the program is being piped then put the accumulated output in stdout.58 if !isTTY {55 if !isOutTTY {56 _, err := os.Stdout.WriteString(m.stdout)57 if err != nil {58 return fmt.Errorf("failed to write to stdout: %w", err)59 }
13 unmodified lines