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

View File

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