62 lines
1.1 KiB
Bash
Executable File
62 lines
1.1 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="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$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=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
|
|
|