Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5fb9c33

Browse files
authored
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
1 parent e847276 commit 5fb9c33

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

cli/cliui/agent.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ func Agent(ctx context.Context, writer io.Writer, opts AgentOptions) error {
5858
return
5959
case <-stopSpin:
6060
}
61+
cancelFunc()
6162
signal.Stop(stopSpin)
6263
spin.Stop()
6364
// nolint:revive
@@ -83,10 +84,16 @@ func Agent(ctx context.Context, writer io.Writer, opts AgentOptions) error {
8384
}
8485
waitMessage = m
8586

86-
// This saves the cursor position, then defers clearing from the cursor
87-
// position to the end of the screen.
88-
_, _ = fmt.Fprintf(writer, "\033[s\r\033[2K%s%s\n\n", moveUp, Styles.Paragraph.Render(Styles.Prompt.String()+waitMessage))
89-
defer fmt.Fprintf(writer, "\033[u\033[J")
87+
// Stop the spinner while we write our message.
88+
spin.Stop()
89+
// Clear the line and (if necessary) move up a line to write our message.
90+
_, _ = fmt.Fprintf(writer, "\033[2K%s%s\n\n", moveUp, Styles.Paragraph.Render(Styles.Prompt.String()+waitMessage))
91+
select {
92+
case <-ctx.Done():
93+
default:
94+
// Safe to resume operation.
95+
spin.Start()
96+
}
9097
}
9198
go func() {
9299
select {

0 commit comments

Comments
 (0)