Perform prompt expansion on strings before computing their length.

This reallows usage of PS1 escape sequences (\u, \w, \W, \h, etc) in plugins.
This commit is contained in:
Ceda EI 2019-12-25 20:22:49 +05:30
parent 136567e08e
commit 919b102a43
1 changed files with 6 additions and 4 deletions

10
wish.sh
View File

@ -73,14 +73,15 @@ function color_to_escape_code() {
function wish_append_left() {
local text="$2"
local colors="$1"
local prompt_text="${text@P}"
if [[ $text == "\n" ]]; then
((WISH_LPLINE++))
WISH_LPL=(${WISH_LPL[@]} 0)
WISH_LEFT_PS1="$WISH_LEFT_PS1$colors$text"
else
if [[ $((${WISH_LPL[$WISH_LPLINE]} + ${#text})) -lt $COLUMNS ]]; then
if [[ $((${WISH_LPL[$WISH_LPLINE]} + ${#prompt_text})) -lt $COLUMNS ]]; then
WISH_LEFT_PS1="$WISH_LEFT_PS1$colors$text"
WISH_LPL[$WISH_LPLINE]=$((${WISH_LPL[$WISH_LPLINE]} + ${#text}))
WISH_LPL[$WISH_LPLINE]=$((${WISH_LPL[$WISH_LPLINE]} + ${#prompt_text}))
fi
fi
}
@ -90,13 +91,14 @@ function wish_append_left() {
function wish_append_right() {
local text="$2"
local colors="$1"
local prompt_text="${text@P}"
if [[ $text == "\n" ]]; then
((WISH_RPLINE++))
WISH_RIGHT_PS1=("${WISH_RIGHT_PS1[@]}" "")
WISH_RPL=(${WISH_RPL[@]} 0)
elif [[ $((${WISH_LPL[$WISH_RPLINE]} + ${WISH_RPL[$WISH_RPLINE]} + ${#text})) -lt $COLUMNS ]]; then
elif [[ $((${WISH_LPL[$WISH_RPLINE]} + ${WISH_RPL[$WISH_RPLINE]} + ${#prompt_text})) -lt $COLUMNS ]]; then
WISH_RIGHT_PS1[$WISH_RPLINE]="${WISH_RIGHT_PS1[$WISH_RPLINE]}$colors$text"
WISH_RPL[$WISH_RPLINE]=$((${WISH_RPL[$WISH_RPLINE]} + ${#text}))
WISH_RPL[$WISH_RPLINE]=$((${WISH_RPL[$WISH_RPLINE]} + ${#prompt_text}))
fi
}