class_docstr: ANSI formatted text.
  Take something ANSI escaped text, for use as a formatted string. E.g.
  
  ::
  
      ANSI('\x1b[31mhello \x1b[32mworld')
  
  Characters between ``\001`` and ``\002`` are supposed to have a zero width
  when printed, but these are literally sent to the terminal output. This can
  be used for instance, for inserting Final Term prompt commands.  They will
  be translated into a prompt_toolkit '[ZeroWidthEscape]' fragment.
class_docstr_tok: ["ANSI","formatted","text",".","Take","something","ANSI","escaped","text",",","for","use","as","a","formatted","string",".","E.g",".",":",":","ANSI","(","'\\x1b","[","31mhello","\\x1b","[","32mworld","'",")","Characters","between","``","\\001","``","and","``","\\002","``","are","supposed","to","have","a","zero","width","when","printed",",","but","these","are","literally","sent","to","the","terminal","output",".","This","can","be","used","for","instance",",","for","inserting","Final","Term","prompt","commands",".","They","will","be","translated","into","a","prompt_toolkit","'","[","ZeroWidthEscape","]","'","fragment","."]
docstr: Coroutine that parses the ANSI escape sequences.
docstr_tok: ["Coroutine","that","parses","the","ANSI","escape","sequences","."]
code: def _parse_corot(self) -> Generator[None, str, None]:
      """
      Coroutine that parses the ANSI escape sequences.
      """
      style = ""
      formatted_text = self._formatted_text
  
      while True:
          # NOTE: CSI is a special token within a stream of characters that
          #       introduces an ANSI control sequence used to set the
          #       style attributes of the following characters.
          csi = False
  
          c = yield
  
          # Everything between \001 and \002 should become a ZeroWidthEscape.
          if c == "\001":
              escaped_text = ""
              while c != "\002":
                  c = yield
                  if c == "\002":
                      formatted_text.append(
                          ("[ZeroWidthEscape]", escaped_text)
                      )
                      c = yield
                      break
                  else:
                      escaped_text += c
  
          # Check for CSI
          if c == "\x1b":
              # Start of color escape sequence.
              square_bracket = yield
              if square_bracket == "[":
                  csi = True
              else:
                  continue
          elif c == "\x9b":
              csi = True
  
          if csi:
              # Got a CSI sequence. Color codes are following.
              current = ""
              params = []
  
              while True:
                  char = yield
  
                  # Construct number
                  if char.isdigit():
                      current += char
  
                  # Eval number
                  else:
                      # Limit and save number value
                      params.append(min(int(current or 0), 9999))
  
                      # Get delimiter token if present
                      if char == ";":
                          current = ""
  
                      # Check and evaluate color codes
                      elif char == "m":
                          # Set attributes and token.
                          self._select_graphic_rendition(params)
                          style = self._create_style_string()
                          break
  
                      # Check and evaluate cursor forward
                      elif char == "C":
                          for i in range(params[0]):
                              # add <SPACE> using current style
                              formatted_text.append((style, " "))
                          break
  
                      else:
                          # Ignore unsupported sequence.
                          break
          else:
              # Add current character.
              # NOTE: At this point, we could merge the current character
              #       into the previous tuple if the style did not change,
              #       however, it's not worth the effort given that it will
              #       be "Exploded" once again when it's rendered to the
              #       output.
              formatted_text.append((style, c))
  
file_path: catboost/contrib/python/prompt-toolkit/py3/prompt_toolkit/formatted_text/ansi.py
imports: from __future__ import annotations
  from string import Formatter
  from typing import Generator
  from prompt_toolkit.output.vt100 import BG_ANSI_COLORS, FG_ANSI_COLORS
  from prompt_toolkit.output.vt100 import _256_colors
  from .base import StyleAndTextTuples
label_desc: Use image node_id 2 for calling the ANSI obj's underlying member method code with example usage: obj._parse_corot() without return types