Skip to content

Commit b0cb380

Browse files
committed
rm unused commands._pretty_print
1 parent 19d50ce commit b0cb380

File tree

1 file changed

+2
-52
lines changed

1 file changed

+2
-52
lines changed

src/stagpy/commands.py

Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44

55
import typing
66
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
118

129
from rich import box
1310
from rich.columns import Columns
@@ -20,7 +17,7 @@
2017
from .stagyydata import _sdat_from_conf
2118

2219
if typing.TYPE_CHECKING:
23-
from typing import Callable, Iterable, Mapping, Sequence
20+
from typing import Callable, Iterable, Mapping
2421

2522
from loam.base import Section
2623

@@ -57,53 +54,6 @@ def info_cmd(conf: Config) -> None:
5754
print()
5855

5956

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-
10757
def _layout(
10858
dict_vars: Mapping[str, Varf | Varr | Vart],
10959
dict_vars_extra: Mapping[str, Callable],

0 commit comments

Comments
 (0)