commit 03b5c338aaab84d7f95a448e08b9f540d739e819
parent 77d8568fb8faf4fd8d0d7edb50268df0ffda59d5
Author: Samuel Walladge <samuel@swalladge.id.au>
Date: Wed, 3 Jan 2018 12:25:36 +1030
fix crash on create note when no notes in db
Was crashing because `self.gui_body_get().focus_position` fails when the
underlying urwid listbox is empty (IndexError). This provides a fallback
position if it fails.
fixes #58
Diffstat:
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/simplenote_cli/sncli.py b/simplenote_cli/sncli.py
@@ -94,9 +94,17 @@ def exec_cmd_on_note(self, note, cmd=None, raw=False):
tf = temp.tempfile_create(note if note else None, raw=raw, tempdir=self.tempdir)
fname = temp.tempfile_name(tf)
+ focus_position = 0
+ try:
+ focus_position = self.gui_body_get().focus_position
+ except IndexError:
+ # focus position will fail if no notes available (listbox empty)
+ # TODO: find a neater way to check than try/except
+ pass
+
subs = {
'fname': fname,
- 'line': self.gui_body_get().focus_position + 1,
+ 'line': focus_position + 1,
}
cmd_list = [c.format(**subs) for c in shlex.split(cmd)]