code: def fit_text(text, length):
      
      text_length = wcswidth(text)
  
      if text_length > length:
          return trunc(text, length)
  
      if text_length < length:
          return pad(text, length)
  
      return text
docs: Makes text fit the given length by padding or truncating it.