Skip to content

Commit

Permalink
v0.2.20
Browse files Browse the repository at this point in the history
  • Loading branch information
yh202109 committed Jul 13, 2024
1 parent cd741d6 commit ab2cf23
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions mtbp3/health/ectd.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ def color_output(out="", words=[], color='red'):
words = [words]
elif isinstance(words, list) and words:
assert all(isinstance(word, str) and word for word in words), "Elements in the list must be strings"
color_dic = {'red': 31, 'green': 32, 'yellow': 33, 'blue': 34, 'magenta': 35, 'cyan': 36}
if color in color_dic.keys():
color_str = f"\x1b[{color_dic[color]}m"
else:
color_str = "\x1b[31m"

row = out
for word in words:
Expand All @@ -64,7 +69,7 @@ def color_output(out="", words=[], color='red'):
continue
start = row.lower().index(word.lower())
end = start + len(word)
row = row[:start] + f"\x1b[31m" + row[start:end] + "\x1b[0m" + row[end:]
row = row[:start] + color_str + row[start:end] + "\x1b[0m" + row[end:]

return row

Expand Down Expand Up @@ -101,7 +106,7 @@ def find_section_given_words(self, words, outfmt='simple', include='up', to_righ
if len(split_row) > 1:
first_part = split_row[0]
second_part = split_row[1]
colored_second_part = self.color_output(second_part, words=words, color="red")
colored_second_part = self.color_output(second_part, words=words, color="blue")
out_colored.append(f"{first_part} {colored_second_part}")
else:
out_colored.append(row)
Expand Down

0 comments on commit ab2cf23

Please sign in to comment.