tabulardelta.formatters.tabulartext.cell module
- class tabulardelta.formatters.tabulartext.cell.Align(vertical: Callable[[list[str], int], list[str]], horizontal: Callable[[str, int], str])[source]
Bases:
objectImplementation of
Aligner, for aligning cell content given a target size.- Offers out-of-the-box alignment styles as class attributes:
TopLeft,MidLeft,MidCenter, andRepeat.Each can be customized with an optional fill character (see
AlignOptionalChar).
Implement
verticalandhorizontalfor specialized alignment styles.Methods
__call__(self, content: list[str], width: int, height: int) -> list[str]:
Implements
Aligner- class AlignOptionalChar(*args, **kwargs)[source]
Bases:
ProtocolProtocol for customizing out-of-the-box alignments with an optional fill character.
- Arguments:
- char
str: Optional fill character for the alignment. Default is a space.
- char
- Returns
Align: An Aligner with the specified fill character.
Methods
__call__(self, char: str = “ “) -> Align:
Gets the
Aligninstance
- MidCenter()[source]
AlignOptionalCharthat aligns content in the middle.
- MidLeft()[source]
AlignOptionalCharthat aligns content to the left, but vertically centered.
- Repeat()[source]
AlignOptionalCharthat repeats the content through the cells.
- TopLeft()[source]
AlignOptionalCharthat aligns content towards the top left.
- horizontal: Callable[[str, int], str]
Callable adding characters to a line to reach the given width.
- vertical: Callable[[list[str], int], list[str]]
Callable adding lines to the cell content to reach the given height.
- class tabulardelta.formatters.tabulartext.cell.Aligner(*args, **kwargs)[source]
Bases:
ProtocolAligner is a protocol for aligning existing cell content within a larger target size.
- Arguments:
- content
list[str]: Original cell content to be aligned.
- width
int: Target width of cell content, not smaller than length of any line in the original content.
- height
int: Target height of cell content, not smaller than number of lines of the original content.
- content
- Returns
list[str]: Cell content with height number of lines, each with length width.
Methods
__call__(self, content: list[str], width: int, height: int) -> list[str]:
Resize cell content to a target size.
- class tabulardelta.formatters.tabulartext.cell.Cell(content: list[str] = <factory>, align: ~tabulardelta.formatters.tabulartext.cell.Aligner = Align(vertical=<function <lambda>.<locals>.<lambda>>, horizontal=<function <lambda>.<locals>.<lambda>>), colspan: int = 1, rowspan: int = 1)[source]
Bases:
objectRepresents a table cell with alignable content, which might span multiple columns and rows.
Methods
fill(self, width: int, height: int) -> list[str]:
Increase size of table content using
align- align: Aligner = Align(vertical=<function <lambda>.<locals>.<lambda>>, horizontal=<function <lambda>.<locals>.<lambda>>)
Alignment strategy (see
Aligner).
- colspan: int = 1
Number of columns to span.
- content: list[str]
Line-separated cell content.
- fill(width: int, height: int) list[str][source]
Return cell content resized to a target size by using
alignstrategy.- Arguments:
- width
int: The target width for the cell.
- height
int: The target height for the cell.
- width
- Returns
list[str]: The resized line-separated content.
- rowspan: int = 1
Number of rows to span.