@@ -3,6 +3,7 @@ package jsonstream
33import (
44 "context"
55 "io"
6+ "iter"
67
78 "github.com/docker/cli/cli/streams"
89 "github.com/moby/moby/api/types/jsonstream"
@@ -41,13 +42,18 @@ func WithAuxCallback(cb func(JSONMessage)) Options {
4142 }
4243}
4344
45+ type ProgressResponse interface {
46+ io.ReadCloser
47+ JSONMessages (ctx context.Context ) iter.Seq2 [jsonstream.Message , error ]
48+ }
49+
4450// Display prints the JSON messages from the given reader to the given stream.
4551//
46- // It wraps the [jsonmessage.DisplayJSONMessagesStream ] function to make it
52+ // It wraps the [jsonmessage.DisplayJSONMessages ] function to make it
4753// "context aware" and appropriately returns why the function was canceled.
4854//
4955// It returns an error if the context is canceled, but not if the input reader / stream is closed.
50- func Display (ctx context.Context , in io. Reader , stream * streams.Out , opts ... Options ) error {
56+ func Display (ctx context.Context , in ProgressResponse , stream * streams.Out , opts ... Options ) error {
5157 if ctx .Err () != nil {
5258 return ctx .Err ()
5359 }
@@ -61,7 +67,7 @@ func Display(ctx context.Context, in io.Reader, stream *streams.Out, opts ...Opt
6167 opt (& o )
6268 }
6369
64- if err := jsonmessage .DisplayJSONMessagesStream ( reader , stream , stream .FD (), stream .IsTerminal (), o .AuxCallback ); err != nil {
70+ if err := jsonmessage .DisplayJSONMessages ( in . JSONMessages ( ctx ) , stream , stream .FD (), stream .IsTerminal (), o .AuxCallback ); err != nil {
6571 return err
6672 }
6773
0 commit comments