From 78bcc11a4b18a7d805b7dcac21cc2dd8302ce7c6 Mon Sep 17 00:00:00 2001 From: Matt Low Date: Sun, 5 Nov 2023 07:40:55 +0000 Subject: [PATCH] Update HandleDelayedResponse to return to complete output --- pkg/cli/tty.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/cli/tty.go b/pkg/cli/tty.go index 80bf21f..5260162 100644 --- a/pkg/cli/tty.go +++ b/pkg/cli/tty.go @@ -2,6 +2,7 @@ package cli import ( "fmt" + "strings" "time" ) @@ -33,12 +34,14 @@ func ShowWaitAnimation(signal chan any) { } // HandledDelayedResponse writes a waiting animation (abusing \r) and the -// content received on the response channel to stdout. Blocks until the channel -// is closed. -func HandleDelayedResponse(response chan string) { +// (possibly chunked) content received on the response channel to stdout. +// Blocks until the channel is closed. +func HandleDelayedResponse(response chan string) string { waitSignal := make(chan any) go ShowWaitAnimation(waitSignal) + sb := strings.Builder{} + firstChunk := true for chunk := range response { if firstChunk { @@ -47,5 +50,8 @@ func HandleDelayedResponse(response chan string) { firstChunk = false } fmt.Print(chunk) + sb.WriteString(chunk) } + + return sb.String() }