Refactor config loading: step 4

Move colors definitions inside _lp_source_config.
(The important part of the diff is that the beginning of the
_lp_source_config function is moving up).
This commit is contained in:
Olivier Mengué 2012-08-21 07:14:00 +02:00
parent 35cc6109fd
commit 5ee2b74f10

View File

@ -77,56 +77,6 @@ case $(uname) in
*) LP_OS=Linux ;;
esac
# Colors declarations
# TermInfo feature detection
_lp_ti_sgr0="$( { tput sgr0 || tput me ; } 2>/dev/null )"
_lp_ti_bold="$( { tput bold || tput md ; } 2>/dev/null )"
if tput setaf >/dev/null 2>&1 ; then
_lp_ti_setaf () { tput setaf "$1" ; }
elif tput AF >/dev/null 2>&1 ; then
# *BSD
_lp_ti_setaf () { tput AF "$1" ; }
else
echo "liquidprompt: terminal $TERM not supported" >&2
_lp_ti_setaf () { : ; }
fi
# Colors
{
BOLD="${_LP_OPEN_ESC}${_lp_ti_bold}${_LP_CLOSE_ESC}"
BLACK="${_LP_OPEN_ESC}$(_lp_ti_setaf 0)${_LP_CLOSE_ESC}"
BOLD_GRAY="${_LP_OPEN_ESC}${_lp_ti_bold}$(_lp_ti_setaf 0)${_LP_CLOSE_ESC}"
WHITE="${_LP_OPEN_ESC}$(_lp_ti_setaf 7)${_LP_CLOSE_ESC}"
BOLD_WHITE="${_LP_OPEN_ESC}${_lp_ti_bold}$(_lp_ti_setaf 7)${_LP_CLOSE_ESC}"
RED="${_LP_OPEN_ESC}$(_lp_ti_setaf 1)${_LP_CLOSE_ESC}"
BOLD_RED="${_LP_OPEN_ESC}${_lp_ti_bold}$(_lp_ti_setaf 1)${_LP_CLOSE_ESC}"
WARN_RED="${_LP_OPEN_ESC}$(_lp_ti_setaf 0 ; tput setab 1)${_LP_CLOSE_ESC}"
CRIT_RED="${_LP_OPEN_ESC}${_lp_ti_bold}$(_lp_ti_setaf 7 ; tput setab 1)${_LP_CLOSE_ESC}"
DANGER_RED="${_LP_OPEN_ESC}${_lp_ti_bold}$(_lp_ti_setaf 3 ; tput setab 1)${_LP_CLOSE_ESC}"
GREEN="${_LP_OPEN_ESC}$(_lp_ti_setaf 2)${_LP_CLOSE_ESC}"
BOLD_GREEN="${_LP_OPEN_ESC}${_lp_ti_bold}$(_lp_ti_setaf 2)${_LP_CLOSE_ESC}"
YELLOW="${_LP_OPEN_ESC}$(_lp_ti_setaf 3)${_LP_CLOSE_ESC}"
BOLD_YELLOW="${_LP_OPEN_ESC}${_lp_ti_bold}$(_lp_ti_setaf 3)${_LP_CLOSE_ESC}"
BLUE="${_LP_OPEN_ESC}$(_lp_ti_setaf 4)${_LP_CLOSE_ESC}"
BOLD_BLUE="${_LP_OPEN_ESC}${_lp_ti_bold}$(_lp_ti_setaf 4)${_LP_CLOSE_ESC}"
PURPLE="${_LP_OPEN_ESC}$(_lp_ti_setaf 5)${_LP_CLOSE_ESC}"
PINK="${_LP_OPEN_ESC}${_lp_ti_bold}$(_lp_ti_setaf 5)${_LP_CLOSE_ESC}"
CYAN="${_LP_OPEN_ESC}$(_lp_ti_setaf 6)${_LP_CLOSE_ESC}"
BOLD_CYAN="${_LP_OPEN_ESC}${_lp_ti_bold}$(_lp_ti_setaf 6)${_LP_CLOSE_ESC}"
NO_COL="${_LP_OPEN_ESC}${_lp_ti_sgr0}${_LP_CLOSE_ESC}"
unset _lp_ti_sgr0 _lp_ti_bold _lp_ti_setaf
}
# Get cpu count
case "$LP_OS" in
@ -167,6 +117,59 @@ esac
_lp_source_config()
{
# Colors declarations
local BOLD BLACK BOLD_GRAY WHITE BOLD_WHITE \
RED BOLD_RED WARN_RED CRIT_RED DANGER_RED \
GREEN BOLD_GREEN YELLOW BOLD_YELLOW \
BLUE BOLD_BLUE PURPLE PINK CYAN BOLD_CYAN
# TermInfo feature detection
_lp_ti_sgr0="$( { tput sgr0 || tput me ; } 2>/dev/null )"
_lp_ti_bold="$( { tput bold || tput md ; } 2>/dev/null )"
if tput setaf >/dev/null 2>&1 ; then
_lp_ti_setaf () { tput setaf "$1" ; }
elif tput AF >/dev/null 2>&1 ; then
# *BSD
_lp_ti_setaf () { tput AF "$1" ; }
else
echo "liquidprompt: terminal $TERM not supported" >&2
_lp_ti_setaf () { : ; }
fi
# Colors
BOLD="${_LP_OPEN_ESC}${_lp_ti_bold}${_LP_CLOSE_ESC}"
BLACK="${_LP_OPEN_ESC}$(_lp_ti_setaf 0)${_LP_CLOSE_ESC}"
BOLD_GRAY="${_LP_OPEN_ESC}${_lp_ti_bold}$(_lp_ti_setaf 0)${_LP_CLOSE_ESC}"
WHITE="${_LP_OPEN_ESC}$(_lp_ti_setaf 7)${_LP_CLOSE_ESC}"
BOLD_WHITE="${_LP_OPEN_ESC}${_lp_ti_bold}$(_lp_ti_setaf 7)${_LP_CLOSE_ESC}"
RED="${_LP_OPEN_ESC}$(_lp_ti_setaf 1)${_LP_CLOSE_ESC}"
BOLD_RED="${_LP_OPEN_ESC}${_lp_ti_bold}$(_lp_ti_setaf 1)${_LP_CLOSE_ESC}"
WARN_RED="${_LP_OPEN_ESC}$(_lp_ti_setaf 0 ; tput setab 1)${_LP_CLOSE_ESC}"
CRIT_RED="${_LP_OPEN_ESC}${_lp_ti_bold}$(_lp_ti_setaf 7 ; tput setab 1)${_LP_CLOSE_ESC}"
DANGER_RED="${_LP_OPEN_ESC}${_lp_ti_bold}$(_lp_ti_setaf 3 ; tput setab 1)${_LP_CLOSE_ESC}"
GREEN="${_LP_OPEN_ESC}$(_lp_ti_setaf 2)${_LP_CLOSE_ESC}"
BOLD_GREEN="${_LP_OPEN_ESC}${_lp_ti_bold}$(_lp_ti_setaf 2)${_LP_CLOSE_ESC}"
YELLOW="${_LP_OPEN_ESC}$(_lp_ti_setaf 3)${_LP_CLOSE_ESC}"
BOLD_YELLOW="${_LP_OPEN_ESC}${_lp_ti_bold}$(_lp_ti_setaf 3)${_LP_CLOSE_ESC}"
BLUE="${_LP_OPEN_ESC}$(_lp_ti_setaf 4)${_LP_CLOSE_ESC}"
BOLD_BLUE="${_LP_OPEN_ESC}${_lp_ti_bold}$(_lp_ti_setaf 4)${_LP_CLOSE_ESC}"
PURPLE="${_LP_OPEN_ESC}$(_lp_ti_setaf 5)${_LP_CLOSE_ESC}"
PINK="${_LP_OPEN_ESC}${_lp_ti_bold}$(_lp_ti_setaf 5)${_LP_CLOSE_ESC}"
CYAN="${_LP_OPEN_ESC}$(_lp_ti_setaf 6)${_LP_CLOSE_ESC}"
BOLD_CYAN="${_LP_OPEN_ESC}${_lp_ti_bold}$(_lp_ti_setaf 6)${_LP_CLOSE_ESC}"
# NO_COL is special: it will be used at runtime, not just during config loading
NO_COL="${_LP_OPEN_ESC}${_lp_ti_sgr0}${_LP_CLOSE_ESC}"
unset _lp_ti_sgr0 _lp_ti_bold _lp_ti_setaf
# Note: configuration is called _after_ colors declarations, because of themes.
# Default values
@ -267,11 +270,6 @@ _lp_source_config
[[ "$LP_ENABLE_HG" = 1 ]] && { command -v hg >/dev/null || LP_ENABLE_HG=0 ; }
[[ "$LP_ENABLE_BATT" = 1 ]] && { command -v acpi >/dev/null || LP_ENABLE_BATT=0 ; }
# Unset colors
unset BOLD BLACK BOLD_GRAY WHITE BOLD_WHITE \
RED BOLD_RED WARN_RED CRIT_RED DANGER_RED \
GREEN BOLD_GREEN YELLOW BOLD_YELLOW \
BLUE BOLD_BLUE PURPLE PINK CYAN BOLD_CYAN
###############