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
Tyler Goodlet 2025-06-17 17:02:21 -04:00
parent 1d8230716c
commit 2bd8bf16d7
2 changed files with 18 additions and 11 deletions

View File

@ -135,7 +135,7 @@ def _trio_main(
f' loglevel: {actor.loglevel}\n' f' loglevel: {actor.loglevel}\n'
) )
log.info( log.info(
'Starting new `trio` subactor:\n' 'Starting new `trio` subactor\n'
+ +
pformat.nest_from_op( pformat.nest_from_op(
input_op='>(', # see syntax ideas above input_op='>(', # see syntax ideas above

View File

@ -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( def nest_from_op(
input_op: str, input_op: str,
# #
@ -328,7 +326,8 @@ def nest_from_op(
# NOTE: so move back-from-the-left of the `input_op` by # NOTE: so move back-from-the-left of the `input_op` by
# this amount. # this amount.
back_from_op: int = 0, back_from_op: int = 0,
nest_prefix: str = '' nest_prefix: str = '|_',
nest_indent: int = 0,
) -> str: ) -> str:
''' '''
@ -338,21 +337,29 @@ def nest_from_op(
`tree_str` to nest content aligned with the ops last char. `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( indented_tree_str: str = textwrap.indent(
tree_str, tree_str,
prefix=' ' *( prefix=' '*tree_str_indent
len(input_op)
-
(back_from_op + 1)
),
) )
# inject any provided nesting-prefix chars # inject any provided nesting-prefix chars
# into the head of the first line. # into the head of the first line.
if nest_prefix: if nest_prefix:
indented_tree_str: str = ( indented_tree_str: str = (
f'{nest_prefix}' f'{nest_prefix}{indented_tree_str[tree_str_indent:]}'
f'{indented_tree_str[len(nest_prefix):]}'
) )
return ( return (
f'{input_op}\n' f'{input_op}\n'
f'{indented_tree_str}' f'{indented_tree_str}'