better looking summary

This commit is contained in:
meisnate12 2021-12-30 18:05:31 -05:00
parent ee2039039c
commit f2ddb6fd46
2 changed files with 11 additions and 7 deletions

View file

@ -183,19 +183,19 @@ def regex_first_int(data, id_type, default=None):
else: else:
raise Failed(f"Regex Error: Failed to parse {id_type} from {data}") raise Failed(f"Regex Error: Failed to parse {id_type} from {data}")
def centered(text, sep=" "): def centered(text, sep=" ", side_space=True, left=False):
if len(text) > screen_width - 2: if len(text) > screen_width - 2:
return text return text
space = screen_width - len(text) - 2 space = screen_width - len(text) - 2
text = f" {text} " text = f"{' ' if side_space else sep}{text}{' ' if side_space else sep}"
if space % 2 == 1: if space % 2 == 1:
text += sep text += sep
space -= 1 space -= 1
side = int(space / 2) - 1 side = int(space / 2) - 1
final_text = f"{sep * side}{text}{sep * side}" final_text = f"{text}{sep * side}{sep * side}" if left else f"{sep * side}{text}{sep * side}"
return final_text return final_text
def separator(text=None, space=True, border=True, debug=False): def separator(text=None, space=True, border=True, debug=False, side_space=True, left=False):
sep = " " if space else separating_character sep = " " if space else separating_character
for handler in logger.handlers: for handler in logger.handlers:
apply_formatter(handler, border=False) apply_formatter(handler, border=False)
@ -208,9 +208,9 @@ def separator(text=None, space=True, border=True, debug=False):
text_list = text.split("\n") text_list = text.split("\n")
for t in text_list: for t in text_list:
if debug: if debug:
logger.debug(f"|{sep}{centered(t, sep=sep)}{sep}|") logger.debug(f"|{sep}{centered(t, sep=sep, side_space=side_space, left=left)}{sep}|")
else: else:
logger.info(f"|{sep}{centered(t, sep=sep)}{sep}|") logger.info(f"|{sep}{centered(t, sep=sep, side_space=side_space, left=left)}{sep}|")
if border and debug: if border and debug:
logger.debug(border_text) logger.debug(border_text)
elif border: elif border:

View file

@ -354,12 +354,16 @@ def update_libraries(config):
for title in playlist_status: for title in playlist_status:
if len(title) > longest: if len(title) > longest:
longest = len(title) longest = len(title)
def print_status(section, status): def print_status(section, status):
logger.info("") logger.info("")
util.separator(f"{section} Summary", space=False, border=False) util.separator(f"{section} Summary", space=False, border=False)
logger.info("") logger.info("")
logger.info(f"{'Title':^{longest}} | + | = | - | {'Status':^13}")
breaker = f"{util.separating_character * longest}|{util.separating_character * 5}|{util.separating_character * 5}|{util.separating_character * 5}|"
util.separator(breaker, space=False, border=False, side_space=False, left=True)
for name, data in status.items(): for name, data in status.items():
logger.info(f"{name:<{longest}} | {data['status']:<13} | +{data['added']} ={data['unchanged']} -{data['removed']}") logger.info(f"{name:<{longest}} | {data['added']:^3} | {data['unchanged']:^3} | {data['removed']:^3} | {data['status']}")
if data["errors"]: if data["errors"]:
for error in data["errors"]: for error in data["errors"]:
util.print_multiline(error, info=True) util.print_multiline(error, info=True)