|
4 | 4 |
|
5 | 5 | import typing |
6 | 6 | from dataclasses import fields |
7 | | -from itertools import zip_longest |
8 | | -from math import ceil |
9 | | -from shutil import get_terminal_size |
10 | | -from textwrap import TextWrapper, indent |
| 7 | +from textwrap import indent |
11 | 8 |
|
12 | 9 | from rich import box |
13 | 10 | from rich.columns import Columns |
|
20 | 17 | from .stagyydata import _sdat_from_conf |
21 | 18 |
|
22 | 19 | if typing.TYPE_CHECKING: |
23 | | - from typing import Callable, Iterable, Mapping, Sequence |
| 20 | + from typing import Callable, Iterable, Mapping |
24 | 21 |
|
25 | 22 | from loam.base import Section |
26 | 23 |
|
@@ -57,53 +54,6 @@ def info_cmd(conf: Config) -> None: |
57 | 54 | print() |
58 | 55 |
|
59 | 56 |
|
60 | | -def _pretty_print( |
61 | | - key_val: Sequence[tuple[str, str]], |
62 | | - sep: str = ": ", |
63 | | - min_col_width: int = 39, |
64 | | - text_width: int | None = None, |
65 | | -) -> None: |
66 | | - """Print a iterable of key/values. |
67 | | -
|
68 | | - Args: |
69 | | - key_val: the pairs of section names and text. |
70 | | - sep: separator between section names and text. |
71 | | - min_col_width: minimal acceptable column width |
72 | | - text_width: text width to use. If set to None, will try to infer the |
73 | | - size of the terminal. |
74 | | - """ |
75 | | - if text_width is None: |
76 | | - text_width = get_terminal_size().columns |
77 | | - if text_width < min_col_width: |
78 | | - min_col_width = text_width |
79 | | - ncols = (text_width + 1) // (min_col_width + 1) |
80 | | - colw = (text_width + 1) // ncols - 1 |
81 | | - ncols = min(ncols, len(key_val)) |
82 | | - |
83 | | - wrapper = TextWrapper(width=colw) |
84 | | - lines = [] |
85 | | - for key, val in key_val: |
86 | | - if len(key) + len(sep) >= colw // 2: |
87 | | - wrapper.subsequent_indent = " " |
88 | | - else: |
89 | | - wrapper.subsequent_indent = " " * (len(key) + len(sep)) |
90 | | - lines.extend(wrapper.wrap(f"{key}{sep}{val}")) |
91 | | - |
92 | | - chunks = [] |
93 | | - for rem_col in range(ncols, 1, -1): |
94 | | - isep = ceil(len(lines) / rem_col) |
95 | | - while isep < len(lines) and lines[isep][0] == " ": |
96 | | - isep += 1 |
97 | | - chunks.append(lines[:isep]) |
98 | | - lines = lines[isep:] |
99 | | - chunks.append(lines) |
100 | | - full_lines = zip_longest(*chunks, fillvalue="") |
101 | | - |
102 | | - fmt = "|".join([f"{{:{colw}}}"] * (ncols - 1)) |
103 | | - fmt += "|{}" if ncols > 1 else "{}" |
104 | | - print(*(fmt.format(*line) for line in full_lines), sep="\n") |
105 | | - |
106 | | - |
107 | 57 | def _layout( |
108 | 58 | dict_vars: Mapping[str, Varf | Varr | Vart], |
109 | 59 | dict_vars_extra: Mapping[str, Callable], |
|
0 commit comments