def display_selection_streaming(
    selection: selectors.Selection,
    visible_selection: bool = True,
    ignore_exceptions: bool = False,
):
  """Displays a top-level selection object in IPython.

  This function produces a rendering of either the selection
  itself, or its selected value. However, instead of directly outputting the
  attributes of the selection, we draw the selected regions as highlighted boxes
  around selected subtrees.

  The output is still a round-trippable "repr"-like output. When
  ``visible_selection`` is True, copying it will reproduce the original
  selection. When ``visible_selection`` is False, copying it will reproduce the
  selected value.

  This function is used to implement `.show_selection()` and `.show_value()` on
  selection objects.

  Args:
    selection: A selection to render.
    visible_selection: Whether to render the selection itself rather than the
      selected value. If True, renders code to build the selection itself, and
      highlights selected nodes in blue. If False, renders the value but expands
      the selected nodes.
    ignore_exceptions: Whether to catch errors during rendering of subtrees and
      show a fallback for those subtrees, instead of failing the entire
      renderer. Best used in contexts where `render_selection_to_html` is not
      being called directly, e.g. when registering this as a default
      pretty-printer.
  """
  with lowering.collecting_deferred_renderings() as deferreds:
    rendered_ir = render_selection_to_foldable_representation(
        selection,
        visible_selection=visible_selection,
        ignore_exceptions=ignore_exceptions,
    )
  lowering.display_streaming_as_root(
      rendered_ir,
      deferreds,
      roundtrip=False,
      ignore_exceptions=ignore_exceptions,
  )
Displays a top-level selection object in IPython.

  This function produces a rendering of either the selection
  itself, or its selected value. However, instead of directly outputting the
  attributes of the selection, we draw the selected regions as highlighted boxes
  around selected subtrees.

  The output is still a round-trippable "repr"-like output. When
  ``visible_selection`` is True, copying it will reproduce the original
  selection. When ``visible_selection`` is False, copying it will reproduce the
  selected value.

  This function is used to implement `.show_selection()` and `.show_value()` on
  selection objects.

  Args:
    selection: A selection to render.
    visible_selection: Whether to render the selection itself rather than the
      selected value. If True, renders code to build the selection itself, and
      highlights selected nodes in blue. If False, renders the value but expands
      the selected nodes.
    ignore_exceptions: Whether to catch errors during rendering of subtrees and
      show a fallback for those subtrees, instead of failing the entire
      renderer. Best used in contexts where `render_selection_to_html` is not
      being called directly, e.g. when registering this as a default
      pretty-printer.
  
penzai/core/_treescope_handlers/selection_rendering.py