supporting regexp

This commit is contained in:
Amber 2024-02-01 16:31:38 +01:00
parent 41113119cc
commit babce420c7
8 changed files with 13 additions and 3 deletions

2
.gitignore vendored
View File

@ -1 +1 @@
**/__pycache__
**/__pycache__/

Binary file not shown.

View File

@ -1,3 +1,5 @@
import re
from src.colors import RED, YELLOW, GREEN, CYAN , BLUE, PURPLE
from src.tree import NerdTree
@ -10,6 +12,7 @@ class NerdTreeFind(NerdTree):
def __init__(self, startpath, opts={}, find_opts={}):
self.item_name = ''
self.re_item_name = None
self.results = []
## computed tree for find
self.json_tree_find = {}
@ -17,7 +20,8 @@ class NerdTreeFind(NerdTree):
NerdTree.__init__(self, startpath, opts=opts)
def find_node_recursively(self, node):
if node['name'] == self.item_name:
# if node['name'] == self.item_name:
if self.re_item_name.match(node['name']):
node_copy = node.copy()
node_copy.update({'color_formatter' : YELLOW, 'found' : 1})
self.results.append(node_copy)
@ -28,7 +32,8 @@ class NerdTreeFind(NerdTree):
if item_child['type'] == 'd':
self.find_node_recursively(item_child)
else:
if item_child['name'] == self.item_name:
# if item_child['name'] == self.item_name:
if self.re_item_name.match(item_child['name']):
item_child_copy = item_child.copy()
item_child_copy.update({'color_formatter' : YELLOW, 'found' : 1})
self.results.append(item_child_copy)
@ -115,6 +120,11 @@ class NerdTreeFind(NerdTree):
self.find_opts = new_opts
self.results = []
self.item_name = new_item_name
print('Regexp: %s' % (new_item_name,))
try:
self.re_item_name = re.compile(r'^%s$' % (new_item_name,))
except re.error:
raise Exception('Can\'t compile regexp %s, exit' % (new_item_name,))
self.json_tree_find = {}
def print(self, item_name='', opts={}):