subclient

Subsonic ncurses client
git clone https://git.e1e0.net/subclient.git
Log | Files | Refs | README

commit 0221b01a01de62e2600e965320fb3554d5ea3e8d
parent 7020a60bfedc3fb426314840abd33f6e65e2542e
Author: Paco Esteban <paco@e1e0.net>
Date:   Sun, 27 Jun 2021 18:03:08 +0200

we can even pge now

Diffstat:
Msubclient/subclient.py | 28+++++++++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/subclient/subclient.py b/subclient/subclient.py @@ -39,7 +39,7 @@ class SubClient: self.nav_top = 0 self.nav_bottom = len(self.nav_list) self.nav_max_lines = curses.LINES - self.nav_page = self.nav_bottom // self.nav_max_lines + self.nav_pages = self.nav_bottom // self.nav_max_lines def init_curses(self): self.window = curses.initscr() @@ -73,6 +73,10 @@ class SubClient: self.nav_scroll(self.DOWN) elif c == 'k': self.nav_scroll(self.UP) + elif c == 'f': + self.nav_page(self.DOWN) + elif c == 'b': + self.nav_page(self.UP) elif c in [curses.KEY_ENTER, '\r', '\n']: with open('foo.txt', 'w') as f: print(f"top: {self.nav_top}", file=f) @@ -125,6 +129,28 @@ class SubClient: self.nav_selected = next_line return + def nav_page(self, direction): + current_page = (self.nav_top + self.nav_selected) // self.nav_max_lines + # Page up + # we test current page >= 0 instead of just > 0 because we can be in + # a situation when the calculated current page is already 0 and compare + # > 0 would prevent going up that last bit. So we actuall allow to go + # negative and correct afterwards. + if (direction == self.UP) and (current_page >= 0): + self.nav_top -= self.nav_max_lines + # top cannot be negative + if self.nav_top < 0: + self.nav_top = 0 + return + # Page down + # if current page is not last page we increment top by a full page + if (direction == self.DOWN) and (current_page < self.nav_pages): + self.nav_top += self.nav_max_lines + # the last page is probably shorter, so adjust for that + if (self.nav_top + self.nav_max_lines) > self.nav_bottom: + self.nav_top = self.nav_bottom - self.nav_max_lines + return + def refresh(self): self.window.noutrefresh() curses.doupdate()