fix width being one off

master
Felix Pankratz 1 year ago
parent 098f2a9666
commit bcb7cfc4f3

16
hn.py

@ -46,7 +46,7 @@ class Client:
self.stories_in_a_site = self.lines - 3 self.stories_in_a_site = self.lines - 3
title_string = '[Y] Hacker News' title_string = '[Y] Hacker News'
title_string +=' ' * (self.cols - len(title_string) - 1) + '\n' title_string += ' ' * (self.cols - len(title_string))
self.screen.addstr(title_string, curses.color_pair(1)) self.screen.addstr(title_string, curses.color_pair(1))
@ -55,14 +55,15 @@ class Client:
prefix = '>' if i == self.cursor_pos else '' prefix = '>' if i == self.cursor_pos else ''
# calculate length of line # calculate length of line
text = f'{prefix} ()\n' text = f'{prefix} ()'
chars_available = self.cols - len(text) chars_available = self.cols - len(text)
max_title_len = min((chars_available//4)*3, len(story.title)) max_title_len = min((chars_available//4)*3, len(story.title))
max_url_len = chars_available - max_title_len max_url_len = chars_available - max_title_len
title = story.title[:max_title_len-1] + "" if len(story.title) > max_title_len else story.title title = story.title[:max_title_len-1] + "" if len(story.title) > max_title_len else story.title
link = story.link.replace('https://', '').replace('http://', '') link = story.link.replace('https://', '').replace('http://', '')
link = link[:max_url_len-1] + "" if len(link) > max_url_len else link link = link[:max_url_len - 1] + "" if len(link) > max_url_len else link
self.screen.addstr(prefix) self.screen.addstr(prefix)
if i == self.cursor_pos: if i == self.cursor_pos:
@ -70,7 +71,9 @@ class Client:
self.screen.addstr(title, curses.A_DIM | curses.A_UNDERLINE) self.screen.addstr(title, curses.A_DIM | curses.A_UNDERLINE)
else: else:
self.screen.addstr(title, curses.A_UNDERLINE) self.screen.addstr(title, curses.A_UNDERLINE)
self.screen.addstr(f' ({link})\n', curses.A_DIM ) self.screen.addstr(f' ({link})', curses.A_DIM )
if len(text) + len(title) + len(link) + 1 < self.cols:
self.screen.addstr('\n')
detail = f' by {story.author} | {story.comments} comments | {story.votes} points\n' detail = f' by {story.author} | {story.comments} comments | {story.votes} points\n'
self.screen.addstr(detail) self.screen.addstr(detail)
else: else:
@ -78,7 +81,10 @@ class Client:
self.screen.addstr(title, curses.A_DIM) self.screen.addstr(title, curses.A_DIM)
else: else:
self.screen.addstr(title) self.screen.addstr(title)
self.screen.addstr(f' ({link})\n', curses.A_DIM ) self.screen.addstr(f' ({link})', curses.A_DIM )
if len(text) + len(title) + len(link) + 1 < self.cols:
self.screen.addstr('\n')
page = int(self.story_pos / self.stories_in_a_site + 1) page = int(self.story_pos / self.stories_in_a_site + 1)
total_pages = math.ceil(len(self.loadedstories)/500) total_pages = math.ceil(len(self.loadedstories)/500)

Loading…
Cancel
Save