code: def _get_offset(text, visible_width, unicode_aware=True):
      
      result = 0
      width = 0
      if unicode_aware:
          for c in text:
              if visible_width - width <= 0:
                  break
              result += 1
              width += wcwidth(c)
          if visible_width - width < 0:
              result -= 1
      else:
          result = min(len(text), visible_width)
      return result
docs: Find the character offset within some text for a given visible offset (taking into account the
      fact that some character glyphs are double width).
  
      :param text: The text to analyze
      :param visible_width: The required location within that text (as seen on screen).
      :return: The offset within text (as a character offset within the string).