nncli

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

commit a18bce32c9743623a51b885fbaddfbf306c6f6ce
parent 6190ff331c0500d7e255d99f97d5d0aefebdd519
Author: Shawn Axsom <shawn.axsom@rooksecurity.com>
Date:   Sun,  8 Mar 2015 15:00:37 -0400

Regular expression search is working within notes

Diffstat:
Msimplenote_cli/config.py | 2+-
Msimplenote_cli/view_note.py | 24++++++++++++++++++------
Msimplenote_cli/view_titles.py | 2+-
3 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/simplenote_cli/config.py b/simplenote_cli/config.py @@ -181,7 +181,7 @@ def __init__(self): self.keybinds['search_gstyle'] = [ cp.get(cfg_sec, 'kb_search_gstyle'), [ 'titles', 'notes' ], 'Search using gstyle' ] self.keybinds['search_prev_gstyle'] = [ cp.get(cfg_sec, 'kb_search_prev_gstyle'), [ 'notes' ], 'Search backwards using gstyle' ] self.keybinds['search_regex'] = [ cp.get(cfg_sec, 'kb_search_regex'), [ 'titles', 'notes' ], 'Search using regex' ] - self.keybinds['search_prev_regex'] = [ cp.get(cfg_sec, 'kb_search_regex'), [ 'titles', 'notes' ], 'Search using regex' ] + self.keybinds['search_prev_regex'] = [ cp.get(cfg_sec, 'kb_search_prev_regex'), [ 'titles', 'notes' ], 'Search using regex' ] self.keybinds['search_next'] = [ cp.get(cfg_sec, 'kb_search_next'), [ 'notes' ], 'Go to next search result' ] self.keybinds['search_prev'] = [ cp.get(cfg_sec, 'kb_search_prev'), [ 'notes' ], 'Go to previous search result' ] self.keybinds['clear_search'] = [ cp.get(cfg_sec, 'kb_clear_search'), [ 'titles' ], 'Show all notes' ] diff --git a/simplenote_cli/view_note.py b/simplenote_cli/view_note.py @@ -4,6 +4,7 @@ import time, urwid import utils +import re class ViewNote(urwid.ListBox): @@ -13,6 +14,7 @@ def __init__(self, config, args): self.key = args['key'] self.log = args['log'] self.search_string = '' + self.search_mode = 'gstyle' self.search_direction = '' self.note = self.ndb.get_note(self.key) if self.key else None self.old_note = None @@ -83,26 +85,36 @@ def lines_before_current_position(self): lines_before_current_position.reverse() return lines_before_current_position - def search_note_view_next(self, search_string=None, search_mode='gstyle'): + def search_note_view_next(self, search_string=None, search_mode=None): if search_string: self.search_string = search_string + if search_mode: + self.search_mode = search_mode note_range = self.lines_after_current_position() if self.search_direction == 'forward' else self.lines_before_current_position() - self.search_note_range(note_range, search_mode) + self.search_note_range(note_range) - def search_note_view_prev(self, search_string=None, search_mode='gstyle'): + def search_note_view_prev(self, search_string=None, search_mode=None): if search_string: self.search_string = search_string + if search_mode: + self.search_mode = search_mode note_range = self.lines_after_current_position() if self.search_direction == 'backward' else self.lines_before_current_position() - self.search_note_range(note_range, search_mode) + self.search_note_range(note_range) - def search_note_range(self, note_range, search_mode='gstyle'): + def search_note_range(self, note_range): for line in note_range: line_content = self.note['content'].split('\n')[line] - if (self.search_string in line_content): + if (self.is_match(self.search_string, line_content)): self.focus_position = line break self.update_note_view() + def is_match(self, term, full_text): + if self.search_mode == 'gstyle': + return term in full_text + else: + results = re.search(term, full_text) + return ( results is not None ) def get_status_bar(self): if not self.key: diff --git a/simplenote_cli/view_titles.py b/simplenote_cli/view_titles.py @@ -26,7 +26,7 @@ def update_note_list(self, search_string, search_mode='gstyle'): if len(self.note_list) == 0: self.log(u'No notes found!') else: - self.focus_position = 1 #TESTING + self.focus_position = 0 def sort_note_list(self, sort_mode): self.ndb.filtered_notes_sort(self.note_list, sort_mode)