mirror of
https://github.com/coder/coder.git
synced 2026-09-22 05:05:20 +08:00
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:
+11
-4
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user