code: def supports_ansi_escape_codes(fd):
      
  
      if os.isatty(fd):
          return True
  
      if not is_win:
          return False
  
      # Check for cygwin/msys terminal
      handle = winapi._get_osfhandle(fd)
      if handle == winapi.INVALID_HANDLE_VALUE:
          return False
  
      if winapi.GetFileType(handle) != winapi.FILE_TYPE_PIPE:
          return False
  
      file_name = _get_file_name_for_handle(handle)
      match = re.match(
          "^\\\\(cygwin|msys)-[a-z0-9]+-pty[0-9]+-(from|to)-master$", file_name)
      return match is not None
docs: Returns whether the output device is capable of interpreting ANSI escape
      codes when :func:`print_` is used.
  
      Args:
          fd (int): file descriptor (e.g. ``sys.stdout.fileno()``)
      Returns:
          `bool`