From fc74272bf5a77e373b70239b196c575bf0060ef8 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Tue, 10 Dec 2024 21:47:00 -0300 Subject: [PATCH] fix(spin): if not a tty, only print title, do not open tty for stdin closes #328 --- spin/command.go | 12 +++++++++--- spin/spin.go | 5 +++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/spin/command.go b/spin/command.go index 5dd04eb7a..a792b3f9b 100644 --- a/spin/command.go +++ b/spin/command.go @@ -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) } diff --git a/spin/spin.go b/spin/spin.go index bcf7c8dde..1a3880080 100644 --- a/spin/spin.go +++ b/spin/spin.go @@ -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") }