Skip to content

Commit

Permalink
Merge branch 'feature/case_insensitive'
Browse files Browse the repository at this point in the history
Add `-i` flag for case-insensitive matching
  • Loading branch information
stdedos committed Jun 21, 2020
2 parents 8140c1d + e554310 commit dfcada5
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions colout/colout.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
context = {}
debug = False

CASE_INSENSITIVE = False

# Available styles
context["styles"] = {
"normal": 0, "bold": 1, "faint": 2, "italic": 3, "underline": 4,
Expand Down Expand Up @@ -669,12 +671,15 @@ def colorup(text, pattern, color="red", style="normal", on_groups=False, sep_lis
'\x1b[1;34mF\x1b[0m\x1b[3;34maites\x1b[0m \x1b[1;34mC\x1b[0m\x1b[3;34mhier\x1b[0m la Vache'
"""
global context
global debug

if not debug:
regex = re.compile(pattern)
else:
regex = re.compile(pattern, re.DEBUG)
re_compile_args = []

if debug:
re_compile_args.append(re.DEBUG)
if CASE_INSENSITIVE:
re_compile_args.append(re.IGNORECASE)

regex = re.compile(pattern, *re_compile_args)

# Prepare the colored text.
colored_text = ""
Expand Down Expand Up @@ -811,6 +816,9 @@ def _args_parse(argv, usage=""):
parser.add_argument("pattern", metavar="REGEX", type=str, nargs=1,
help="A regular expression")

parser.add_argument("-i", "--case-insensitive", action="store_true",
help="Match RegEx as case-insensitive pattern.")

pygments_warn=" You can use a language name to activate syntax coloring (see `-r all` for a list)."

parser.add_argument("color", metavar="COLOR", type=str, nargs='?',
Expand Down Expand Up @@ -882,6 +890,9 @@ def _args_parse(argv, usage=""):

args = parser.parse_args()

global CASE_INSENSITIVE
CASE_INSENSITIVE = args.case_insensitive

return args.pattern[0], args.color, args.style, args.groups, \
args.colormap, args.theme, args.source, args.all, args.scale, args.debug, args.resources, args.palettes_dir, \
args.themes_dir, args.default, args.sep_list, args.sep_pair
Expand Down

0 comments on commit dfcada5

Please sign in to comment.