code: def wrap_text(
      text,
      width=78,
      initial_indent="",
      subsequent_indent="",
      preserve_paragraphs=False,
  ):
      """A helper function that intelligently wraps text.  By default, it
      assumes that it operates on a single paragraph of text but if the
      `preserve_paragraphs` parameter is provided it will intelligently
      handle paragraphs (defined by two empty lines).
  
      If paragraphs are handled, a paragraph can be prefixed with an empty
      line containing the ``\\b`` character (``\\x08``) to indicate that
      no rewrapping should happen in that block.
  
      :param text: the text that should be rewrapped.
      :param width: the maximum width for the text.
      :param initial_indent: the initial indent that should be placed on the
                             first line as a string.
      :param subsequent_indent: the indent string that should be placed on
                                each consecutive line.
      :param preserve_paragraphs: if this flag is set then the wrapping will
                                  intelligently handle paragraphs.
      """
      from ._textwrap import TextWrapper
  
      text = text.expandtabs()
      wrapper = TextWrapper(
          width,
          initial_indent=initial_indent,
          subsequent_indent=subsequent_indent,
          replace_whitespace=False,
      )
      if not preserve_paragraphs:
          return wrapper.fill(text)
  
      p = []
      buf = []
      indent = None
  
      def _flush_par():
          if not buf:
              return
          if buf[0].strip() == "\b":
              p.append((indent or 0, True, "\n".join(buf[1:])))
          else:
              p.append((indent or 0, False, " ".join(buf)))
          del buf[:]
  
      for line in text.splitlines():
          if not line:
              _flush_par()
              indent = None
          else:
              if indent is None:
                  orig_len = term_len(line)
                  line = line.lstrip()
                  indent = orig_len - term_len(line)
              buf.append(line)
      _flush_par()
  
      rv = []
      for indent, raw, text in p:
          with wrapper.extra_indent(" " * indent):
              if raw:
                  rv.append(wrapper.indent_only(text))
              else:
                  rv.append(wrapper.fill(text))
  
      return "\n\n".join(rv)
  
imports: from contextlib import contextmanager
  from ._compat import term_len
  from .parser import split_opt
  from .termui import get_terminal_size
label_desc: Use image node_id 3 for calling a global function with example usage: wrap_text(text, width, initial_indent, subsequent_indent, preserve_paragraphs) and returns: str, wrapper