Skip to content

Commit

Permalink
refactor(pikaprint: sidejoin_multiline_paragraphs): change function s…
Browse files Browse the repository at this point in the history
…ignature to be more clear and extendable
  • Loading branch information
actionless committed Sep 12, 2024
1 parent 2a04ef4 commit db1a530
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 48 deletions.
11 changes: 6 additions & 5 deletions pikaur/info_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,12 @@ def cli_info_packages() -> None: # noqa: PLR0914
)
value_height = len(value_display.splitlines())
line = sidejoin_multiline_paragraphs(
"",
key_display + (
"\n" + " " * (longest_field_length + 2 + 1)
) * (value_height - 1),
value_display,
"", (
key_display + (
"\n" + " " * (longest_field_length + 2 + 1)
) * (value_height - 1),
value_display,
),
)
pkg_info_lines.append(line)
print_stdout(
Expand Down
3 changes: 2 additions & 1 deletion pikaur/pikaprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import shutil
import sys
import termios
from collections.abc import Sequence
from itertools import zip_longest
from typing import TYPE_CHECKING

Expand Down Expand Up @@ -347,7 +348,7 @@ def make_equal_right_padding(multiline_string: str, length: int | None = None) -
)


def sidejoin_multiline_paragraphs(join_separator: str, *multiline_strings: str) -> str:
def sidejoin_multiline_paragraphs(join_separator: str, multiline_strings: Sequence[str]) -> str:
return "\n".join(
join_separator.join(line or "" for line in lines)
for lines in zip_longest(
Expand Down
81 changes: 42 additions & 39 deletions pikaur/pikasay.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,42 +120,42 @@ def bubble_right(
f"{' ' * (bubble_width + margin * 2 + bubble_handle_width)}\n"
* height_compensating_margin
) + sidejoin_multiline_paragraphs(
"",
"\n".join(
[" " * margin] * (bubble_height + vert_margin - 1 + 2),
),
"\n".join((
*([" "] * (vert_margin + 1)),
"/",
*(["|"] * (bubble_height - 2)),
"\\",
)),
"\n".join((
*([" " * (bubble_width - 2)] * vert_margin),
"_" * (bubble_width - 2),
*([" " * (bubble_width - 2)] * (vert_padding + 1)),
formatted_paragraph,
*([" " * (bubble_width - 2)] * (vert_padding)),
"_" * (bubble_width - 2),
*([" " * (bubble_width - 2)] * vert_margin),
)),
"\n".join((
*([" "] * (vert_margin + 1)),
"\\",
*(["|"] * (bubble_handle_position)),
" ",
*(["|"] * (bubble_height - 2 - bubble_handle_position - 1)),
"/",
)),
"\n".join((
*([" "] * (vert_margin + 1)),
*([" "] * (bubble_handle_position)),
bubble_handle,
*([" "] * (bubble_height - 2 - bubble_handle_position)),
)),
"\n".join(
[" " * margin] * (bubble_height + vert_margin - 1 + 2),
),
"", [
"\n".join(lines)
for lines in (
[" " * margin] * (bubble_height + vert_margin - 1 + 2),
(
*([" "] * (vert_margin + 1)),
"/",
*(["|"] * (bubble_height - 2)),
"\\",
),
(
*([" " * (bubble_width - 2)] * vert_margin),
"_" * (bubble_width - 2),
*([" " * (bubble_width - 2)] * (vert_padding + 1)),
formatted_paragraph,
*([" " * (bubble_width - 2)] * (vert_padding)),
"_" * (bubble_width - 2),
*([" " * (bubble_width - 2)] * vert_margin),
),
(
*([" "] * (vert_margin + 1)),
"\\",
*(["|"] * (bubble_handle_position)),
" ",
*(["|"] * (bubble_height - 2 - bubble_handle_position - 1)),
"/",
),
(
*([" "] * (vert_margin + 1)),
*([" "] * (bubble_handle_position)),
bubble_handle,
*([" "] * (bubble_height - 2 - bubble_handle_position)),
),
[" " * margin] * (bubble_height + vert_margin - 1 + 2),
)
],
)


Expand All @@ -169,9 +169,12 @@ def pikasay( # noqa: PLR0917
))
elif orientation == "vertical":
message = sidejoin_multiline_paragraphs(
"",
bubble_right(text=text, margin=margin, padding=padding, width=width, mascot=mascot_pic),
mascot_pic,
"", (
bubble_right(
text=text, margin=margin, padding=padding, width=width, mascot=mascot_pic,
),
mascot_pic,
),
)
else:
raise ValueError(orientation)
Expand Down
7 changes: 4 additions & 3 deletions pikaur/print_department.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ def print_version(pacman_version: str, pyalpm_version: str, *, quiet: bool = Fal
year = str(datetime.now(tz=DEFAULT_TIMEZONE).year)
sys.stdout.write(
sidejoin_multiline_paragraphs(
" ",
make_equal_right_padding(PIKAPIC),
r"""
" ", (
make_equal_right_padding(PIKAPIC),
r"""
Expand All @@ -75,6 +75,7 @@ def print_version(pacman_version: str, pyalpm_version: str, *, quiet: bool = Fal
""" + pacman_version + r"""
pyalpm v""" + pyalpm_version + r"""
""",
),
) + "\n",
)

Expand Down

0 comments on commit db1a530

Please sign in to comment.