nncli

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

commit 215748d2fcb54b0f385b88bb4e8e3035e20ad458
parent d1617d9fb29d7b89b059510367c2d2d21158989c
Author: Eric Davis <edavis@insanum.com>
Date:   Mon,  7 Jul 2014 01:03:39 -0700

lots of note specific keybind commands exposed in the note view

Diffstat:
Mconfig.py | 18+++++++++---------
Msncli.py | 313++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------
2 files changed, 206 insertions(+), 125 deletions(-)

diff --git a/config.py b/config.py @@ -137,12 +137,12 @@ def __init__(self): 'top' : [ cp.get(cfg_sec, 'kb_top'), [ 'common' ], 'Goto top' ], 'status' : [ cp.get(cfg_sec, 'kb_status'), [ 'common' ], 'Toggle status bar' ], 'view_log' : [ cp.get(cfg_sec, 'kb_view_log'), [ 'common' ], 'View log' ], - 'trash_note' : [ cp.get(cfg_sec, 'kb_trash_note'), [ 'titles' ], 'Trash a note' ], + 'trash_note' : [ cp.get(cfg_sec, 'kb_trash_note'), [ 'titles', 'notes' ], 'Trash a note' ], 'create_note' : [ cp.get(cfg_sec, 'kb_create_note'), [ 'titles' ], 'Create a new note' ], - 'edit_note' : [ cp.get(cfg_sec, 'kb_edit_note'), [ 'titles' ], 'Edit note' ], + 'edit_note' : [ cp.get(cfg_sec, 'kb_edit_note'), [ 'titles', 'notes' ], 'Edit note' ], 'view_note' : [ cp.get(cfg_sec, 'kb_view_note'), [ 'titles' ], 'View note' ], - 'view_note_ext' : [ cp.get(cfg_sec, 'kb_view_note_ext'), [ 'titles' ], 'View note with pager' ], - 'pipe_note' : [ cp.get(cfg_sec, 'kb_pipe_note'), [ 'titles' ], 'Pipe note contents' ], + 'view_note_ext' : [ cp.get(cfg_sec, 'kb_view_note_ext'), [ 'titles', 'notes' ], 'View note with pager' ], + 'pipe_note' : [ cp.get(cfg_sec, 'kb_pipe_note'), [ 'titles', 'notes' ], 'Pipe note contents' ], 'view_next_note' : [ cp.get(cfg_sec, 'kb_view_next_note'), [ 'notes' ], 'View next note' ], 'view_prev_note' : [ cp.get(cfg_sec, 'kb_view_prev_note'), [ 'notes' ], 'View previous note' ], 'tabstop2' : [ cp.get(cfg_sec, 'kb_tabstop2'), [ 'notes' ], 'View with tabstop=2' ], @@ -150,11 +150,11 @@ def __init__(self): 'tabstop8' : [ cp.get(cfg_sec, 'kb_tabstop8'), [ 'notes' ], 'View with tabstop=8' ], 'search' : [ cp.get(cfg_sec, 'kb_search'), [ 'titles' ], 'Search notes' ], 'clear_search' : [ cp.get(cfg_sec, 'kb_clear_search'), [ 'titles' ], 'Show all notes' ], - 'note_pin' : [ cp.get(cfg_sec, 'kb_note_pin'), [ 'titles' ], 'Pin note' ], - 'note_unpin' : [ cp.get(cfg_sec, 'kb_note_unpin'), [ 'titles' ], 'Unpin note' ], - 'note_markdown' : [ cp.get(cfg_sec, 'kb_note_markdown'), [ 'titles' ], 'Flag note as markdown' ], - 'note_unmarkdown' : [ cp.get(cfg_sec, 'kb_note_unmarkdown'), [ 'titles' ], 'Unflag note as markdown' ], - 'note_tags' : [ cp.get(cfg_sec, 'kb_note_tags'), [ 'titles' ], 'Edit note tags' ] + 'note_pin' : [ cp.get(cfg_sec, 'kb_note_pin'), [ 'titles', 'notes' ], 'Pin note' ], + 'note_unpin' : [ cp.get(cfg_sec, 'kb_note_unpin'), [ 'titles', 'notes' ], 'Unpin note' ], + 'note_markdown' : [ cp.get(cfg_sec, 'kb_note_markdown'), [ 'titles', 'notes' ], 'Flag note as markdown' ], + 'note_unmarkdown' : [ cp.get(cfg_sec, 'kb_note_unmarkdown'), [ 'titles', 'notes' ], 'Unflag note as markdown' ], + 'note_tags' : [ cp.get(cfg_sec, 'kb_note_tags'), [ 'titles', 'notes' ], 'Edit note tags' ] } self.colors = \ diff --git a/sncli.py b/sncli.py @@ -203,9 +203,19 @@ def gui_tags_input(self, tags): self.gui_body_focus() self.master_frame.keypress = self.gui_frame_keypress if tags != None: - self.ndb.set_note_tags( - self.view_titles.note_list[self.view_titles.focus_position].note['key'], tags) - self.view_titles.update_note_title(None) + if self.gui_body_get().__class__ != view_titles.ViewTitles: + note = self.view_titles.note_list[self.view_titles.focus_position].note + else: # self.gui_body_get().__class__ == view_note.ViewNote: + note = self.view_note.note + + self.ndb.set_note_tags(note['key'], tags) + + if self.gui_body_get().__class__ != view_titles.ViewTitles: + self.view_titles.update_note_title(None) + else: # self.gui_body_get().__class__ == view_note.ViewNote: + self.view_note.update_note(note['key']) + + self.gui_update_status_bar() def gui_pipe_input(self, cmd): self.gui_footer_clear() @@ -326,198 +336,269 @@ def gui_frame_keypress(self, size, key): self.status_bar = self.config.get_config('status_bar') elif key == self.config.get_keybind('trash_note'): + if self.gui_body_get().__class__ != view_titles.ViewTitles and \ + self.gui_body_get().__class__ != view_note.ViewNotes: + return key + if self.gui_body_get().__class__ == view_titles.ViewTitles: if len(lb.body.positions()) <= 0: return None note = lb.note_list[lb.focus_position].note - self.ndb.set_note_deleted(note['key']) + else: # self.gui_body_get().__class__ == view_note.ViewNote: + note = lb.note + + self.ndb.set_note_deleted(note['key']) elif key == self.config.get_keybind('create_note'): - if self.gui_body_get().__class__ == view_titles.ViewTitles: - editor = self.get_editor() - if not editor: return None - - tf = temp.tempfile_create(None) - try: - subprocess.check_call(editor + u' ' + temp.tempfile_name(tf), shell=True) - except Exception, e: - self.gui_status_message_set(u'Editor error: ' + str(e)) - return None + if self.gui_body_get().__class__ != view_titles.ViewTitles: + return key - content = ''.join(temp.tempfile_content(tf)) - if content: - self.gui_status_message_set(u'New note created') - self.ndb.create_note(content) + editor = self.get_editor() + if not editor: return None - temp.tempfile_delete(tf) + tf = temp.tempfile_create(None) + try: + subprocess.check_call(editor + u' ' + temp.tempfile_name(tf), shell=True) + except Exception, e: + self.gui_status_message_set(u'Editor error: ' + str(e)) + return None + + content = ''.join(temp.tempfile_content(tf)) + if content: + self.gui_status_message_set(u'New note created') + self.ndb.create_note(content) + + temp.tempfile_delete(tf) elif key == self.config.get_keybind('edit_note'): + if self.gui_body_get().__class__ != view_titles.ViewTitles and \ + self.gui_body_get().__class__ != view_note.ViewNote: + return key + if self.gui_body_get().__class__ == view_titles.ViewTitles: if len(lb.body.positions()) <= 0: return None - - editor = self.get_editor() - if not editor: return None - note = lb.note_list[lb.focus_position].note - md5_old = md5.new(note['content']).digest() - tf = temp.tempfile_create(note) - try: - subprocess.check_call(editor + u' ' + temp.tempfile_name(tf), shell=True) - except Exception, e: - self.gui_status_message_set(u'Editor error: ' + str(e)) - return None + else: # self.gui_body_get().__class__ == view_note.ViewNote: + note = lb.note + + editor = self.get_editor() + if not editor: return None + md5_old = md5.new(note['content']).digest() + tf = temp.tempfile_create(note) + try: + subprocess.check_call(editor + u' ' + temp.tempfile_name(tf), shell=True) + except Exception, e: + self.gui_status_message_set(u'Editor error: ' + str(e)) + temp.tempfile_delete(tf) + else: new_content = ''.join(temp.tempfile_content(tf)) md5_new = md5.new(new_content).digest() if md5_old != md5_new: self.gui_status_message_set(u'Note updated') self.ndb.set_note_content(note['key'], new_content) - lb.update_note_title(None) + if self.gui_body_get().__class__ == view_titles.ViewTitles: + lb.update_note_title(None) + else: # self.gui_body_get().__class__ == view_note.ViewNote: + lb.update_note(note['key']) temp.tempfile_delete(tf) elif key == self.config.get_keybind('view_note'): - # only when viewing the note list - if self.gui_body_get().__class__ == view_titles.ViewTitles: - if len(lb.body.positions()) <= 0: - return None - note = lb.note_list[lb.focus_position].note - self.view_note.update_note(note['key']) - self.gui_switch_frame_body(self.view_note) + if self.gui_body_get().__class__ != view_titles.ViewTitles: + return key + + if len(lb.body.positions()) <= 0: + return None + note = lb.note_list[lb.focus_position].note + self.view_note.update_note(note['key']) + self.gui_switch_frame_body(self.view_note) elif key == self.config.get_keybind('view_note_ext'): - # only when viewing the note list + if self.gui_body_get().__class__ != view_titles.ViewTitles and \ + self.gui_body_get().__class__ != view_note.ViewNote: + return key + if self.gui_body_get().__class__ == view_titles.ViewTitles: if len(lb.body.positions()) <= 0: return None + note = lb.note_list[lb.focus_position].note + else: # self.gui_body_get().__class__ == view_note.ViewNote: + note = lb.note - pager = self.get_pager() - if not pager: return None + pager = self.get_pager() + if not pager: return None - note = lb.note_list[lb.focus_position].note - md5_old = md5.new(note['content']).digest() - tf = temp.tempfile_create(note) - try: - subprocess.check_call(pager + u' ' + temp.tempfile_name(tf), shell=True) - except Exception, e: - self.gui_status_message_set(u'Pager error: ' + str(e)) - return None + md5_old = md5.new(note['content']).digest() + tf = temp.tempfile_create(note) + try: + subprocess.check_call(pager + u' ' + temp.tempfile_name(tf), shell=True) + except Exception, e: + self.gui_status_message_set(u'Pager error: ' + str(e)) + return None - new_content = ''.join(temp.tempfile_content(tf)) - md5_new = md5.new(new_content).digest() - if md5_old != md5_new: - self.gui_status_message_set(u'Note updated') - self.ndb.set_note_content(note['key'], new_content) - lb.update_note_title(None) - temp.tempfile_delete(tf) + new_content = ''.join(temp.tempfile_content(tf)) + md5_new = md5.new(new_content).digest() + if md5_old != md5_new: + self.gui_status_message_set(u'Note updated') + self.ndb.set_note_content(note['key'], new_content) + lb.update_note_title(None) + temp.tempfile_delete(tf) elif key == self.config.get_keybind('pipe_note'): - # only when viewing the note list + if self.gui_body_get().__class__ != view_titles.ViewTitles and \ + self.gui_body_get().__class__ != view_note.ViewNote: + return key + if self.gui_body_get().__class__ == view_titles.ViewTitles: if len(lb.body.positions()) <= 0: return None note = lb.note_list[lb.focus_position].note - self.gui_status_message_cancel() - self.gui_footer_set( - urwid.AttrMap( - user_input.UserInput(self.config, - key, '', - self.gui_pipe_input), - 'search_bar')) - self.gui_footer_focus() - self.master_frame.keypress = self.gui_footer_get().keypress + else: # self.gui_body_get().__class__ == view_note.ViewNote: + note = lb.note + + self.gui_status_message_cancel() + self.gui_footer_set( + urwid.AttrMap( + user_input.UserInput(self.config, + key, '', + self.gui_pipe_input), + 'search_bar')) + self.gui_footer_focus() + self.master_frame.keypress = self.gui_footer_get().keypress elif key == self.config.get_keybind('view_next_note'): - # only when viewing the note content - if self.gui_body_get().__class__ == view_note.ViewNote: - if len(self.view_titles.body.positions()) <= 0: - return None - last = len(self.view_titles.body.positions()) - if self.view_titles.focus_position == (last - 1): - return None - self.view_titles.focus_position += 1 - lb.update_note( - self.view_titles.note_list[self.view_titles.focus_position].note['key']) - self.gui_switch_frame_body(self.view_note) + if self.gui_body_get().__class__ != view_note.ViewNote: + return key + + if len(self.view_titles.body.positions()) <= 0: + return None + last = len(self.view_titles.body.positions()) + if self.view_titles.focus_position == (last - 1): + return None + self.view_titles.focus_position += 1 + lb.update_note( + self.view_titles.note_list[self.view_titles.focus_position].note['key']) + self.gui_switch_frame_body(self.view_note) elif key == self.config.get_keybind('view_prev_note'): - # only when viewing the note content - if self.gui_body_get().__class__ == view_note.ViewNote: - if len(self.view_titles.body.positions()) <= 0: - return None - if self.view_titles.focus_position == 0: - return None - self.view_titles.focus_position -= 1 - lb.update_note( - self.view_titles.note_list[self.view_titles.focus_position].note['key']) - self.gui_switch_frame_body(self.view_note) + if self.gui_body_get().__class__ != view_note.ViewNote: + return key + + if len(self.view_titles.body.positions()) <= 0: + return None + if self.view_titles.focus_position == 0: + return None + self.view_titles.focus_position -= 1 + lb.update_note( + self.view_titles.note_list[self.view_titles.focus_position].note['key']) + self.gui_switch_frame_body(self.view_note) elif key == self.config.get_keybind('search'): - # search when viewing the note list - if self.gui_body_get().__class__ == view_titles.ViewTitles: - self.gui_status_message_cancel() - self.gui_footer_set(urwid.AttrMap( - user_input.UserInput(self.config, - key, '', - self.gui_search_input), - 'search_bar')) - self.gui_footer_focus() - self.master_frame.keypress = self.gui_footer_get().keypress + if self.gui_body_get().__class__ != view_titles.ViewTitles: + return key + + self.gui_status_message_cancel() + self.gui_footer_set(urwid.AttrMap( + user_input.UserInput(self.config, + key, '', + self.gui_search_input), + 'search_bar')) + self.gui_footer_focus() + self.master_frame.keypress = self.gui_footer_get().keypress elif key == self.config.get_keybind('note_pin'): - # pin note when viewing the note list + if self.gui_body_get().__class__ != view_titles.ViewTitles and \ + self.gui_body_get().__class__ != view_note.ViewNote: + return key + if self.gui_body_get().__class__ == view_titles.ViewTitles: if len(lb.body.positions()) <= 0: return None note = lb.note_list[lb.focus_position].note - self.ndb.set_note_pinned(note['key'], 1) + else: # self.gui_body_get().__class__ == view_note.ViewNote: + note = lb.note + + self.ndb.set_note_pinned(note['key'], 1) + + if self.gui_body_get().__class__ == view_titles.ViewTitles: lb.update_note_title(None) elif key == self.config.get_keybind('note_unpin'): - # unpin note when viewing the note list + if self.gui_body_get().__class__ != view_titles.ViewTitles and \ + self.gui_body_get().__class__ != view_note.ViewNote: + return key + if self.gui_body_get().__class__ == view_titles.ViewTitles: if len(lb.body.positions()) <= 0: return None note = lb.note_list[lb.focus_position].note - self.ndb.set_note_pinned(note['key'], 0) + else: # self.gui_body_get().__class__ == view_note.ViewNote: + note = lb.note + + self.ndb.set_note_pinned(note['key'], 0) + if self.gui_body_get().__class__ == view_titles.ViewTitles: lb.update_note_title(None) elif key == self.config.get_keybind('note_markdown'): - # markdown note when viewing the note list + if self.gui_body_get().__class__ != view_titles.ViewTitles and \ + self.gui_body_get().__class__ != view_note.ViewNote: + return key + if self.gui_body_get().__class__ == view_titles.ViewTitles: if len(lb.body.positions()) <= 0: return None note = lb.note_list[lb.focus_position].note - self.ndb.set_note_markdown(note['key'], 1) + else: # self.gui_body_get().__class__ == view_note.ViewNote: + note = lb.note + + self.ndb.set_note_markdown(note['key'], 1) + if self.gui_body_get().__class__ == view_titles.ViewTitles: lb.update_note_title(None) elif key == self.config.get_keybind('note_unmarkdown'): - # unmarkdown note when viewing the note list + if self.gui_body_get().__class__ != view_titles.ViewTitles and \ + self.gui_body_get().__class__ != view_note.ViewNote: + return key + if self.gui_body_get().__class__ == view_titles.ViewTitles: if len(lb.body.positions()) <= 0: return None note = lb.note_list[lb.focus_position].note - self.ndb.set_note_markdown(note['key'], 0) + else: # self.gui_body_get().__class__ == view_note.ViewNote: + note = lb.note + + self.ndb.set_note_markdown(note['key'], 0) + if self.gui_body_get().__class__ == view_titles.ViewTitles: lb.update_note_title(None) elif key == self.config.get_keybind('note_tags'): - # edit tags when viewing the note list + if self.gui_body_get().__class__ != view_titles.ViewTitles and \ + self.gui_body_get().__class__ != view_note.ViewNote: + return key + if self.gui_body_get().__class__ == view_titles.ViewTitles: if len(lb.body.positions()) <= 0: return None note = lb.note_list[lb.focus_position].note - self.gui_status_message_cancel() - self.gui_footer_set( - urwid.AttrMap( - user_input.UserInput(self.config, - 'Tags: ', - '%s' % ','.join(note['tags']), - self.gui_tags_input), - 'search_bar')) - self.gui_footer_focus() - self.master_frame.keypress = self.gui_footer_get().keypress + else: # self.gui_body_get().__class__ == view_note.ViewNote: + note = lb.note + + self.gui_status_message_cancel() + self.gui_footer_set( + urwid.AttrMap( + user_input.UserInput(self.config, + 'Tags: ', + '%s' % ','.join(note['tags']), + self.gui_tags_input), + 'search_bar')) + self.gui_footer_focus() + self.master_frame.keypress = self.gui_footer_get().keypress elif key == self.config.get_keybind('clear_search'): + if self.gui_body_get().__class__ != view_titles.ViewTitles: + return key + self.view_titles.update_note_list(None) self.gui_body_set(self.view_titles)