Skip to content

Commit

Permalink
feat:command history parameter -filter match to highlight
Browse files Browse the repository at this point in the history
  • Loading branch information
liuf5 committed Mar 24, 2021
1 parent 9040434 commit 0187338
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion zoomeye/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,4 +625,4 @@ def filter_fields(self, fields):
"filter command has unsupport fields [{}], support fields has [{}]".format(item, support_fields),
color='red')
exit(0)
show.print_filter_history(not_equal, result_data[:self.num])
show.print_filter_history(not_equal, result_data[:self.num], has_equal)
16 changes: 13 additions & 3 deletions zoomeye/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ def print_filter(keys, data_list, condition):
items = ""
for j in i:
j_hex = convert_str(str(j))
# match
# match to content highlight
if condition:
for item in condition:
k, v = item.split('=')
result_re = re.search(v, j_hex, re.I | re.M)
if result_re:
# match to content highlight
# replace to highlight
color_content = "\033[31m{}\033[0m".format(result_re.group())
j_hex = j_hex.replace(result_re.group(), color_content)
items += "{:<30}".format(j_hex)
Expand Down Expand Up @@ -285,11 +285,12 @@ def print_host_data(host_data):
printf(content)


def print_filter_history(fileds, hist_data):
def print_filter_history(fileds, hist_data, condition=None):
"""
print user filter history data,
:param fileds list,user input field
:param hist_data dict, from ZoomEye API get data
:param condition list, filter condition
"""
filter_title = ''
first_item = hist_data[0]
Expand All @@ -314,5 +315,14 @@ def print_filter_history(fileds, hist_data):
for data_item in all_data:
content = ""
for item_item in data_item:
# match to content highlight
if condition:
for condition_item in condition:
k, v = condition_item.split('=')
re_result = re.search(str(v), str(item_item), re.I | re.M)
content = "\033[31m{}\033[0m".format(re_result.group())
# replace to highlight
if re_result:
item_item = item_item.replace(re_result.group(), content)
content += "{:<27}".format(item_item)
printf(content)

0 comments on commit 0187338

Please sign in to comment.