fix width being one off

master
Felix Pankratz 1 year ago
parent 098f2a9666
commit bcb7cfc4f3

14
hn.py

@ -46,7 +46,7 @@ class Client:
self.stories_in_a_site = self.lines - 3
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))
@ -55,7 +55,7 @@ class Client:
prefix = '>' if i == self.cursor_pos else ''
# calculate length of line
text = f'{prefix} ()\n'
text = f'{prefix} ()'
chars_available = self.cols - len(text)
max_title_len = min((chars_available//4)*3, len(story.title))
max_url_len = chars_available - max_title_len
@ -64,13 +64,16 @@ class Client:
link = story.link.replace('https://', '').replace('http://', '')
link = link[:max_url_len - 1] + "" if len(link) > max_url_len else link
self.screen.addstr(prefix)
if i == self.cursor_pos:
if story.read:
self.screen.addstr(title, curses.A_DIM | curses.A_UNDERLINE)
else:
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'
self.screen.addstr(detail)
else:
@ -78,7 +81,10 @@ class Client:
self.screen.addstr(title, curses.A_DIM)
else:
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)
total_pages = math.ceil(len(self.loadedstories)/500)

Loading…
Cancel
Save