code: def _choose_width_fn(has_invisible, enable_widechars, is_multiline):
      
      if has_invisible:
          line_width_fn = _visible_width
      elif enable_widechars:  # optional wide-character support if available
          line_width_fn = wcwidth.wcswidth
      else:
          line_width_fn = len
      if is_multiline:
          def width_fn(s): return _multiline_width(s, line_width_fn)
      else:
          width_fn = line_width_fn
      return width_fn
docs: Return a function to calculate visible cell width.