Skip to content

Commit

Permalink
Merge pull request #100 from Kraymer/master
Browse files Browse the repository at this point in the history
Add --select-ignore option
  • Loading branch information
mooz authored Jul 23, 2019
2 parents dac0389 + 4b3a63e commit 7e7662c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
5 changes: 5 additions & 0 deletions percol/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ def setup_options(parser):
help = "whether quote the output line")
parser.add_option("--peep", action = "store_true", dest = "peep", default = False,
help = "exit immediately with doing nothing to cache module files and speed up start-up time")
parser.add_option("--select-ignore", dest="select_ignore",
help="lines that match regex cannot be selected")

def set_proper_locale(options):
try:
Expand Down Expand Up @@ -261,6 +263,9 @@ def set_if_not_none(src, dest, name):
# view settings from option values
set_if_not_none(options, percol.view, 'prompt_on_top')
set_if_not_none(options, percol.view, 'results_top_down')
# command settings from options
set_if_not_none(options, percol.command_candidate, 'select_ignore')

# enter main loop
if options.auto_fail and percol.has_no_candidate():
exit_code = percol.cancel_with_exit_code()
Expand Down
20 changes: 19 additions & 1 deletion percol/command.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,39 @@
# -*- coding: utf-8 -*-

import re
import six


class SelectorCommand(object):
"""
Wraps up SelectorModel and provides advanced commands
"""

def __init__(self, model, view):
self.model = model
self.view = view
self.select_ignore = r''

# ------------------------------------------------------------ #
# Selection
# ------------------------------------------------------------ #

# Line

def delta_next(self, step=1):
delta = step
while True:
line = self.model.get_result(self.model.index + delta)
if line is None:
return step
if not line or self.select_ignore and re.match(
self.select_ignore, line):
delta += step
continue
break
return delta

def delta_prev(self):
return self.delta_next(step=-1)
def select_successor(self):
self.model.select_index(self.model.index + 1)

Expand Down

0 comments on commit 7e7662c

Please sign in to comment.