From f65a7cc38905ad74c0d398cd165b7454f00d4b2d Mon Sep 17 00:00:00 2001 From: Hugues Hiegel Date: Thu, 14 Jun 2012 12:15:10 +0200 Subject: [Funcs] Internals / ZLE Widgets cleanup --- 01_Internal.zsh | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to '01_Internal.zsh') diff --git a/01_Internal.zsh b/01_Internal.zsh index 01cf713..a50fa6f 100644 --- a/01_Internal.zsh +++ b/01_Internal.zsh @@ -342,4 +342,70 @@ __privileged_user () ! __normal_user } +__expand_text() +{ + # Strips unprintable characters + print -Pn -- "$(echo $@ | sed 's/\r.*//g;s/%{[^(%})]*%}//g;s/'$T_'//g;s/'$_T'//g')" +} + +export _COLUMNS_OLD=0 +__hbar() +{ + if [ $COLUMNS != $_COLUMNS_OLD ] + then + __debug -n " Horizontal bar..." + _COLUMNS_OLD=$COLUMNS + unset HBAR + HBAR=$C_$_prompt_colors[bar]$_C$T_ + for h in {1..$COLUMNS} + do + HBAR=${HBAR}$_tq_ + done + HBAR=$HBAR$_T + __debug + fi +} + +__get_prompt_lines() +{ + local lines + lines=$( (__expand_text "$PS1 $@" ) | sed "s/\\(.\{,$COLUMNS\}\\)/\\1\n/g" ) + lines=$( echo "$lines" | sed -n '/^$/n;p' | wc -l ) + # Got number of empty lines at end of command, because they are screwed up above... + lines=$(( $lines + $( echo -n "$@" | tr ';\n' '.;' | sed 's/^\(.*[^;]\)\(;*\)$/\2/' | wc -c ) )) + + echo $lines +} + +# Rewrites current prompt. +__redisplay_ps1 () +{ + tput sc + up_up - 1 + __redefine_prompt + + print -Pn "$PS1" + tput rc +} +zle -N __redisplay_ps1 + +__clear () +{ + tput clear + [ -n "$1" ] && tput cup $1 +} + +up_up () +{ + for i in {1..$(($(__get_prompt_lines) $@ ))} + tput cuu1 + print -Pn '\r' +} + +_rehash () +{ + builtin rehash + __redisplay_ps1 +} +zle -N _rehash -- cgit v1.2.3