Re-impl `.devx.nest_from_op()` yet again XD
Apparently having lots of trouble getting the nested indenting correct.. shh This hopefully resolves it by doing the indent calcs incrementally in the order of, - `input_op: str` the "sclang" operator chars, - `nest_prefix: str` the hierarchy chars, by def our little sub-tree L: '|_', - finally the `tree_str` so there's no-overlap-/adjacency-to the `nest_prefix`. Also deprecate (kinda) the `back_from_op` param, `nest_indent` is more or less the replacement.enable_tpts
parent
1d8230716c
commit
2bd8bf16d7
|
@ -135,7 +135,7 @@ def _trio_main(
|
|||
f' loglevel: {actor.loglevel}\n'
|
||||
)
|
||||
log.info(
|
||||
'Starting new `trio` subactor:\n'
|
||||
'Starting new `trio` subactor\n'
|
||||
+
|
||||
pformat.nest_from_op(
|
||||
input_op='>(', # see syntax ideas above
|
||||
|
|
|
@ -249,8 +249,6 @@ def pformat_cs(
|
|||
)
|
||||
|
||||
|
||||
# TODO: move this func to some kinda `.devx.pformat.py` eventually
|
||||
# as we work out our multi-domain state-flow-syntax!
|
||||
def nest_from_op(
|
||||
input_op: str,
|
||||
#
|
||||
|
@ -328,7 +326,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 = ''
|
||||
nest_prefix: str = '|_',
|
||||
nest_indent: int = 0,
|
||||
|
||||
) -> str:
|
||||
'''
|
||||
|
@ -338,21 +337,29 @@ def nest_from_op(
|
|||
`tree_str` to nest content aligned with the ops last char.
|
||||
|
||||
'''
|
||||
nest_indent = nest_indent or back_from_op # <- rm latter!
|
||||
if (
|
||||
nest_prefix
|
||||
and
|
||||
nest_indent
|
||||
):
|
||||
nest_prefix: str = textwrap.indent(
|
||||
nest_prefix,
|
||||
prefix=nest_indent*' ',
|
||||
)
|
||||
|
||||
tree_str_indent: int = len(nest_prefix)
|
||||
indented_tree_str: str = textwrap.indent(
|
||||
tree_str,
|
||||
prefix=' ' *(
|
||||
len(input_op)
|
||||
-
|
||||
(back_from_op + 1)
|
||||
),
|
||||
prefix=' '*tree_str_indent
|
||||
)
|
||||
# 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):]}'
|
||||
f'{nest_prefix}{indented_tree_str[tree_str_indent:]}'
|
||||
)
|
||||
|
||||
return (
|
||||
f'{input_op}\n'
|
||||
f'{indented_tree_str}'
|
||||
|
|
Loading…
Reference in New Issue