diff options
author | Koichi Murase <myoga.murase@gmail.com> | 2023-12-29 04:34:34 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-28 19:34:34 +0000 |
commit | be1f6fd5ca718f725a840f764f387ccf4acf8a9f (patch) | |
tree | 34e7a6b68bc058e3fea0f2f58d84abb6868b8998 | |
parent | d52e57612942cbe0c6a0dd774fcc2caac8f439d5 (diff) |
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`.
-rw-r--r-- | atuin/src/shell/atuin.bash | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/atuin/src/shell/atuin.bash b/atuin/src/shell/atuin.bash index bd9506e5..d04f1d9e 100644 --- a/atuin/src/shell/atuin.bash +++ b/atuin/src/shell/atuin.bash @@ -29,8 +29,11 @@ __atuin_history() { then HISTORY=${HISTORY#__atuin_accept__:} # Reprint the prompt, accounting for multiple lines - # shellcheck disable=SC2046 - tput cuu $(echo -n "${PS1@P}" | tr -cd '\n' | wc -c) + local __atuin_prompt_offset + __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" if [[ -n "${BLE_VERSION-}" ]]; then |