code: def insert_ansi(p_string):
      
      result = p_string.data
  
      for pos, color in sorted(p_string.colors.items(), reverse=True):
          color = lookup_color(color)
  
          result = result[:pos] + color.as_ansi() + result[pos:]
  
      return result
docs: Returns a string with color information at the right positions.