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: Taken a list of graphics attributes and apply changes.
docstr_tok: ["Taken","a","list","of","graphics","attributes","and","apply","changes","."]
code: def _select_graphic_rendition(self, attrs: list[int]) -> None:
      """
      Taken a list of graphics attributes and apply changes.
      """
      if not attrs:
          attrs = [0]
      else:
          attrs = list(attrs[::-1])
  
      while attrs:
          attr = attrs.pop()
  
          if attr in _fg_colors:
              self._color = _fg_colors[attr]
          elif attr in _bg_colors:
              self._bgcolor = _bg_colors[attr]
          elif attr == 1:
              self._bold = True
          # elif attr == 2:
          #   self._faint = True
          elif attr == 3:
              self._italic = True
          elif attr == 4:
              self._underline = True
          elif attr == 5:
              self._blink = True  # Slow blink
          elif attr == 6:
              self._blink = True  # Fast blink
          elif attr == 7:
              self._reverse = True
          elif attr == 8:
              self._hidden = True
          elif attr == 9:
              self._strike = True
          elif attr == 22:
              self._bold = False  # Normal intensity
          elif attr == 23:
              self._italic = False
          elif attr == 24:
              self._underline = False
          elif attr == 25:
              self._blink = False
          elif attr == 27:
              self._reverse = False
          elif attr == 28:
              self._hidden = False
          elif attr == 29:
              self._strike = False
          elif not attr:
              # Reset all style attributes
              self._color = None
              self._bgcolor = None
              self._bold = False
              self._underline = False
              self._strike = False
              self._italic = False
              self._blink = False
              self._reverse = False
              self._hidden = False
  
          elif attr in (38, 48) and len(attrs) > 1:
              n = attrs.pop()
  
              # 256 colors.
              if n == 5 and len(attrs) >= 1:
                  if attr == 38:
                      m = attrs.pop()
                      self._color = _256_colors.get(m)
                  elif attr == 48:
                      m = attrs.pop()
                      self._bgcolor = _256_colors.get(m)
  
              # True colors.
              if n == 2 and len(attrs) >= 3:
                  try:
                      color_str = "#{:02x}{:02x}{:02x}".format(
                          attrs.pop(),
                          attrs.pop(),
                          attrs.pop(),
                      )
                  except IndexError:
                      pass
                  else:
                      if attr == 38:
                          self._color = color_str
                      elif attr == 48:
                          self._bgcolor = color_str
  
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 3 for calling the ANSI obj's underlying member method code with example usage: obj._select_graphic_rendition(attrs) without return types