Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions libs/cmdio/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,21 @@ func Render(ctx context.Context, v any) error {
// locked from the first batch so columns stay aligned across pages).
// Piped output and JSON output keep the existing non-paged behavior.
func RenderIterator[T any](ctx context.Context, i listing.Iterator[T]) error {
return renderAnyIterator(ctx, anyIterator[T]{i})
}

// anyIterator erases the element type so that the renderers and pager below
// are instantiated once rather than once per listed SDK type, which
// otherwise adds megabytes to the binary.
type anyIterator[T any] struct {
listing.Iterator[T]
}

func (a anyIterator[T]) Next(ctx context.Context) (any, error) {
return a.Iterator.Next(ctx)
}

func renderAnyIterator(ctx context.Context, i listing.Iterator[any]) error {
c := fromContext(ctx)
if c.capabilities.SupportsPager() && c.outputFormat == flags.OutputText && c.template != "" {
return renderIteratorPagedTemplate(ctx, i, c.in, c.out, c.headerTemplate, c.template)
Expand Down
Loading