From 78beeebe8f2aca6e11f5e0ff6bbb2faaa8c50d39 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 12 Jun 2025 23:22:46 -0400 Subject: [PATCH] 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". --- tractor/devx/pformat.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/tractor/devx/pformat.py b/tractor/devx/pformat.py index b9e1ca48..f2973441 100644 --- a/tractor/devx/pformat.py +++ b/tractor/devx/pformat.py @@ -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. ''' + indented_tree_str: str = textwrap.indent( + tree_str, + 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' - + - textwrap.indent( - tree_str, - prefix=( - len(input_op) - - - (back_from_op + 1) - ) * ' ', - ) + f'{indented_tree_str}' )