Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display balances in Accounts view #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions regdel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand Down