lib/colors: revert #99
This reverts bash-it/bash-it#99, a metaprogramming adventure in terminal color code escape computation. It was functionally reverted in bash-it/bash-it#699; I'm just finishing the job.pull/2019/head^2
parent
2a8d8ba540
commit
16cee1956d
|
|
@ -80,6 +80,7 @@ completion/available/vuejs.completion.bash
|
|||
completion/available/wpscan.completion.bash
|
||||
|
||||
# libraries
|
||||
lib/colors.bash
|
||||
lib/helpers.bash
|
||||
lib/log.bash
|
||||
lib/preexec.bash
|
||||
|
|
|
|||
185
lib/colors.bash
185
lib/colors.bash
|
|
@ -1,188 +1,7 @@
|
|||
# shellcheck shell=bash
|
||||
# shellcheck disable=SC2005
|
||||
# shellcheck disable=SC2034
|
||||
|
||||
function __ {
|
||||
echo "$@"
|
||||
}
|
||||
|
||||
function __make_ansi {
|
||||
next=$1; shift
|
||||
echo "\[\e[$(__$next $@)m\]"
|
||||
}
|
||||
|
||||
function __make_echo {
|
||||
next=$1; shift
|
||||
echo "\033[$(__$next $@)m"
|
||||
}
|
||||
|
||||
|
||||
function __reset {
|
||||
next=$1; shift
|
||||
out="$(__$next $@)"
|
||||
echo "0${out:+;${out}}"
|
||||
}
|
||||
|
||||
function __bold {
|
||||
next=$1; shift
|
||||
out="$(__$next $@)"
|
||||
echo "${out:+${out};}1"
|
||||
}
|
||||
|
||||
function __faint {
|
||||
next=$1; shift
|
||||
out="$(__$next $@)"
|
||||
echo "${out:+${out};}2"
|
||||
}
|
||||
|
||||
function __italic {
|
||||
next=$1; shift
|
||||
out="$(__$next $@)"
|
||||
echo "${out:+${out};}3"
|
||||
}
|
||||
|
||||
function __underline {
|
||||
next=$1; shift
|
||||
out="$(__$next $@)"
|
||||
echo "${out:+${out};}4"
|
||||
}
|
||||
|
||||
function __negative {
|
||||
next=$1; shift
|
||||
out="$(__$next $@)"
|
||||
echo "${out:+${out};}7"
|
||||
}
|
||||
|
||||
function __crossed {
|
||||
next=$1; shift
|
||||
out="$(__$next $@)"
|
||||
echo "${out:+${out};}8"
|
||||
}
|
||||
|
||||
|
||||
function __color_normal_fg {
|
||||
echo "3$1"
|
||||
}
|
||||
|
||||
function __color_normal_bg {
|
||||
echo "4$1"
|
||||
}
|
||||
|
||||
function __color_bright_fg {
|
||||
echo "9$1"
|
||||
}
|
||||
|
||||
function __color_bright_bg {
|
||||
echo "10$1"
|
||||
}
|
||||
|
||||
|
||||
function __color_black {
|
||||
echo "0"
|
||||
}
|
||||
|
||||
function __color_red {
|
||||
echo "1"
|
||||
}
|
||||
|
||||
function __color_green {
|
||||
echo "2"
|
||||
}
|
||||
|
||||
function __color_yellow {
|
||||
echo "3"
|
||||
}
|
||||
|
||||
function __color_blue {
|
||||
echo "4"
|
||||
}
|
||||
|
||||
function __color_magenta {
|
||||
echo "5"
|
||||
}
|
||||
|
||||
function __color_cyan {
|
||||
echo "6"
|
||||
}
|
||||
|
||||
function __color_white {
|
||||
echo "7"
|
||||
}
|
||||
|
||||
function __color_rgb {
|
||||
r=$1 && g=$2 && b=$3
|
||||
[[ $r == $g && $g == $b ]] && echo $(( $r / 11 + 232 )) && return # gray range above 232
|
||||
echo "8;5;$(( ($r * 36 + $b * 6 + $g) / 51 + 16 ))"
|
||||
}
|
||||
|
||||
function __color {
|
||||
color=$1; shift
|
||||
case "$1" in
|
||||
fg|bg) side="$1"; shift ;;
|
||||
*) side=fg;;
|
||||
esac
|
||||
case "$1" in
|
||||
normal|bright) mode="$1"; shift;;
|
||||
*) mode=normal;;
|
||||
esac
|
||||
[[ $color == "rgb" ]] && rgb="$1 $2 $3"; shift 3
|
||||
|
||||
next=$1; shift
|
||||
out="$(__$next $@)"
|
||||
echo "$(__color_${mode}_${side} $(__color_${color} $rgb))${out:+;${out}}"
|
||||
}
|
||||
|
||||
|
||||
function __black {
|
||||
echo "$(__color black $@)"
|
||||
}
|
||||
|
||||
function __red {
|
||||
echo "$(__color red $@)"
|
||||
}
|
||||
|
||||
function __green {
|
||||
echo "$(__color green $@)"
|
||||
}
|
||||
|
||||
function __yellow {
|
||||
echo "$(__color yellow $@)"
|
||||
}
|
||||
|
||||
function __blue {
|
||||
echo "$(__color blue $@)"
|
||||
}
|
||||
|
||||
function __magenta {
|
||||
echo "$(__color magenta $@)"
|
||||
}
|
||||
|
||||
function __cyan {
|
||||
echo "$(__color cyan $@)"
|
||||
}
|
||||
|
||||
function __white {
|
||||
echo "$(__color white $@)"
|
||||
}
|
||||
|
||||
function __rgb {
|
||||
echo "$(__color rgb $@)"
|
||||
}
|
||||
|
||||
|
||||
function __color_parse {
|
||||
next=$1; shift
|
||||
echo "$(__$next $@)"
|
||||
}
|
||||
|
||||
function color {
|
||||
echo "$(__color_parse make_ansi $@)"
|
||||
}
|
||||
|
||||
function echo_color {
|
||||
echo "$(__color_parse make_echo $@)"
|
||||
}
|
||||
|
||||
#
|
||||
# A set of pre-defined color escape codes for use in prompts and with `echo`.
|
||||
|
||||
black="\[\e[0;30m\]"
|
||||
red="\[\e[0;31m\]"
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
load ../test_helper
|
||||
load ../test_helper_libs
|
||||
load ../../plugins/available/base.plugin
|
||||
load ../../themes/colors.theme
|
||||
load ../../lib/colors
|
||||
|
||||
function local_setup {
|
||||
setup_test_fixture
|
||||
|
|
|
|||
Loading…
Reference in New Issue