Update HandleDelayedResponse to return to complete output

This commit is contained in:
Matt Low 2023-11-05 07:40:55 +00:00
parent 1ac8f7d046
commit 78bcc11a4b
1 changed files with 9 additions and 3 deletions

View File

@ -2,6 +2,7 @@ package cli
import ( import (
"fmt" "fmt"
"strings"
"time" "time"
) )
@ -33,12 +34,14 @@ func ShowWaitAnimation(signal chan any) {
} }
// HandledDelayedResponse writes a waiting animation (abusing \r) and the // HandledDelayedResponse writes a waiting animation (abusing \r) and the
// content received on the response channel to stdout. Blocks until the channel // (possibly chunked) content received on the response channel to stdout.
// is closed. // Blocks until the channel is closed.
func HandleDelayedResponse(response chan string) { func HandleDelayedResponse(response chan string) string {
waitSignal := make(chan any) waitSignal := make(chan any)
go ShowWaitAnimation(waitSignal) go ShowWaitAnimation(waitSignal)
sb := strings.Builder{}
firstChunk := true firstChunk := true
for chunk := range response { for chunk := range response {
if firstChunk { if firstChunk {
@ -47,5 +50,8 @@ func HandleDelayedResponse(response chan string) {
firstChunk = false firstChunk = false
} }
fmt.Print(chunk) fmt.Print(chunk)
sb.WriteString(chunk)
} }
return sb.String()
} }