#!/bin/bash
#########################################################
#                                                       #
# This is BashStyle-NG                                  #
#                                                       #
# Licensed under GNU GENERAL PUBLIC LICENSE v3          #
#                                                       #
# Copyright Christopher Roy Bratušek                    #
#                                                       #
#########################################################

dbg_msg "$(eval_gettext "BashStyle-NG Setting:")" "$(eval_gettext "colored manpages")" "$(eval_gettext "On")"

# enforce pager to be less, else this does not work
# less is a hard dependency for BashStyle-NG, so it
# must be available, no need for an explicit check
export PAGER="less"

# background colors
lbblack="30m"
lbred="41m"
lbgreen="42m"
lbyellow="43m"
lbblue="44m"
lbmagenta="45m"
lbcyan="46m"
lbgrey="47m"
lbwhite="107m"

# foreground colors
lfblack="30m"
lfred="31m"
lfgreen="32m"
lfyellow="33m"
lfblue="34m"
lfmagenta="35m"
lfcyan="36m"
lfgrey="37m"
lfwhite="97m"

if bt "$(ini_get dark_terminal)"; then
    lfblack=${lfwhite}
    lbblack=${lbwhite}
else    lfwhite=${lfblack}
    lbwhite=${lbblack}
fi

if [[ ${TERM} != *xterm*color* ]]; then
    lfcoldblue=${lfblue}
    lfsmoothblue=${lfblue}
    lficeblue=${lfblue}
    lfturqoise=${lfcyan}
    lfsmoothgreen=${lfgreen}
    lfwinered=${lfred}
    lfbrown=${lfyellow}
    lfsilver=${lfwhite}
    lfocher=${lfyellow}
    lforange=${lfyellow}
    lfpurple=${lfmagenta}
    lfpink=${lfmagenta}
    lfcream=${lfmagenta}
else
    lfcoldblue="38;5;33m"
    lfsmoothgreen="38;5;42m"
    lficeblue="38;5;45m"
    lfturqoise="38;5;50m"
    lfpurple="38;5;92m"
    lfsmoothblue="38;5;111m"
    lfwinered="38;5;125m"
    lfbrown="38;5;130m"
    lfocher="38;5;136m"
    lfpink="38;5;200m"
    lfcream="38;5;218m"
    lforange="38;5;202m"
    lfsilver="38;5;245m"
fi

# standout-mode
eval termcap_sof="$(ini_get less_standout_foreground)"
eval termcap_sob="$(ini_get less_standout_background)"
export LESS_TERMCAP_so=$(echo -e "\033[${termcap_sob}\033[01;${termcap_sof}")

# blinking text
eval termcap_mb="$(ini_get less_blink)"
export LESS_TERMCAP_mb=$(echo -e "\033[01;${termcap_mb}")

# bold text
eval termcap_md="$(ini_get less_bold)"
export LESS_TERMCAP_md=$(echo -e "\033[01;${termcap_md}")

# underline text
eval termcap_us="$(ini_get less_underline)"
export LESS_TERMCAP_us=$(echo -e "\033[04;${termcap_us}")

# reverse text
eval termcap_rs="$(ini_get less_reverse)"
export LESS_TERMCAP_mr=$(echo -e "\033[07;${termcap_rs}")

# dimmed text
eval termcap_mh="$(ini_get less_dim)"
export LESS_TERMCAP_mh=$(echo -e "\033[02;${termcap_mh}")

# stop mode ; stop underline; stop standout
export LESS_TERMCAP_me=$'\033[0m'
export LESS_TERMCAP_se=$'\033[0m'
export LESS_TERMCAP_ue=$'\033[0m'

unset termcap_mb termcap_md termcap_md termcap_mr \
    termcap_mh termcap_us termcap_sof termcap_sob \
    termcap_rs

for lfcolor in "${colors[@]}"; do
    eval unset "lf${lfcolor}"
    eval unset "lb${lfcolor}"
done
