From 5fb9c33ecd6a0caa8e9ebd3882b20476b3f729e1 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Thu, 10 Nov 2022 20:21:38 +0200 Subject: [PATCH] fix: Fix ssh message/spinner in VSCode integrated terminal (#5000) * fix: Fix ssh message/spinner in VSCode integrated terminal The messages never show up in VSCode integrated terminal due to the defer `fmt.Fprintf`. There could be a race in VSCode in handling the terminal codes but ultimately, we can simplify our logic by just stopping the spinner for the duration of the update. * Avoid race in starting spinner after exit --- cli/cliui/agent.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) 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 {