diff --git a/cli/cliui/agent.go b/cli/cliui/agent.go index afe2e464c0..023891f678 100644 --- a/cli/cliui/agent.go +++ b/cli/cliui/agent.go @@ -58,6 +58,7 @@ func Agent(ctx context.Context, writer io.Writer, opts AgentOptions) error { return case <-stopSpin: } + cancelFunc() signal.Stop(stopSpin) spin.Stop() // nolint:revive @@ -83,10 +84,16 @@ func Agent(ctx context.Context, writer io.Writer, opts AgentOptions) error { } waitMessage = m - // This saves the cursor position, then defers clearing from the cursor - // position to the end of the screen. - _, _ = fmt.Fprintf(writer, "\033[s\r\033[2K%s%s\n\n", moveUp, Styles.Paragraph.Render(Styles.Prompt.String()+waitMessage)) - defer fmt.Fprintf(writer, "\033[u\033[J") + // Stop the spinner while we write our message. + spin.Stop() + // Clear the line and (if necessary) move up a line to write our message. + _, _ = fmt.Fprintf(writer, "\033[2K%s%s\n\n", moveUp, Styles.Paragraph.Render(Styles.Prompt.String()+waitMessage)) + select { + case <-ctx.Done(): + default: + // Safe to resume operation. + spin.Start() + } } go func() { select {