Formats elements for better readability. Once it becomes wider than the display width it will create a newline and continue indented to col_width. Once there are more rows than the maximum displayed rows it will start removing rows. Parameters ---------- elements :
(
elements: Collection[Hashable],
col_width: int,
max_rows: int | None = None,
delimiter: str = ", ",
)
| 573 | |
| 574 | |
| 575 | def _element_formatter( |
| 576 | elements: Collection[Hashable], |
| 577 | col_width: int, |
| 578 | max_rows: int | None = None, |
| 579 | delimiter: str = ", ", |
| 580 | ) -> str: |
| 581 | """ |
| 582 | Formats elements for better readability. |
| 583 | |
| 584 | Once it becomes wider than the display width it will create a newline and |
| 585 | continue indented to col_width. |
| 586 | Once there are more rows than the maximum displayed rows it will start |
| 587 | removing rows. |
| 588 | |
| 589 | Parameters |
| 590 | ---------- |
| 591 | elements : Collection of hashable |
| 592 | Elements to join together. |
| 593 | col_width : int |
| 594 | The width to indent to if a newline has been made. |
| 595 | max_rows : int, optional |
| 596 | The maximum number of allowed rows. The default is None. |
| 597 | delimiter : str, optional |
| 598 | Delimiter to use between each element. The default is ", ". |
| 599 | """ |
| 600 | elements_len = len(elements) |
| 601 | out = [""] |
| 602 | length_row = 0 |
| 603 | for i, v in enumerate(elements): |
| 604 | delim = delimiter if i < elements_len - 1 else "" |
| 605 | v_delim = f"{v}{delim}" |
| 606 | length_element = len(v_delim) |
| 607 | length_row += length_element |
| 608 | |
| 609 | # Create a new row if the next elements makes the print wider than |
| 610 | # the maximum display width: |
| 611 | if col_width + length_row > OPTIONS["display_width"]: |
| 612 | out[-1] = out[-1].rstrip() # Remove trailing whitespace. |
| 613 | out.append("\n" + pretty_print("", col_width) + v_delim) |
| 614 | length_row = length_element |
| 615 | else: |
| 616 | out[-1] += v_delim |
| 617 | |
| 618 | # If there are too many rows of dimensions trim some away: |
| 619 | if max_rows and (len(out) > max_rows): |
| 620 | first_rows = calc_max_rows_first(max_rows) |
| 621 | last_rows = calc_max_rows_last(max_rows) |
| 622 | out = ( |
| 623 | out[:first_rows] |
| 624 | + ["\n" + pretty_print("", col_width) + "..."] |
| 625 | + (out[-last_rows:] if max_rows > 1 else []) |
| 626 | ) |
| 627 | return "".join(out) |
| 628 | |
| 629 | |
| 630 | def dim_summary_limited( |
no test coverage detected
searching dependent graphs…