From 2f6ced69fc2aeed0240de2826c201c5dd40da578 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Hoelt Date: Mon, 7 Nov 2016 12:52:10 +0200 Subject: [PATCH 1/2] Display balances in Accounts view --- regdel | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/regdel b/regdel index bde8735..c2ad710 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,7 +166,11 @@ class View(object): class AccountsView(View): def __init__(self, app, win): super(AccountsView, self).__init__(app, win) - lines = ledger(app.path, 'accounts') + self.update() + + def update(self): + lines = ledger(self.app.path, 'balance', + options=[ '--flat', '--no-total' ]) accounts = [] for line in lines: for i in range(len(line.split(':'))): @@ -180,7 +188,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 +320,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 From a9a1f7b8d0d3fcbdbddbc3ed140457864d65ee3f Mon Sep 17 00:00:00 2001 From: Jean-Christophe Hoelt Date: Mon, 7 Nov 2016 20:20:44 +0200 Subject: [PATCH 2/2] Fix display of accounts as balance --- regdel | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/regdel b/regdel index c2ad710..5a1b032 100755 --- a/regdel +++ b/regdel @@ -169,14 +169,8 @@ class AccountsView(View): self.update() def update(self): - lines = ledger(self.app.path, 'balance', + self.lines = ledger(self.app.path, 'balance', options=[ '--flat', '--no-total' ]) - 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 def render(self, win, i): if i >= len(self.lines): return