fix(bash/preexec): erase the previous prompt before overwriting

When the previous prompt is longer than the prompt calculated by the
current PS1, some extra characters from the previous prompt remains in
the terminal display.  In this patch, we erase the content of the
previous prompt before outputting our new prompt.
This commit is contained in:
Koichi Murase 2024-02-04 02:43:56 +09:00 committed by Ellie Huxtable
parent b00887562b
commit 9c210e8987

View File

@ -106,10 +106,16 @@ __atuin_accept_line() {
# Reprint the prompt, accounting for multiple lines
local __atuin_prompt __atuin_prompt_offset
__atuin_evaluate_prompt
local __atuin_clear_prompt
__atuin_clear_prompt=$'\r'$(tput el)
if ((__atuin_prompt_offset > 0)); then
tput cuu "$__atuin_prompt_offset"
__atuin_clear_prompt+=$(
tput cuu "$__atuin_prompt_offset"
tput dl "$__atuin_prompt_offset"
tput il "$__atuin_prompt_offset"
)
fi
printf '%s\n' "$__atuin_prompt$__atuin_command"
printf '%s\n' "$__atuin_clear_prompt$__atuin_prompt$__atuin_command"
# Add it to the bash history
history -s "$__atuin_command"