From 996228d224262488c0c2008589c72313c38e1eea Mon Sep 17 00:00:00 2001 From: Ivan Habunek Date: Thu, 14 Feb 2019 15:47:40 +0100 Subject: [PATCH] Employ wcstring utils to improve rendering --- toot/output.py | 4 +++- toot/ui/app.py | 18 ++++++------------ toot/ui/utils.py | 6 +++--- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/toot/output.py b/toot/output.py index bfdd7e2..1729edf 100644 --- a/toot/output.py +++ b/toot/output.py @@ -9,7 +9,9 @@ from itertools import chain from itertools import zip_longest from textwrap import wrap, TextWrapper -from toot.utils import format_content, get_text, pad +from toot.utils import format_content, get_text +from toot.wcstring import pad + START_CODES = { 'red': '\033[31m', diff --git a/toot/ui/app.py b/toot/ui/app.py index f4b3db2..a23e29b 100644 --- a/toot/ui/app.py +++ b/toot/ui/app.py @@ -7,13 +7,13 @@ from toot import __version__ from toot.exceptions import ConsoleError from toot.ui.parsers import parse_status from toot.ui.utils import draw_horizontal_divider, draw_lines -from toot.utils import trunc +from toot.wcstring import fit_text # Attempt to load curses, which is not available on windows try: import curses import curses.panel -except ImportError as e: +except ImportError: raise ConsoleError("Curses is not available on this platform") @@ -64,12 +64,12 @@ class FooterWindow: def draw_status(self, selected, count): text = "Showing toot {} of {}".format(selected + 1, count) - text = trunc(text, self.width - 1).ljust(self.width - 1) + text = fit_text(text, self.width) self.window.addstr(0, 0, text, Color.WHITE_ON_BLUE | curses.A_BOLD) self.window.refresh() def draw_message(self, text, color): - text = trunc(text, self.width - 1).ljust(self.width - 1) + text = fit_text(text, self.width - 1) self.window.addstr(1, 0, text, color) self.window.refresh() @@ -121,8 +121,8 @@ class StatusListWindow: color = Color.GREEN if highlight else Color.WHITE trunc_width = width - 15 - acct = trunc("@" + status['account']['acct'], trunc_width).ljust(trunc_width) - display_name = trunc(status['account']['display_name'], trunc_width).ljust(trunc_width) + acct = fit_text("@" + status['account']['acct'], trunc_width) + display_name = fit_text(status['account']['display_name'], trunc_width) if status['account']['display_name']: self.pad.addstr(offset + 1, 14, display_name, color) @@ -134,12 +134,6 @@ class StatusListWindow: self.pad.addstr(offset + 1, 1, " " + date.ljust(12), color) self.pad.addstr(offset + 2, 1, " " + time.ljust(12), color) - # Redraw box borders to mitigate unicode overflow issues - self.pad.addch(offset + 1, 0, "│") - self.pad.addch(offset + 2, 0, "│") - self.pad.addch(offset + 1, width - 1, "│") - self.pad.addch(offset + 2, width - 1, "│") - if draw_divider: draw_horizontal_divider(self.pad, offset + 3) diff --git a/toot/ui/utils.py b/toot/ui/utils.py index 5600388..262a9ef 100644 --- a/toot/ui/utils.py +++ b/toot/ui/utils.py @@ -1,6 +1,6 @@ import re -from textwrap import wrap +from toot.wcstring import fit_text, wc_wrap def draw_horizontal_divider(window, y): @@ -27,7 +27,7 @@ def enumerate_lines(lines, text_width, default_color): for line in lines: line, color = parse_line(line) if line: - for wrapped in wrap(line, text_width): + for wrapped in wc_wrap(line, text_width): yield wrapped, color else: yield "", color @@ -53,7 +53,7 @@ def draw_lines(window, lines, start_y, padding, default_color): for dy, (line, color) in enumerate_lines(lines, text_width, default_color): y = start_y + dy if y < height - 1: - window.addstr(y, padding, line.ljust(text_width), color) + window.addstr(y, padding, fit_text(line, text_width), color) highlight_hashtags(window, y, padding, line) return y + 1