colortest: Replace test-color

This commit is contained in:
Salt 2019-06-07 00:40:15 -05:00
parent 89944129d7
commit 719384fe5b
2 changed files with 62 additions and 48 deletions

62
colortest Executable file
View File

@ -0,0 +1,62 @@
#! /bin/bash
#
# colortest.bash
# A script to ricily display a color palette
# Copyright (C) 2019 Vintage Salt <rehashedsalt@cock.li>
#
# Distributed under terms of the MIT license.
#
# Globals
teststring="ABC"
padding=" "
spacer=" "
# Derived globals
teststringlen="$(( $(wc -m <<< "$teststring") - 1 ))"
# $1: Foreground color
# $2: Background color
printc() {
[ -z "$1" ] && return 1
[ -z "$2" ] && return 2
printf "\e[0m\e[$2m\e[$1m$padding$teststring$padding\e[0m"
}
# $1: Heading
printh() {
[ -z "$1" ] && return 1
printf "$padding%${teststringlen}s$padding" "$1"
printf "$spacer"
}
println() {
printf "\\n"
}
# Headers
printf "%8s$spacer"
printh "0m"
for (( bg=40; bg<=47; bg++)); do
printh "${bg}m"
done
println
# Content
for (( fg=30; fg <=37; fg++ )); do
for (( bold=0; bold<=1; bold++ )); do
headerstring="${fg}m"
[ "$bold" == "1" ] && headerstring="$bold;$headerstring"
printf "%8s" "$headerstring"
printf "$spacer"
# No background
printc $fg 0
printf "$spacer"
# All backgrounds
for (( bg=40; bg<=47; bg++)); do
printc $fg $bg
printf "$spacer"
done
println
done
done
println

View File

@ -1,48 +0,0 @@
#!/bin/bash
#
# Description:
#
# Prints a color table of 8bg * 8fg * 2 states (regular/bold)
#
# Copyright:
#
# (C) 2009 Wolfgang Frisch <xororand@unfoog.de>
#
# License:
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
echo
echo Table for 16-color terminal escape sequences.
echo Replace ESC with \\033 in bash.
echo
echo "Background | Foreground colors"
echo "-----------------------------------------------------------------------------"
for((bg=40;bg<=47;bg++)); do
for((bold=0;bold<=1;bold++)) do
echo -en "\033[0m"" ESC[${bg}m | "
for((fg=30;fg<=37;fg++)); do
if [ $bold == "0" ]; then
echo -en "\033[${bg}m\033[${fg}m █[${fg}m "
else
echo -en "\033[${bg}m\033[1;${fg}m █[1;${fg}m"
fi
done
echo -e "\033[0m"
done
echo "----------------------------------------------------------------------------- "
done
echo
echo