#!/usr/bin/env bash
#
# pcolors - print terminals active colors

# make size of the blocks dependent on the width of terminal
columns="$(tput cols)"
if [ "${columns}" -gt 90 ]; then
  # 9
  space='         '
elif [ "${columns}" -gt 80 ]; then
  # 6
  space='      '
else
  # 3
  space='   '
fi

printf '%b\n' "\n"

# run through 16 colors - create two rows
for i in $(seq 0 15); do
  printf '%b' "\033[48;5;${i}m${space}\033[m "
  if [ "${i}" = 7 ]; then
    echo '' && continue
  fi
done

printf '%b\n' "\n"
