<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _truncate(p_str, p_repl):
 """ Place of the truncation is calculated depending on p_max_width. """

    # 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