from collections import defaultdict from itertools import chain from operator import itemgetter from typing import Dict, Iterable, List, Optional, Tuple
from .align import Align, AlignMethod from .console import Console, ConsoleOptions, RenderableType, RenderResult from .constrain import Constrain from .measure import Measurement from .padding import Padding, PaddingDimensions from .table import Table from .text import TextType from .jupyter import JupyterMixin
class Columns(JupyterMixin): """Display renderables in neat columns.
Args:
renderables (Iterable[RenderableType]): Any number of Rich renderables (including str).
width (int, optional): The desired width of the columns, orNone to auto detect. Defaults to None.
padding (PaddingDimensions, optional): Optional padding around cells. Defaults to (0, 1).
expand (bool, optional): Expand columns to full width. Defaults to False.
equal (bool, optional): Arrange in to equal sized columns. Defaults to False.
column_first (bool, optional): Align items from top to bottom (rather than left to right). Defaults to False.
right_to_left (bool, optional): Start column from right hand side. Defaults to False.
align (str, optional): Align value ("left", "right", or"center") orNonefor default. Defaults to None.
title (TextType, optional): Optional title for Columns. """
column_lengths: List[int] = [item_count // column_count] * column_count for col_no in range(item_count % column_count):
column_lengths[col_no] += 1
row_count = (item_count + column_count - 1) // column_count
cells = [[-1] * column_count for _ in range(row_count)]
row = col = 0 for index in range(item_count):
cells[row][col] = index
column_lengths[col] -= 1 if column_lengths[col]:
row += 1 else:
col += 1
row = 0 for index in chain.from_iterable(cells): if index == -1: break yield width_renderables[index] else: yieldfrom zip(renderable_widths, renderables) # Pad odd elements with spaces if item_count % column_count: for _ in range(column_count - (item_count % column_count)): yield 0, None
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.