Better colour codes

This commit is contained in:
cs127 2023-03-13 18:00:04 +03:30
parent dcff08340e
commit 4d6743b886
6 changed files with 51 additions and 30 deletions

View file

@ -38,7 +38,7 @@ shopt -s eval_unsafe_arith &>/dev/null
sys_locale=${LANG:-C}
XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-${HOME}/.config}
PATH=$PATH:/usr/xpg4/bin:/usr/sbin:/sbin:/usr/etc:/usr/libexec
reset='\e[0m'
reset='\e[39;22m'
shopt -s nocasematch extglob
# Speed up script by not using unicode.
@ -4805,16 +4805,19 @@ get_cols() {
esac
done
# Workaround for bright background colors in the Linux framebuffer console.
(( block_range[1] < 16 )) && printf -v blocks2 '\e[5m%b\e[25m' "$blocks2"
# Convert height into spaces.
printf -v block_spaces "%${block_height}s"
# Convert the spaces into rows of blocks.
if [[ $BASH_VERSION == 3* ]]; then
[[ "$blocks" ]] && cols+="${block_spaces// /${blocks}nl}"
[[ "$blocks2" ]] && cols+="${block_spaces// /${blocks2}nl}"
[[ "$blocks" ]] && cols+="${block_spaces// /${blocks}nl}"
[[ "$blocks2" ]] && cols+="${block_spaces// /${blocks2}nl}"
else
[[ "$blocks" ]] && cols+="${block_spaces// /${blocks}\[mnl}"
[[ "$blocks2" ]] && cols+="${block_spaces// /${blocks2}\[mnl}"
[[ "$blocks" ]] && cols+="${block_spaces// /${blocks}\[39;49mnl}"
[[ "$blocks2" ]] && cols+="${block_spaces// /${blocks2}\[39;49mnl}"
fi
# Determine the horizontal offset of the blocks.
@ -5529,12 +5532,8 @@ trim_quotes() {
}
strip_sequences() {
strip="${1//$'\e['3[0-9]m}"
strip="${strip//$'\e['[0-9]m}"
strip="${strip//\\e\[[0-9]m}"
strip="${strip//$'\e['38\;5\;[0-9]m}"
strip="${strip//$'\e['38\;5\;[0-9][0-9]m}"
strip="${strip//$'\e['38\;5\;[0-9][0-9][0-9]m}"
strip="${1//$'\e'\[*([0-9])*(;*([0-9]))m}"
strip="${strip//\\e\[*([0-9])*(;*([0-9]))m}"
printf '%s\n' "$strip"
}
@ -5593,8 +5592,8 @@ set_text_colors() {
color() {
case $1 in
[0-6]) printf '%b\e[3%sm' "$reset" "$1" ;;
7 | "fg") printf '\e[37m%b' "$reset" ;;
[0-7]) printf '%b\e[3%sm' "$reset" "$1" ;;
"fg") printf '%b' "$reset" ;;
"#"*)
local rgb="${1//#}"
rgb="$((0x$rgb))"