diff --git a/regdel b/regdel index bde8735..5a1b032 100755 --- a/regdel +++ b/regdel @@ -45,10 +45,14 @@ KEY_MAP = { curses.KEY_UP: "PREV_LINE", curses.KEY_DOWN: "NEXT_LINE", ord('q'): "QUIT", + curses.KEY_EXIT: "QUIT", + curses.KEY_F10: "QUIT", ord('x'): "COMMODITY", ord('\n'): "SELECT", ord('b'): "BALANCE", ord(' '): "NEXT_PAGE", + curses.KEY_NPAGE: "NEXT_PAGE", + curses.KEY_PPAGE: "PREV_PAGE", ord('g'): "FIRST_LINE", curses.KEY_HOME: "FIRST_LINE", ord('G'): "LAST_LINE", @@ -162,13 +166,11 @@ class View(object): class AccountsView(View): def __init__(self, app, win): super(AccountsView, self).__init__(app, win) - lines = ledger(app.path, 'accounts') - accounts = [] - for line in lines: - for i in range(len(line.split(':'))): - a = ':'.join(line.split(':')[:i+1]) - if a not in accounts: accounts.append(a) - self.lines = accounts + self.update() + + def update(self): + self.lines = ledger(self.app.path, 'balance', + options=[ '--flat', '--no-total' ]) def render(self, win, i): if i >= len(self.lines): return @@ -180,7 +182,14 @@ class AccountsView(View): win.addstr("Accounts") def select(self, i): - return RegView(self.app, self.full, self.lines[i]) + if len(self.lines) <= i: + return None + tokens = self.lines[i].split(" ") + tokens = [token for token in tokens if len(token) > 0] + if len(tokens) <= 1: + return None + txt = tokens[len(tokens) - 1] + return RegView(self.app, self.full, txt) class RegView(View): def __init__(self, app, win, account): @@ -305,6 +314,11 @@ class App: if req == "NEXT_PAGE": step = self.view.win.getmaxyx()[0] self.view.offset += self.view.win.getmaxyx()[0] + if req == "PREV_PAGE": + step = -self.view.win.getmaxyx()[0] + self.view.offset -= self.view.win.getmaxyx()[0] + if self.view.offset < 0: + self.view.offset = 0 if req == "FIRST_LINE": self.view.lineno = 0 self.view.offset = 0