fix(bash): fix loss of the last output line with enter_accept (#1463)

With a single-line prompt, the last line of the output of the previous
command is overwritten by the prompt on the enter_accept.  In this
situation, `tput cuu` receives 0 as the argument, but `tput cuu 0`
emits the control sequence `\e[0A`, which moves the cursor above by
one line unexpectedly.  This is because the parameter 0 for CUU means
the default value, 1.  In this patch, to avoid moving the cursor when
the prompt offset is 0, we check the offset value before running `tput
cuu`.
This commit is contained in:
Koichi Murase 2023-12-29 04:34:34 +09:00 committed by GitHub
parent d52e576129
commit be1f6fd5ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -29,8 +29,11 @@ __atuin_history() {
then then
HISTORY=${HISTORY#__atuin_accept__:} HISTORY=${HISTORY#__atuin_accept__:}
# Reprint the prompt, accounting for multiple lines # Reprint the prompt, accounting for multiple lines
# shellcheck disable=SC2046 local __atuin_prompt_offset
tput cuu $(echo -n "${PS1@P}" | tr -cd '\n' | wc -c) __atuin_prompt_offset=$(echo -n "${PS1@P}" | tr -cd '\n' | wc -c)
if ((__atuin_prompt_offset > 0)); then
tput cuu "$__atuin_prompt_offset"
fi
echo "${PS1@P}$HISTORY" echo "${PS1@P}$HISTORY"
if [[ -n "${BLE_VERSION-}" ]]; then if [[ -n "${BLE_VERSION-}" ]]; then