mirror of
https://github.com/cheat/cheat.git
synced 2024-12-18 10:45:05 +01:00
Introduced CHEAT_HIGHLIGHT
Introduced CHEAT_HIGHLIGHT environment variable to de-couple search-term highlighting from syntax highlighting.
This commit is contained in:
parent
ba9051e3cd
commit
730c488854
@ -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"
|
||||
|
@ -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 """
|
||||
|
Loading…
Reference in New Issue
Block a user