Skip to content

Commit

Permalink
feat(info_cli): make -Si output closer to pacman's
Browse files Browse the repository at this point in the history
  • Loading branch information
actionless committed Sep 12, 2024
1 parent 7213af8 commit 2a04ef4
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions pikaur/info_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@
from .i18n import translate
from .pacman import get_pacman_command, refresh_pkg_db_if_needed
from .pacman_i18n import _p
from .pikaprint import ColorsHighlight, bold_line, color_line, print_stdout
from .pikaprint import (
ColorsHighlight,
bold_line,
color_line,
format_paragraph,
get_term_width,
print_stdout,
printable_length,
sidejoin_multiline_paragraphs,
)
from .spawn import spawn


Expand Down Expand Up @@ -64,7 +73,7 @@ def _decorate_aur_info_output(output: str) -> str:
)


def cli_info_packages() -> None:
def cli_info_packages() -> None: # noqa: PLR0914
refresh_pkg_db_if_needed()

args = parse_args()
Expand All @@ -83,6 +92,7 @@ def cli_info_packages() -> None:
aur_pkgs = aur_result[0]
num_found = len(aur_pkgs)
info_fields = get_info_fields()
term_width = get_term_width()
longest_field_length = max(len(field) for field in info_fields.values())
for i, aur_pkg in enumerate(aur_pkgs):
pkg_info_lines = []
Expand All @@ -91,9 +101,24 @@ def cli_info_packages() -> None:
if key in {"firstsubmitted", "lastmodified", "outofdate"} and value:
value = datetime.fromtimestamp(value, tz=DEFAULT_TIMEZONE).strftime("%c")
elif isinstance(value, list):
value = ", ".join(value) or translate("None")
key_display = bold_line(_rightpad(display_name, longest_field_length + 1))
pkg_info_lines.append(f"{key_display}: {value}")
value = " ".join(value) or translate("None")
key_display = bold_line(_rightpad(display_name, longest_field_length + 1) + ": ")
if not isinstance(value, str):
value = str(value)
line = f"{key_display}{value}"
if printable_length(line) > term_width:
value_display = format_paragraph(
value, width=term_width - longest_field_length - 2 - 1, padding=0,
)
value_height = len(value_display.splitlines())
line = sidejoin_multiline_paragraphs(
"",
key_display + (
"\n" + " " * (longest_field_length + 2 + 1)
) * (value_height - 1),
value_display,
)
pkg_info_lines.append(line)
print_stdout(
_decorate_aur_info_output("\n".join(pkg_info_lines)) +
("\n" if i + 1 < num_found else ""),
Expand Down

0 comments on commit 2a04ef4

Please sign in to comment.