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() }