From 730c48885411b50d60e72e470ea3bb87582c0a4d Mon Sep 17 00:00:00 2001 From: Chris Lane Date: Fri, 11 Jan 2019 16:13:38 -0500 Subject: [PATCH] Introduced CHEAT_HIGHLIGHT Introduced CHEAT_HIGHLIGHT environment variable to de-couple search-term highlighting from syntax highlighting. --- cheat/sheets.py | 7 +------ cheat/utils.py | 6 +++--- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/cheat/sheets.py b/cheat/sheets.py index 4d494ee..383de87 100644 --- a/cheat/sheets.py +++ b/cheat/sheets.py @@ -86,12 +86,7 @@ def search(term): match = '' for line in open(cheatsheet[1]): if term in line: - - # highlight the search term if CHEATCOLORS equals true - if 'CHEATCOLORS' in os.environ: - line = highlight(term, line); - - match += ' ' + line + match += ' ' + highlight(term, line) if match != '': result += cheatsheet[0] + ":\n" + match + "\n" diff --git a/cheat/utils.py b/cheat/utils.py index 23d75a6..77c61a5 100644 --- a/cheat/utils.py +++ b/cheat/utils.py @@ -6,8 +6,8 @@ import sys def highlight(needle, haystack): """ Highlights a search term matched within a line """ - # if colorization is not configured, exit early - if os.environ.get('CHEATCOLORS') != 'true': + # if a highlight color is not configured, exit early + if not 'CHEAT_HIGHLIGHT' in os.environ: return haystack # otherwise, attempt to import the termcolor library @@ -19,7 +19,7 @@ def highlight(needle, haystack): return haystack # if the import succeeds, colorize the needle in haystack - return haystack.replace(needle, colored(needle, 'blue')); + return haystack.replace(needle, colored(needle, os.environ.get('CHEAT_HIGHLIGHT'))); def colorize(sheet_content): """ Colorizes cheatsheet content if so configured """