Formats key-values as a Rich Table: key1 : value1 key2 : value2 ...
( entries: dict[str, str | list[str] | bool], ignore_empty: bool = True, )
| 10 | |
| 11 | |
| 12 | def as_key_value_pair( |
| 13 | entries: dict[str, str | list[str] | bool], |
| 14 | ignore_empty: bool = True, |
| 15 | ) -> str: |
| 16 | """ |
| 17 | Formats key-values as a Rich Table: |
| 18 | key1 : value1 |
| 19 | key2 : value2 |
| 20 | ... |
| 21 | """ |
| 22 | table = BaseRichTable() |
| 23 | table.add_column('key', style='bold', no_wrap=True) |
| 24 | table.add_column('value', style='white', max_width=70) |
| 25 | |
| 26 | for label, value in entries.items(): |
| 27 | if ignore_empty and not value: |
| 28 | continue |
| 29 | |
| 30 | if isinstance(value, bool): |
| 31 | value = 'Yes' if value else 'No' |
| 32 | |
| 33 | if isinstance(value, list): |
| 34 | value = '\n '.join(str(val) for val in value) |
| 35 | |
| 36 | table.add_row(label.title(), f': {value}') |
| 37 | |
| 38 | return table.stringify() |
| 39 | |
| 40 | |
| 41 | def as_columns(entries: list[str], cols: int) -> str: |
no test coverage detected