Employ wcstring utils to improve rendering
This commit is contained in:
parent
8a3ff94e47
commit
996228d224
3 changed files with 12 additions and 16 deletions
|
@ -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',
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue