Skip to content

Commit

Permalink
fix(spin): if not a tty, only print title, do not open tty for stdin
Browse files Browse the repository at this point in the history
closes #328
  • Loading branch information
caarlos0 committed Dec 11, 2024
1 parent b0c9c58 commit fc74272
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
12 changes: 9 additions & 3 deletions spin/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
5 changes: 5 additions & 0 deletions spin/spin.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type model struct {
align string
command []string
quitting bool
isTTY bool
status int
stdout string
stderr string
Expand Down Expand Up @@ -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")
}
Expand Down

0 comments on commit fc74272

Please sign in to comment.