#!/usr/bin/env zsh

function print_color
{
    #local formatted=`printf "%4d " $1`
    local formatted="     "
    print -Pn "%K{$1}${formatted}%k"
}

print -n '        '
for (( i = 0; i < 8; i += 1 )); do
    printf "%4d " $i
done
print
print -n 'Normal: '
for (( i = 0; i < 8; i += 1 )); do
    print_color $i
done
print

print -n '        '
for (( i = 8; i < 16; i += 1 )); do
    printf "%4d " $i
done
print
print -n 'Bright: '
for (( i = 8; i < 16; i += 1 )); do
    print_color $i
done
print

SUPPORTED_COLORS=`echotc Co`
COLORS_PER_LINE=16

print
print "Color Table ($SUPPORTED_COLORS supported colors)"

for (( base = 0; base < $SUPPORTED_COLORS ; base += $COLORS_PER_LINE )); do
    for (( i = base; i < base + $COLORS_PER_LINE && i < $SUPPORTED_COLORS; i += 1 )); do
        printf "%4d " $i
    done

    print

    for (( i = base; i < base + $COLORS_PER_LINE && i < $SUPPORTED_COLORS; i += 1 )); do
        print_color $i
    done
    print
done
