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 ab2cf23 commit 3fe0c07
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion docs/example_ectd.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
},
"outputs": [],
"source": [
"print(\"\\n\".join(ctoc.find_section_given_words(words=[\"REMS\",\"dsur\"], outfmt='tree', colored='nb')))"
"print(\"\\n\".join(ctoc.find_section_given_words(words=[\"REMS\",\"dsur\"], outfmt='tree', colored='green')))"
]
},
{
Expand Down
28 changes: 14 additions & 14 deletions mtbp3/health/ectd.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,23 @@ def color_output(out="", words=[], color='red'):
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"
if color not in color_dic.keys():
return row
else:
color_str = "\x1b[31m"
color_str = f"\x1b[{color_dic[color]}m"

row = out
for word in words:
try:
row = out
for word in words:
try:
start = row.lower().index(word.lower())
end = start + len(word)
except ValueError:
continue
start = row.lower().index(word.lower())
end = start + len(word)
except ValueError:
continue
start = row.lower().index(word.lower())
end = start + len(word)
row = row[:start] + color_str + row[start:end] + "\x1b[0m" + row[end:]
row = row[:start] + color_str + row[start:end] + "\x1b[0m" + row[end:]

return row
return row

def find_section_given_words(self, words, outfmt='simple', include='up', to_right=False, colored=None):
if isinstance(words, str) and words:
Expand Down Expand Up @@ -99,14 +99,14 @@ def find_section_given_words(self, words, outfmt='simple', include='up', to_righ
out1 = out1+out2
out = list(set(out+out1))

if colored == "nb":
if colored:
out_colored=[]
for row in out:
split_row = row.split(' ', 1)
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="blue")
colored_second_part = self.color_output(second_part, words=words, color=colored)
out_colored.append(f"{first_part} {colored_second_part}")
else:
out_colored.append(row)
Expand Down

0 comments on commit 3fe0c07

Please sign in to comment.