diff --git a/linkulator.py b/linkulator.py index 8f3a5a4..ce64cee 100755 --- a/linkulator.py +++ b/linkulator.py @@ -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} {:= 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: