nncli

NextCloud Notes Command Line Interface
git clone git://git.danielmoch.com/nncli.git
Log | Files | Refs | LICENSE

commit 399379685c5c70e44b6604188956e05e2bc93f80
parent cdd936c474693ac83cac8c1754e50e18fa727f5e
Author: Eric Davis <edavis@insanum.com>
Date:   Tue,  8 Jul 2014 23:40:57 -0700

limit the number of logs shown in the footer
update the log view went entering the view

Diffstat:
Msncli.py | 23+++++++++++++----------
Mview_log.py | 7+++++--
2 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/sncli.py b/sncli.py @@ -31,6 +31,9 @@ def __init__(self): logging.debug('sncli logging initialized') + self.max_logs = 5 + self.logs = [] + try: self.ndb = NotesDB(self.config, self.log) except Exception, e: @@ -107,6 +110,7 @@ def log_timeout(self, loop, arg): self.log_alarms -= 1 if self.log_alarms == 0: self.gui_footer_clear() + self.logs = [] self.log_lock.release() @@ -119,18 +123,16 @@ def log(self, msg): self.log_lock.acquire() - # if there is already a message showing then concatenate them - existing_msg = '' - if self.log_alarms and \ - 'footer' in self.master_frame.contents.keys(): - existing_msg = \ - self.master_frame.contents['footer'][0].base_widget.text + u'\n' + self.logs.append(msg) + if len(self.logs) > self.max_logs: + self.logs.pop(0) - # if we don't do this clear first there can be corruption in the body - self.gui_footer_clear() + p = urwid.Pile([]) + log_pile = [] + for l in self.logs: + log_pile.append(urwid.Text(l)) - self.gui_footer_set(urwid.AttrMap(urwid.Text(existing_msg + msg), - 'log')) + self.gui_footer_set(urwid.AttrMap(urwid.Pile(log_pile), 'log')) self.sncli_loop.set_alarm_in(5, self.log_timeout, None) self.log_alarms += 1 @@ -215,6 +217,7 @@ def gui_frame_keypress(self, size, key): self.ndb.last_sync = 0 elif key == self.config.get_keybind('view_log'): + self.view_log.update_log() self.gui_switch_frame_body(self.view_log) elif key == self.config.get_keybind('down'): diff --git a/view_log.py b/view_log.py @@ -5,8 +5,11 @@ class ViewLog(urwid.ListBox): def __init__(self, config): self.config = config - f = open(self.config.logfile) + super(ViewLog, self).__init__(urwid.SimpleFocusListWalker([])) + + def update_log(self): lines = [] + f = open(self.config.logfile) for line in f: lines.append( urwid.AttrMap(urwid.Text(line.rstrip()), @@ -15,7 +18,7 @@ def __init__(self, config): f.close() if self.config.get_config('log_reversed') == 'yes': lines.reverse() - super(ViewLog, self).__init__(urwid.SimpleFocusListWalker(lines)) + self.body[:] = urwid.SimpleFocusListWalker(lines) def get_status_bar(self): cur = -1