add option: show-subtree-info
This commit is contained in:
parent
451e1f1f22
commit
c18feb49e6
|
@ -12,6 +12,7 @@ cmd_parser.add_argument("pattern")
|
|||
cmd_parser.add_argument("-t", "--type")
|
||||
# if -s is found in the command line cmd_args.show_children_nodes is True
|
||||
cmd_parser.add_argument("-s", "--show-children-nodes", action="store_true")
|
||||
cmd_parser.add_argument("-S", "--show-subtree-info", action="store_true")
|
||||
## more than one occurrencies of -e option are appended in a list
|
||||
cmd_parser.add_argument("-e", "--exclude", action="append")
|
||||
|
||||
|
|
13
src/tree.py
13
src/tree.py
|
@ -209,16 +209,16 @@ class NerdTree():
|
|||
if (rootnode['is_symlink'] and rootnode.get('target', '')):
|
||||
nerd_tree_txt += ' -> %s' % (rootnode['target'],)
|
||||
|
||||
items = rootnode.get('children') or []
|
||||
|
||||
nodefound = rootnode.get('found')
|
||||
if nodefound and self.opts['dont_show_children_nodes']:
|
||||
if nodefound:
|
||||
if self.opts['dont_show_children_nodes'] or self.opts['show_subtree_info']:
|
||||
if rootnode.get('subtree_items'):
|
||||
hnum, unit = _tree_repr.format(rootnode['subtree_size'])
|
||||
nerd_tree_txt += ' (%s item(s)/%s%s ▾)' % (rootnode['subtree_items'], hnum, unit)
|
||||
|
||||
items = []
|
||||
|
||||
else:
|
||||
items = rootnode.get('children') or []
|
||||
if self.opts['dont_show_children_nodes']: items = []
|
||||
|
||||
for n, item in enumerate(items):
|
||||
# if item['name'] in _tree_repr.ITEMS_TO_EXCLUDE:
|
||||
|
@ -241,6 +241,9 @@ class NerdTree():
|
|||
treeline = _tree_repr.produce_treeline(prec_seps, (sep, {'name' : ' '})) + ' ' + self.tree_from_struct(item, prec_seps=seps)
|
||||
else:
|
||||
treeline = _tree_repr.produce_treeline(prec_seps, (sep, item))
|
||||
if item.get('found') and self.opts['show_subtree_info']:
|
||||
hnum, unit = _tree_repr.format(item['size'])
|
||||
treeline += ' (%s%s)' % (hnum, unit)
|
||||
|
||||
nerd_tree_txt += '\n' + treeline
|
||||
|
||||
|
|
|
@ -99,7 +99,10 @@ class NerdTreeFind(NerdTree):
|
|||
results = filtered_results
|
||||
|
||||
dont_show_children_nodes = self.find_opts['dont_show_children_nodes'] if self.find_opts.get('dont_show_children_nodes') is not None else False
|
||||
show_subtree_info = self.find_opts['show_subtree_info'] if self.find_opts.get('show_subtree_info') is not None else False
|
||||
|
||||
self.opts['dont_show_children_nodes'] = dont_show_children_nodes
|
||||
self.opts['show_subtree_info'] = show_subtree_info
|
||||
|
||||
|
||||
tree_struct = {}
|
||||
|
@ -138,7 +141,8 @@ class NerdTreeFind(NerdTree):
|
|||
self.find_opts = new_opts
|
||||
self.results = []
|
||||
self.item_name = new_item_name
|
||||
print('Regexp: %s' % (new_item_name,))
|
||||
print('Starting from path: %s' % CYAN(self.startpath,))
|
||||
print('Regexp: %s' % CYAN(new_item_name,))
|
||||
try:
|
||||
self.re_item_name = re.compile(r'^%s$' % (new_item_name,))
|
||||
except re.error:
|
||||
|
|
11
vfind.py
11
vfind.py
|
@ -4,20 +4,27 @@ from src.cmdline_parser import cmd_args
|
|||
from src.tree_find import NerdTreeFind
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(cmd_args.path)
|
||||
print(cmd_args.show_children_nodes)
|
||||
# print(cmd_args.path)
|
||||
# print(cmd_args.show_children_nodes)
|
||||
# print(cmd_args.show_father_subtree_info)
|
||||
path = cmd_args.path
|
||||
pattern = cmd_args.pattern
|
||||
show_children_nodes = cmd_args.show_children_nodes
|
||||
show_subtree_info = cmd_args.show_subtree_info
|
||||
|
||||
# opts for generatign the tree
|
||||
opts = {
|
||||
'items_to_exclude' : cmd_args.exclude or [],
|
||||
}
|
||||
|
||||
if show_subtree_info:
|
||||
## force show_children_nodes -> True
|
||||
show_children_nodes = True
|
||||
|
||||
# opts for find
|
||||
find_opts = {
|
||||
'dont_show_children_nodes': not show_children_nodes,
|
||||
'show_subtree_info': show_subtree_info,
|
||||
'type' : cmd_args.type,
|
||||
'items_to_include' : cmd_args.include or [],
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue