code: def _enforce_width(text, width, unicode_aware=True):
      
      # Double-width strings cannot be more than twice the string length, so no need to try
      # expensive truncation if this upper bound isn't an issue.
      if 2 * len(text) < width:
          return text
  
      # Can still optimize performance if we are not handling unicode characters.
      if unicode_aware:
          size = 0
          for i, c in enumerate(text):
              w = wcwidth(c) if ord(c) >= 256 else 1
              if size + w > width:
                  return text[0:i]
              size += w
      elif len(text) + 1 > width:
          return text[0:width]
      return text
docs: Enforce a displayed piece of text to be a certain number of cells wide.  This takes into
      account double-width characters used in CJK languages.
  
      :param text: The text to be truncated
      :param width: The screen cell width to enforce
      :return: The resulting truncated text