code: def print_formatted_text(
      output: Output,
      formatted_text: AnyFormattedText,
      style: BaseStyle,
      style_transformation: StyleTransformation | None = None,
      color_depth: ColorDepth | None = None,
  ) -> None:
      """
      Print a list of (style_str, text) tuples in the given style to the output.
      """
      fragments = to_formatted_text(formatted_text)
      style_transformation = (
          style_transformation or DummyStyleTransformation()
      )
      color_depth = color_depth or output.get_default_color_depth()
  
      # Reset first.
      output.reset_attributes()
      output.enable_autowrap()
      last_attrs: Attrs | None = None
  
      # Print all (style_str, text) tuples.
      attrs_for_style_string = _StyleStringToAttrsCache(
          style.get_attrs_for_style_str, style_transformation
      )
  
      for style_str, text, *_ in fragments:
          attrs = attrs_for_style_string[style_str]
  
          # Set style attributes if something changed.
          if attrs != last_attrs:
              if attrs:
                  output.set_attributes(attrs, color_depth)
              else:
                  output.reset_attributes()
          last_attrs = attrs
  
          # Print escape sequences as raw output
          if "[ZeroWidthEscape]" in style_str:
              output.write_raw(text)
          else:
              # Eliminate carriage returns
              text = text.replace("\r", "")
              # Insert a carriage return before every newline (important when the
              # front-end is a telnet client).
              text = text.replace("\n", "\r\n")
              output.write(text)
  
      # Reset again.
      output.reset_attributes()
      output.flush()
  
imports: from __future__ import annotations
  from asyncio import FIRST_COMPLETED, Future, ensure_future, sleep, wait
  from collections import deque
  from enum import Enum
  from typing import TYPE_CHECKING, Any, Callable, Dict, Hashable
  from prompt_toolkit.application.current import get_app
  from prompt_toolkit.cursor_shapes import CursorShape
  from prompt_toolkit.data_structures import Point, Size
  from prompt_toolkit.filters import FilterOrBool, to_filter
  from prompt_toolkit.formatted_text import AnyFormattedText, to_formatted_text
  from prompt_toolkit.layout.mouse_handlers import MouseHandlers
  from prompt_toolkit.layout.screen import Char, Screen, WritePosition
  from prompt_toolkit.output import ColorDepth, Output
  from prompt_toolkit.styles import Attrs, BaseStyle, DummyStyleTransformation, StyleTransformation
label_desc: Use image node_id 2 for calling a global function with example usage: print_formatted_text(output, formatted_text, style, style_transformation, color_depth) without return types