Merge pull request 'Category Details screen now fits terminal width, with aligned columns' (#93) from semioticformatic into release

Reviewed-on: #93
This commit is contained in:
cmccabe 2020-07-03 06:19:00 -04:00
commit 90166b470a
1 changed files with 22 additions and 5 deletions

View File

@ -4,7 +4,7 @@
## If this script contains bugs, blame cmccabe.
import getpass
import readline # pylint: disable=unused-import
import readline # pylint: disable=unused-import
import signal
import subprocess
import sys
@ -47,8 +47,24 @@ def print_categories():
def print_category_details(view_cat):
"""produces category detail data, prints it to the console. returns dict
containing an index of threads"""
header = "\n{}\n\n{:>4s} {:<15s}{:<12s} #RESP {:<13s}".format(
style_text(view_cat["name"].upper(), "bold"), "ID#", "DATE", "AUTHOR", "DESC"
columns, _ = get_terminal_size()
maxnamelen = len(max(link_data, key=lambda x: len(x[1]))[1])
namelen = max(maxnamelen, 6) # minimum field width is 6
desclen = (
columns - 18 - namelen - 9 - 1
) # length of available space for the description field.
# The terminal width, minus the width of ID and Date fields and padding,
# minus the max name length, minus Resp field and padding width, minus the
# unread mark width
header = "\n{}\n\n {:>3s} {:>10s} {:<{namelen}s} {:<5} {:<s}".format(
style_text(view_cat["name"].upper(), "bold"),
"ID#",
"DATE",
"AUTHOR",
"#RESP",
"DESC",
namelen=namelen,
)
out = ""
link_count = 0
@ -63,10 +79,11 @@ def print_category_details(view_cat):
new_replies = len(
[line for line in replies if line[2] >= config.USER.lastlogin]
)
desc = textwrap.shorten(line[6], width=desclen, placeholder="...")
newmarker = "*" if new_replies or line[2] >= config.USER.lastlogin else ""
_dt = datetime.fromtimestamp(float(line[2])).strftime("%Y-%m-%d")
out += "{:4d} {:<15s}{:<12s} [{:3d}] {:s}{}\n".format(
link_count, _dt, line[1], len(replies), line[6], newmarker
out += " {:3d} {:>10s} {:<{namelen}s} [{:3d}] {:s}{}\n".format(
link_count, _dt, line[1], len(replies), desc, newmarker, namelen=namelen
)
if len(out) > 0: