ch11-24: clean up by @eumiro & sync with Atlas

This commit is contained in:
Luciano Ramalho
2021-02-14 20:58:46 -03:00
parent 03ace4f4ae
commit 47cafc801a
143 changed files with 21692 additions and 63 deletions

View File

@@ -0,0 +1,35 @@
from tree import tree
SPACES = ' ' * 4
HLINE = '\u2500' # ─ BOX DRAWINGS LIGHT HORIZONTAL
HLINE2 = HLINE * 2
ELBOW = f'\u2514{HLINE2} ' # └ BOX DRAWINGS LIGHT UP AND RIGHT
TEE = f'\u251C{HLINE2} ' # ├ BOX DRAWINGS LIGHT VERTICAL AND RIGHT
PIPE = f'\u2502 ' # │ BOX DRAWINGS LIGHT VERTICAL
def render_lines(tree_iter):
name, _, _ = next(tree_iter)
yield name
prefix = ''
for name, level, last in tree_iter:
if last:
connector = ELBOW
else:
connector = TEE
prefix = prefix[:4 * (level-1)]
prefix = prefix.replace(TEE, PIPE).replace(ELBOW, SPACES)
prefix += connector
yield prefix + name
def display(cls):
for line in render_lines(tree(cls)):
print(line)
if __name__ == '__main__':
display(BaseException)