From eea94fd4aa8237f92e73b0e56b31bae6d25c58b9 Mon Sep 17 00:00:00 2001 From: Amber Date: Thu, 18 Jan 2024 21:41:19 +0100 Subject: [PATCH] colorize find results and comments --- src/__pycache__/tree_repr.cpython-39.pyc | Bin 5173 -> 5563 bytes src/tree_repr.py | 36 ++++++++++++++++------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/__pycache__/tree_repr.cpython-39.pyc b/src/__pycache__/tree_repr.cpython-39.pyc index b6586859e10809677e5f6eda7cfc996b7bfe6e7a..524222bce526db1431f1c399101e0f60326b0f50 100644 GIT binary patch delta 2106 zcmZ`)O>Epm6!wgN*6VfL&2HQLwAngsn#9SHq=mMqv?y&;0{s`=qLNaAyLOUQH{Q+I z8&t3fB0?%c2+&+A4k+aUTo6^^REZmc3kOa}K2+ic0wm6G;k{Y5DF`gho0<1B^X7f; zJ%2fRZ`^Xbx(o@vKi~e;f42XQ^%1qQuvKB4fDzv0U(t!R$_q46V5o@}t4Su-Jklqz zAl5cykKQKiMc~jrsm)&}i5}?fb)v^=toKMsCQ@P=sj;$7;>^07(3P>6ZfLiqi;^Rs zOO?P~_R}rZM!mu27aDBYjUt~pnRLs^vll9SLN4{C@}eKH0yxFC0!cL%My%F!viv1^ zI+tc^k-t2T$M6k#xYP?O5;ciQ47!ylL?;F*P#xw1Wj4PrzeRfal2RfiPKrhTfzrF9 z3>IM??Lc2qERqKsN=(W|`FF}2g;9{OK_t6@IF#+>u3GLs44Y5`BI$4qWn=t9bzto$ z*vArvDWS2nA&D^Az`-z42$38>KoVKVt%L{}wtVdZeF zMl#AhrB}L6F{BXQ468>f&f#jLCD}mn)Fc}>G*9c3yv%jVzKw~ed-|Jjabm>AMkdaB z#8Ycz0gxk7q{k%Ifs;kfI`y(WQk0Fg*zk;ZC?J;$thP?9p*+dOvX_fpoRsD%z(W+E8gLQf0vQ6SMcIM7rv5#7auUoO zx$VvbtW({+7S1=_Xz33+G3ltA5_SZ{Y#hlRAQgu&hwm`pE1m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PlV%z3m*><6v|Apkr)i&z)X}~Q$oUzRMk&>%8ER2RQ;ZKwM|(Fr z3@3a5;WU8Dcu{_-RXZ=j!q)+a30E^-l7DCedq2Qh5RdkfkOf4reHto)98ixvqOJZ- z5~=~iux80yA0LITqjaF$BmB}%Noeh`J*9`-VUP$dG=;&J10BEqT402Urs}C-Lg=2> zOFaD!%B=rOIQb{NOZvLQcAuJ7S&T>&`$VJ1&HWDOQ=9tjE+?gsk9 z8Vh>DrXgUHA{1cKg%DcBQ-BRB$j%|dpy+I0p=755Cs5k>mP&k!inr{Xsd&&$uJ&3x z<~T!`%GhhjZCuAOnMse)ioBd29Gr#2&tSA$1xjN-(3rMy)L)ynPH5a<8_d5%w3c?5na)EbK9%)Yw~-0Aa{u7OaP*p zzzFEbdHJvXQRQK5WEslZfmPvbv7FC4mkH}Tf1P@mrpweI@%ui&c^m` z)2mwYS;u4!^q&)BaSnQVOfF?cAkzDpYWX@Ce2S)fV$%>QJRK=!;}ZfA;}__7{mG9R zMn~+}mzkPZEEe(Fm=`fIUjpqm^J1<|$v-=%>6E;ft+HoCdfAD+d6XysMC$r>>m81U z`DKJO0+ztF;}r2%apM|5l*Bx)LND#E2mC5-$0qSPifC&^YvEP!!MG#6Rpa$$z;B=& z)_BEgcOv$R?8+6BKf|Vf7J#VoN^YDk$(`KQLR=zjQ$7sq^cxZ7ZEBrDjvM LnKHY~vZ?(CCUH^G diff --git a/src/tree_repr.py b/src/tree_repr.py index 3009c71..7ee1d90 100644 --- a/src/tree_repr.py +++ b/src/tree_repr.py @@ -31,8 +31,12 @@ def produce_treeline(prec_seps, lsep): for level_n, (sep, item) in enumerate(lseps): tomount = sep - if item: - tomount = sep + item + if item['name']: + if item.get('color_formatter'): + item_name = item['color_formatter'](item['name']) + else: + item_name = item['name'] + tomount = sep + item_name tree_line = mount_str_at(tree_line, level2indent(level_n), tomount) return tree_line.rstrip() @@ -72,7 +76,10 @@ def nerd_tree_from_struct(rootnode, prec_seps=[]): ## rootnode is always a dir -> colorize rootnode_name = rootnode['name'] - nerd_tree_txt = CYAN(rootnode_name) + if rootnode.get('color_formatter'): + nerd_tree_txt = rootnode['color_formatter'](rootnode_name) + else: + nerd_tree_txt = rootnode_name items = rootnode.get('children') or [] @@ -93,10 +100,10 @@ def nerd_tree_from_struct(rootnode, prec_seps=[]): if item['type'] == 'd': seps = prec_seps[:] - seps.append((psep_char, '')) - treeline = produce_treeline(prec_seps, (sep, ' ')) + ' ' + nerd_tree_from_struct(item, prec_seps=seps) + seps.append((psep_char, {'name' : ''})) + treeline = produce_treeline(prec_seps, (sep, {'name' : ' '})) + ' ' + nerd_tree_from_struct(item, prec_seps=seps) else: - treeline = produce_treeline(prec_seps, (sep, item['name'])) + treeline = produce_treeline(prec_seps, (sep, item)) nerd_tree_txt += '\n' + treeline @@ -171,8 +178,12 @@ def nerd_tree_struct(startpath, path=[]): return d def find_subtree(node, node_name, results=[]): + ''' + Starting fron node, recursively, find node_name and its subtree + ''' if node['name'] == node_name: + node.update({'color_formatter' : YELLOW}) results.append(node) children = node.get('children') or [] @@ -182,11 +193,16 @@ def find_subtree(node, node_name, results=[]): find_subtree(item_child, node_name, results) else: if item_child['name'] == node_name: + item_child.update({'color_formatter' : YELLOW}) results.append(item_child) def find_node(startpath, item_name): ''' - search item_name in subtree starting from startpath + @param startpath string + @param item_name string + + search the node with name==item_name (basically a subtree) + starting from startpath Note: it finds all occurrencies ''' rnode = nerd_tree_struct(startpath) @@ -198,8 +214,9 @@ def find_node(startpath, item_name): def find_children(tree, item_abs_path): ''' - It returns a tuple, first value is if father of node with item_name is found, - second value represents the children of parent node + It returns a tuple: + first value True if father of node with item_abs_path is found, + second value represents the children of parent node with item_abs_path ''' if tree['abs_path'] == item_abs_path: if not tree.get('children'): @@ -219,7 +236,6 @@ def find_children(tree, item_abs_path): def find_tree_struct(startpath, item_name): ''' - Bad!!! ''' results = find_node(startpath, item_name) if not results: