Get all the cells with padding and optional header.
(
self, console: "Console", column_index: int, column: Column
)
| 625 | return widths |
| 626 | |
| 627 | def _get_cells( |
| 628 | self, console: "Console", column_index: int, column: Column |
| 629 | ) -> Iterable[_Cell]: |
| 630 | """Get all the cells with padding and optional header.""" |
| 631 | |
| 632 | collapse_padding = self.collapse_padding |
| 633 | pad_edge = self.pad_edge |
| 634 | padding = self.padding |
| 635 | any_padding = any(padding) |
| 636 | |
| 637 | first_column = column_index == 0 |
| 638 | last_column = column_index == len(self.columns) - 1 |
| 639 | |
| 640 | _padding_cache: Dict[Tuple[bool, bool], Tuple[int, int, int, int]] = {} |
| 641 | |
| 642 | def get_padding(first_row: bool, last_row: bool) -> Tuple[int, int, int, int]: |
| 643 | cached = _padding_cache.get((first_row, last_row)) |
| 644 | if cached: |
| 645 | return cached |
| 646 | top, right, bottom, left = padding |
| 647 | |
| 648 | if collapse_padding: |
| 649 | if not first_column: |
| 650 | left = max(0, left - right) |
| 651 | if not last_row: |
| 652 | bottom = max(0, top - bottom) |
| 653 | |
| 654 | if not pad_edge: |
| 655 | if first_column: |
| 656 | left = 0 |
| 657 | if last_column: |
| 658 | right = 0 |
| 659 | if first_row: |
| 660 | top = 0 |
| 661 | if last_row: |
| 662 | bottom = 0 |
| 663 | _padding = (top, right, bottom, left) |
| 664 | _padding_cache[(first_row, last_row)] = _padding |
| 665 | return _padding |
| 666 | |
| 667 | raw_cells: List[Tuple[StyleType, "RenderableType"]] = [] |
| 668 | _append = raw_cells.append |
| 669 | get_style = console.get_style |
| 670 | if self.show_header: |
| 671 | header_style = get_style(self.header_style or "") + get_style( |
| 672 | column.header_style |
| 673 | ) |
| 674 | _append((header_style, column.header)) |
| 675 | cell_style = get_style(column.style or "") |
| 676 | for cell in column.cells: |
| 677 | _append((cell_style, cell)) |
| 678 | if self.show_footer: |
| 679 | footer_style = get_style(self.footer_style or "") + get_style( |
| 680 | column.footer_style |
| 681 | ) |
| 682 | _append((footer_style, column.footer)) |
| 683 | |
| 684 | if any_padding: |
no test coverage detected