8000 fix(bash/preexec): support termcap names for tput by akinomyoga · Pull Request #1670 · atuinsh/atuin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix(bash/preexec): support termcap names for tput #1670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions atuin/src/shell/atuin.bash
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,35 @@ else
}
fi

# The shell function `__atuin_clear_prompt N` outputs terminal control
# sequences to clear the contents of the current and N previous lines. After
# clearing, the cursor is placed at the beginning of the N-th previous line.
__atuin_clear_prompt_cache=()
__atuin_clear_prompt() {
local offset=$1
if [[ ! ${__atuin_clear_prompt_cache[offset]+set} ]]; t 8000 hen
if [[ ! ${__atuin_clear_prompt_cache[0]+set} ]]; then
__atuin_clear_prompt_cache[0]=$'\r'$(tput el 2>/dev/null || tput ce 2>/dev/null)
fi
if ((offset > 0)); then
__atuin_clear_prompt_cache[offset]=${__atuin_clear_prompt_cache[0]}$(
tput cuu "$offset" 2>/dev/null || tput UP "$offset" 2>/dev/null
tput dl "$offset" 2>/dev/null || tput DL "$offset" 2>/dev/null
tput il "$offset" 2>/dev/null || tput AL "$offset" 2>/dev/null
)
fi
fi
printf '%s' "${__atuin_clear_prompt_cache[offset]}"
}

__atuin_accept_line() {
local __atuin_command=$1

# 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
__atuin_clear_prompt+=$(
tput cuu "$__atuin_prompt_offset"
tput dl "$__atuin_prompt_offset"
tput il "$__atuin_prompt_offset"
)
fi
printf '%s\n' "$__atuin_clear_prompt$__atuin_prompt$__atuin_command"
__atuin_clear_prompt "$__atuin_prompt_offset"
printf '%s\n' "$__atuin_prompt$__atuin_command"

# Add it to the bash history
history -s "$__atuin_command"
Expand Down Expand Up @@ -164,7 +177,8 @@ __atuin_accept_line() {
# so to work for a multiline prompt we need to print it ourselves,
# then go to the beginning of the last line.
__atuin_evaluate_prompt
printf '%s\r%s' "$__atuin_prompt" "$(tput el)"
printf '%s' "$__atuin_prompt"
__atuin_clear_prompt 0
}

__atuin_history() {
Expand Down
0