Refactor _lp_as_text for speed

Uses 'sed' once instead of 2 ; move building of the sed program from
ruuntime to init time.
This commit is contained in:
Olivier Mengué 2013-12-28 00:29:33 +01:00
parent 5d93b64c6a
commit f4c20b05fc

View File

@ -1477,21 +1477,16 @@ _lp_temperature() {
# DESIGN # # DESIGN #
########## ##########
# Sed expression using extended regexp to remove shell codes around terminal
# escape sequences
_LP_CLEAN_ESC="$(printf "s,%q|%q,,g" "$_LP_OPEN_ESC" "$_LP_CLOSE_ESC")"
# Remove all colors and escape characters of the given string and return a pure text # Remove all colors and escape characters of the given string and return a pure text
_lp_as_text() _lp_as_text()
{ {
# Remove colors from the computed prompt # Remove colors from the computed prompt
local pst echo -n "$1" | sed -$_LP_SED_EXTENDED "s/\x1B\[[0-9;]*[mK]//g;$_LP_CLEAN_ESC"
pst="$(echo "$1" | sed -$_LP_SED_EXTENDED 's/\x1B\[[0-9;]*[mK]//g')"
# Remove escape sequences
# FIXME check the zsh compatibility
# pst=$(echo $pst | sed "s,\\\\\\[\|\\\\\\],,g")
local op="$(printf "%q" "$_LP_OPEN_ESC")"
local cl="$(printf "%q" "$_LP_CLOSE_ESC")"
pst="$(echo "$pst" | sed "s,$op\|$cl,,g")" # replace all open _or_ close tags with nothing
echo -n "$pst"
} }
_lp_title() _lp_title()