nncli

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

commit 34adc95511d190fc9fe1691bd48203cd8a938f7d
parent bed564893212755687fe278b87af2126f5661d0b
Author: Eric Davis <edavis@insanum.com>
Date:   Thu,  3 Jul 2014 13:17:52 -0700

simplified help view so keybind list is automatically generated

Diffstat:
Mconfig.py | 57++++++++++++++++++++++++++++++---------------------------
Mview_help.py | 50+++++++++-----------------------------------------
2 files changed, 39 insertions(+), 68 deletions(-)

diff --git a/config.py b/config.py @@ -117,32 +117,32 @@ def __init__(self): self.keybinds = \ { - 'help' : [ cp.get(cfg_sec, 'kb_help'), 'Help' ], - 'quit' : [ cp.get(cfg_sec, 'kb_quit'), 'Quit' ], - 'down' : [ cp.get(cfg_sec, 'kb_down'), 'Scroll down one line' ], - 'up' : [ cp.get(cfg_sec, 'kb_up'), 'Scroll up one line' ], - 'page_down' : [ cp.get(cfg_sec, 'kb_page_down'), 'Page down' ], - 'page_up' : [ cp.get(cfg_sec, 'kb_page_up'), 'Page up' ], - 'half_page_down' : [ cp.get(cfg_sec, 'kb_half_page_down'), 'Half page down' ], - 'half_page_up' : [ cp.get(cfg_sec, 'kb_half_page_up'), 'Half page up' ], - 'bottom' : [ cp.get(cfg_sec, 'kb_bottom'), 'Goto bottom' ], - 'top' : [ cp.get(cfg_sec, 'kb_top'), 'Goto top' ], - 'status' : [ cp.get(cfg_sec, 'kb_status'), 'Toggle status bar' ], - 'view_note' : [ cp.get(cfg_sec, 'kb_view_note'), 'View note' ], - 'view_note_ext' : [ cp.get(cfg_sec, 'kb_view_note_ext'), 'View note with pager' ], - 'view_next_note' : [ cp.get(cfg_sec, 'kb_view_next_note'), 'View next note' ], - 'view_prev_note' : [ cp.get(cfg_sec, 'kb_view_prev_note'), 'View previous note' ], - 'view_log' : [ cp.get(cfg_sec, 'kb_view_log'), 'View log' ], - 'tabstop2' : [ cp.get(cfg_sec, 'kb_tabstop2'), 'View with tabstop=2' ], - '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' ], - 'note_pin' : [ cp.get(cfg_sec, 'kb_note_pin'), 'Pin note' ], - 'note_unpin' : [ cp.get(cfg_sec, 'kb_note_unpin'), 'Unpin note' ], - 'note_markdown' : [ cp.get(cfg_sec, 'kb_note_markdown'), 'Flag note as markdown' ], - 'note_unmarkdown' : [ cp.get(cfg_sec, 'kb_note_unmarkdown'), 'Unflag note as markdown' ], - 'note_tags' : [ cp.get(cfg_sec, 'kb_note_tags'), 'Edit note tags' ] + 'help' : [ cp.get(cfg_sec, 'kb_help'), 'common', 'Help' ], + 'quit' : [ cp.get(cfg_sec, 'kb_quit'), 'common', 'Quit' ], + 'down' : [ cp.get(cfg_sec, 'kb_down'), 'common', 'Scroll down one line' ], + 'up' : [ cp.get(cfg_sec, 'kb_up'), 'common', 'Scroll up one line' ], + 'page_down' : [ cp.get(cfg_sec, 'kb_page_down'), 'common', 'Page down' ], + 'page_up' : [ cp.get(cfg_sec, 'kb_page_up'), 'common', 'Page up' ], + 'half_page_down' : [ cp.get(cfg_sec, 'kb_half_page_down'), 'common', 'Half page down' ], + 'half_page_up' : [ cp.get(cfg_sec, 'kb_half_page_up'), 'common', 'Half page up' ], + 'bottom' : [ cp.get(cfg_sec, 'kb_bottom'), 'common', 'Goto bottom' ], + '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' ], + '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' ], + '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' ], + 'tabstop4' : [ cp.get(cfg_sec, 'kb_tabstop4'), 'notes', 'View with tabstop=4' ], + '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' ] } self.colors = \ @@ -198,9 +198,12 @@ def get_config_descr(self, name): def get_keybind(self, name): return self.keybinds[name][0] - def get_keybind_descr(self, name): + def get_keybind_use(self, name): return self.keybinds[name][1] + def get_keybind_descr(self, name): + return self.keybinds[name][2] + def get_color(self, name): return self.colors[name][0] diff --git a/view_help.py b/view_help.py @@ -7,45 +7,11 @@ def __init__(self, config): self.config = config lines = [] - - # Common keybinds - keys = [ 'help', - 'quit', - 'down', - 'up', - 'page_down', - 'page_up', - 'half_page_down', - 'half_page_up', - 'bottom', - 'top', - 'status', - 'view_log' ] - lines.extend(self.create_kb_help_lines(u"Keybinds Common", keys)) - - # NoteTitles keybinds - keys = [ 'note_pin', - 'note_unpin', - 'note_markdown', - 'note_unmarkdown', - 'note_tags', - 'search', - 'clear_search', - 'view_note', - 'view_note_ext' ] - lines.extend(self.create_kb_help_lines(u"Keybinds Note List", keys)) - - # NoteContent keybinds - keys = [ 'view_next_note', - 'view_prev_note', - 'tabstop2', - 'tabstop4', - 'tabstop8' ] - lines.extend(self.create_kb_help_lines(u"Keybinds Note Content", keys)) - + lines.extend(self.create_kb_help_lines(u'Keybinds Common', 'common')) + lines.extend(self.create_kb_help_lines(u'Keybinds Note List', 'titles')) + lines.extend(self.create_kb_help_lines(u'Keybinds Note Content', 'notes')) lines.extend(self.create_config_help_lines()) lines.extend(self.create_color_help_lines()) - lines.append(urwid.Text(('help_header', u''))) super(ViewHelp, self).__init__(urwid.SimpleFocusListWalker(lines)) @@ -71,14 +37,16 @@ def get_status_bar(self): urwid.AttrMap(urwid.Columns([ status_title, status_index ]), 'status_bar') - def create_kb_help_lines(self, header, keys): + def create_kb_help_lines(self, header, use): lines = [ urwid.AttrMap(urwid.Text(u''), 'help_header', 'help_focus') ] lines.append(urwid.AttrMap(urwid.Text(u' ' + header), 'help_header', 'help_focus')) - for c in keys: + for c in self.config.keybinds.keys(): + if self.config.get_keybind_use(c) != use: + continue lines.append( urwid.AttrMap( urwid.Text( @@ -133,7 +101,7 @@ def create_color_help_lines(self): 'help_focus')) fmap = {} for c in sorted(self.config.colors): - fmap[re.search("^(.*)(_fg|_bg)$", c).group(1)] = 'help_focus' + fmap[re.search('^(.*)(_fg|_bg)$', c).group(1)] = 'help_focus' for c in sorted(self.config.colors): lines.append( urwid.AttrMap( @@ -141,7 +109,7 @@ def create_color_help_lines(self): [ ('help_descr', '{:>24} '.format(self.config.get_color_descr(c))), ('help_config', '{:>25} '.format(u'clr_' + c)), - (re.search("^(.*)(_fg|_bg)$", c).group(1), + (re.search('^(.*)(_fg|_bg)$', c).group(1), u"'" + self.config.get_color(c) + u"'") ] ),