Augment `nest_from_op()` with a `nest_prefix: str`

Such that the caller can pass chars they'd like to prefix the first line
of the (indented) `tree_str`, commonly we use '|_' for "obj fields".
moar_eg_smoothing
Tyler Goodlet 2025-06-12 23:22:46 -04:00
parent 333fde39ad
commit 78beeebe8f
1 changed files with 18 additions and 9 deletions

View File

@ -328,6 +328,8 @@ def nest_from_op(
# NOTE: so move back-from-the-left of the `input_op` by
# this amount.
back_from_op: int = 0,
nest_prefix: str = ''
) -> str:
'''
Depth-increment the input (presumably hierarchy/supervision)
@ -336,15 +338,22 @@ def nest_from_op(
`tree_str` to nest content aligned with the ops last char.
'''
return (
f'{input_op}\n'
+
textwrap.indent(
indented_tree_str: str = textwrap.indent(
tree_str,
prefix=(
prefix=' ' *(
len(input_op)
-
(back_from_op + 1)
) * ' ',
),
)
# inject any provided nesting-prefix chars
# into the head of the first line.
if nest_prefix:
indented_tree_str: str = (
f'{nest_prefix}'
f'{indented_tree_str[len(nest_prefix):]}'
)
return (
f'{input_op}\n'
f'{indented_tree_str}'
)