From bcb7cfc4f3d595fec60aa6a83aa7e4acff434e46 Mon Sep 17 00:00:00 2001 From: Felix Pankratz Date: Thu, 31 Aug 2023 23:13:27 +0200 Subject: [PATCH] fix width being one off --- hn.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/hn.py b/hn.py index a2ab73f..0fdfd16 100755 --- a/hn.py +++ b/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,14 +55,15 @@ 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 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 = 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) if i == self.cursor_pos: @@ -70,7 +71,9 @@ class Client: 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)