bin/colortest

59 lines
1.0 KiB
Bash
Executable File

#! /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="•••"
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$spacer" "$1"
}
println() {
printf "\\n"
}
# Headers
printf "%8s$spacer"
printh "0m"
for (( bg=40; bg<=47; bg++)); do
printh "${bg}m"
done
println
# Content
for fg in $(seq 30 1 37) "" $(seq 90 1 97); do
[ -z "$fg" ] && println && continue
headerstring="${fg}m"
printf "%8s$spacer" "$headerstring"
# No background
printc $fg 0
printf "$spacer"
# All backgrounds
for (( bg=40; bg<=47; bg++)); do
printc $fg $bg
printf "$spacer"
done
println
done
println