Display prints the JSON messages from the given reader to the given stream. It wraps the [jsonmessage.DisplayJSONMessagesStream] function to make it "context aware" and appropriately returns why the function was canceled. It returns an error if the context is canceled, but not if the input reader
(ctx context.Context, in io.Reader, stream *streams.Out, opts ...Options)
| 48 | // |
| 49 | // 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 { |
| 51 | if ctx.Err() != nil { |
| 52 | return ctx.Err() |
| 53 | } |
| 54 | |
| 55 | reader := &ctxReader{err: make(chan error, 1), r: in} |
| 56 | stopFunc := context.AfterFunc(ctx, func() { reader.err <- ctx.Err() }) |
| 57 | defer stopFunc() |
| 58 | |
| 59 | o := options{} |
| 60 | for _, opt := range opts { |
| 61 | opt(&o) |
| 62 | } |
| 63 | |
| 64 | if err := jsonmessage.DisplayJSONMessagesStream(reader, stream, stream.FD(), stream.IsTerminal(), o.AuxCallback); err != nil { |
| 65 | return err |
| 66 | } |
| 67 | |
| 68 | return ctx.Err() |
| 69 | } |
searching dependent graphs…