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 """