Dynamically size the status list window
This makes toot more usable on narrow screens. Still requires 60 columns minimum. fixes #26
This commit is contained in:
parent
b92049ff1d
commit
0ef5a9e41e
2 changed files with 20 additions and 6 deletions
18
toot/app.py
18
toot/app.py
|
@ -5,7 +5,7 @@ import webbrowser
|
||||||
from textwrap import wrap
|
from textwrap import wrap
|
||||||
|
|
||||||
from toot.exceptions import ConsoleError
|
from toot.exceptions import ConsoleError
|
||||||
from toot.utils import format_content
|
from toot.utils import format_content, trunc
|
||||||
|
|
||||||
# Attempt to load curses, which is not available on windows
|
# Attempt to load curses, which is not available on windows
|
||||||
try:
|
try:
|
||||||
|
@ -60,7 +60,10 @@ class TimelineApp:
|
||||||
def setup_windows(self):
|
def setup_windows(self):
|
||||||
screen_height, screen_width = self.stdscr.getmaxyx()
|
screen_height, screen_width = self.stdscr.getmaxyx()
|
||||||
|
|
||||||
self.left_width = 60
|
if screen_width < 60:
|
||||||
|
raise ConsoleError("Terminal screen is too narrow, toot curses requires at least 60 columns to display properly.")
|
||||||
|
|
||||||
|
self.left_width = max(min(screen_width // 3, 60), 30)
|
||||||
self.right_width = screen_width - self.left_width
|
self.right_width = screen_width - self.left_width
|
||||||
|
|
||||||
self.top = curses.newwin(2, screen_width, 0, 0)
|
self.top = curses.newwin(2, screen_width, 0, 0)
|
||||||
|
@ -150,7 +153,7 @@ class TimelineApp:
|
||||||
self.draw_usage(self.bottom)
|
self.draw_usage(self.bottom)
|
||||||
|
|
||||||
screen_height, screen_width = self.stdscr.getmaxyx()
|
screen_height, screen_width = self.stdscr.getmaxyx()
|
||||||
self.left.refresh(0, 0, 2, 0, screen_height - 4, self.left_width)
|
self.left.refresh(0, 0, 2, 0, screen_height - 3, self.left_width)
|
||||||
|
|
||||||
self.right.refresh()
|
self.right.refresh()
|
||||||
self.top.refresh()
|
self.top.refresh()
|
||||||
|
@ -175,16 +178,19 @@ class TimelineApp:
|
||||||
return self.statuses[self.selected]
|
return self.statuses[self.selected]
|
||||||
|
|
||||||
def draw_status_row(self, window, status, offset, highlight=False):
|
def draw_status_row(self, window, status, offset, highlight=False):
|
||||||
width = window.getmaxyx()[1]
|
height, width = window.getmaxyx()
|
||||||
color = Color.blue() if highlight else 0
|
color = Color.blue() if highlight else 0
|
||||||
|
|
||||||
date, time = status['created_at']
|
date, time = status['created_at']
|
||||||
window.addstr(offset + 2, 2, date, color)
|
window.addstr(offset + 2, 2, date, color)
|
||||||
window.addstr(offset + 3, 2, time, color)
|
window.addstr(offset + 3, 2, time, color)
|
||||||
|
|
||||||
window.addstr(offset + 2, 15, status['account']['acct'], color)
|
trunc_width = width - 16
|
||||||
window.addstr(offset + 3, 15, status['account']['display_name'], color)
|
acct = trunc(status['account']['acct'], trunc_width)
|
||||||
|
display_name = trunc(status['account']['display_name'], trunc_width)
|
||||||
|
|
||||||
|
window.addstr(offset + 2, 14, acct, color)
|
||||||
|
window.addstr(offset + 3, 14, display_name, color)
|
||||||
window.addstr(offset + 4, 1, '─' * (width - 2))
|
window.addstr(offset + 4, 1, '─' * (width - 2))
|
||||||
|
|
||||||
screen_height, screen_width = self.stdscr.getmaxyx()
|
screen_height, screen_width = self.stdscr.getmaxyx()
|
||||||
|
|
|
@ -57,3 +57,11 @@ def domain_exists(name):
|
||||||
def assert_domain_exists(domain):
|
def assert_domain_exists(domain):
|
||||||
if not domain_exists(domain):
|
if not domain_exists(domain):
|
||||||
raise ConsoleError("Domain {} not found".format(domain))
|
raise ConsoleError("Domain {} not found".format(domain))
|
||||||
|
|
||||||
|
|
||||||
|
def trunc(text, length):
|
||||||
|
"""Trims text to given length, if trimmed appends ellipsis."""
|
||||||
|
if len(text) <= length:
|
||||||
|
return text
|
||||||
|
|
||||||
|
return text[:length - 1] + '…'
|
||||||
|
|
Loading…
Reference in a new issue