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
This commit is contained in:
Mathias Fredriksson
2022-11-10 18:21:38 +00:00
committed by GitHub
parent e847276d74
commit 5fb9c33ecd
+11 -4
View File
@@ -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 {