supporting regexp
This commit is contained in:
parent
41113119cc
commit
babce420c7
|
@ -1 +1 @@
|
||||||
**/__pycache__
|
**/__pycache__/
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,3 +1,5 @@
|
||||||
|
import re
|
||||||
|
|
||||||
from src.colors import RED, YELLOW, GREEN, CYAN , BLUE, PURPLE
|
from src.colors import RED, YELLOW, GREEN, CYAN , BLUE, PURPLE
|
||||||
from src.tree import NerdTree
|
from src.tree import NerdTree
|
||||||
|
|
||||||
|
@ -10,6 +12,7 @@ class NerdTreeFind(NerdTree):
|
||||||
|
|
||||||
def __init__(self, startpath, opts={}, find_opts={}):
|
def __init__(self, startpath, opts={}, find_opts={}):
|
||||||
self.item_name = ''
|
self.item_name = ''
|
||||||
|
self.re_item_name = None
|
||||||
self.results = []
|
self.results = []
|
||||||
## computed tree for find
|
## computed tree for find
|
||||||
self.json_tree_find = {}
|
self.json_tree_find = {}
|
||||||
|
@ -17,7 +20,8 @@ class NerdTreeFind(NerdTree):
|
||||||
NerdTree.__init__(self, startpath, opts=opts)
|
NerdTree.__init__(self, startpath, opts=opts)
|
||||||
|
|
||||||
def find_node_recursively(self, node):
|
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 = node.copy()
|
||||||
node_copy.update({'color_formatter' : YELLOW, 'found' : 1})
|
node_copy.update({'color_formatter' : YELLOW, 'found' : 1})
|
||||||
self.results.append(node_copy)
|
self.results.append(node_copy)
|
||||||
|
@ -28,7 +32,8 @@ class NerdTreeFind(NerdTree):
|
||||||
if item_child['type'] == 'd':
|
if item_child['type'] == 'd':
|
||||||
self.find_node_recursively(item_child)
|
self.find_node_recursively(item_child)
|
||||||
else:
|
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 = item_child.copy()
|
||||||
item_child_copy.update({'color_formatter' : YELLOW, 'found' : 1})
|
item_child_copy.update({'color_formatter' : YELLOW, 'found' : 1})
|
||||||
self.results.append(item_child_copy)
|
self.results.append(item_child_copy)
|
||||||
|
@ -115,6 +120,11 @@ class NerdTreeFind(NerdTree):
|
||||||
self.find_opts = new_opts
|
self.find_opts = new_opts
|
||||||
self.results = []
|
self.results = []
|
||||||
self.item_name = new_item_name
|
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 = {}
|
self.json_tree_find = {}
|
||||||
|
|
||||||
def print(self, item_name='', opts={}):
|
def print(self, item_name='', opts={}):
|
||||||
|
|
Loading…
Reference in New Issue