code: def _truncate(p_str, p_repl):
      
      # 4 is for '...' and an extra space at the end
      text_lim = _columns() - len(escape_ansi(p_str)) - 4
      truncated_str = re.sub(re.escape(p_repl), p_repl[:text_lim] + '...', p_str)
  
      return truncated_str
docs: Returns p_str with truncated and ended with '...' version of p_repl.
  
      Place of the truncation is calculated depending on p_max_width.