nncli

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

commit 3c3428f1117d6c2275b08d1403f1f2265ee82435
parent ae5719a599416d6527882b804135322af656c0c3
Author: Eric Davis <edavis@insanum.com>
Date:   Mon, 30 Jun 2014 19:21:29 -0700

added hooks and keybinds for pinning/unpinning notes

Diffstat:
Mconfig.py | 6+++++-
Mnotes_db.py | 5++++-
Msncli.py | 43+++++++++++++++++++++++++++----------------
3 files changed, 36 insertions(+), 18 deletions(-)

diff --git a/config.py b/config.py @@ -39,6 +39,8 @@ def __init__(self): 'kb_tabstop8' : '8', 'kb_search' : '/', 'kb_clear_search' : 'a', + 'kb_note_pin' : 'p', + 'kb_note_unpin' : 'u', 'clr_default_fg' : 'default', 'clr_default_bg' : 'default', @@ -126,7 +128,9 @@ def __init__(self): 'tabstop4' : [ cp.get(cfg_sec, 'kb_tabstop4'), 'View with tabstop=4' ], 'tabstop8' : [ cp.get(cfg_sec, 'kb_tabstop8'), 'View with tabstop=8' ], 'search' : [ cp.get(cfg_sec, 'kb_search'), 'Search notes' ], - 'clear_search' : [ cp.get(cfg_sec, 'kb_clear_search'), 'Show all notes' ] + 'clear_search' : [ cp.get(cfg_sec, 'kb_clear_search'), 'Show all notes' ], + 'note_pin' : [ cp.get(cfg_sec, 'kb_note_pin'), 'Pin note' ], + 'note_unpin' : [ cp.get(cfg_sec, 'kb_note_unpin'), 'Unpin note' ] } self.colors = \ diff --git a/notes_db.py b/notes_db.py @@ -714,7 +714,10 @@ def set_note_pinned(self, key, pinned): systemtags.remove('pinned') n['modifydate'] = time.time() - self.notify_observers('change:note-status', utils.KeyValueObject(what='modifydate', key=key)) + self.notify_observers('change:note-status', + utils.KeyValueObject(what='modifydate', + key=key, + msg='Note pinned.' if pinned else 'Note unpinned.')) def worker_save(self): diff --git a/sncli.py b/sncli.py @@ -59,10 +59,7 @@ def sync_full(self): def observer_notes_db_change_note_status(self, ndb, evt_type, evt): logging.debug(evt.msg) - # XXX set status text someplace visible - skey = self.get_selected_note_key() - if skey == evt.key: - print self.ndb.get_note_status(skey) + set_status_message(evt.msg) def observer_notes_db_sync_full(self, ndb, evt_type, evt): logging.debug(evt.msg) @@ -109,10 +106,10 @@ def format_title(note): # get the note flags if note.has_key("systemtags"): flags = '' - if ('pinned' in note['systemtags']): flags = flags + u'*' - else: flags = flags + u' ' - if ('markdown' in note['systemtags']): flags = flags + u'm' - else: flags = flags + u' ' + if 'pinned' in note['systemtags']: flags = flags + u'*' + else: flags = flags + u' ' + if 'markdown' in note['systemtags']: flags = flags + u'm' + else: flags = flags + u' ' else: flags = ' ' @@ -244,6 +241,9 @@ def push_last_view(view): def pop_last_view(): return self.last_view.pop() + def set_note_pinned(note_key, pinned): + self.ndb.set_note_pinned(note_key, pinned) + def remove_status_message(loop, frame): if not hasattr(frame, 'contents'): return @@ -433,7 +433,7 @@ def update_note_titles(self, search_string): self.contents['footer'] = ( None, None ) self.update_status() if len(self.listbox.body.positions()) == 0: - set_status_message('No notes found!') + set_status_message(u'No notes found!') def update_status(self): if self.status_bar != 'yes': @@ -471,13 +471,20 @@ def note_title_listbox_keypress(self, size, key): if key == self.config.get_keybind('quit'): raise urwid.ExitMainLoop() - elif key == 'o': - set_status_message("foobar") - elif key == self.config.get_keybind('help'): push_last_view(self) sncli_loop.widget = Help() + elif key == self.config.get_keybind('note_pin'): + set_note_pinned( + list_get_note_json( + self.listbox.focus_position)['key'], 1) + + elif key == self.config.get_keybind('note_unpin'): + set_note_pinned( + list_get_note_json( + self.listbox.focus_position)['key'], 0) + elif key == self.config.get_keybind('view_log'): push_last_view(self) sncli_loop.widget = ViewLog() @@ -495,7 +502,7 @@ def note_title_listbox_keypress(self, size, key): if not pager and os.environ['PAGER']: pager = os.environ['PAGER'] if not pager: - set_status_message("No pager configured!") + set_status_message(u'No pager configured!') return saveb = self.contents['body'][0] \ @@ -509,7 +516,7 @@ def note_title_listbox_keypress(self, size, key): try: subprocess.check_call(pager + u' ' + tempfile_name(), shell=True) except Exception, e: - set_status_message("Pager error: " + str(e)) + set_status_message(u'Pager error: ' + str(e)) # XXX check if modified, if so update it tempfile_delete() @@ -698,14 +705,18 @@ def __init__(self): lines.extend(self.create_kb_help_lines(u"Keybinds Common", keys)) # NoteTitles keybinds - keys = [ 'search', + keys = [ 'note_pin', + 'note_unpin', + 'search', 'clear_search', 'view_note', 'view_note_ext' ] lines.extend(self.create_kb_help_lines(u"Keybinds Note List", keys)) # NoteContent keybinds - keys = [ 'tabstop2', + keys = [ 'note_pin', + 'note_unpin', + 'tabstop2', 'tabstop4', 'tabstop8' ] lines.extend(self.create_kb_help_lines(u"Keybinds Note Content", keys))