Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --select-ignore option #100

Merged
merged 1 commit into from
Jul 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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