#!/bin/sh
#
# 256colors - view [-m] arg2 or 256 colors
# dependencies: less

usage() {
  cat <<EOF
Usage: $(basename "$0") [-h|--help] [-b|--bg <num>] [-m|--max <num>]

options:
    -b | --bg  <num>     - Set background to <num>
    -m | --max <num>     - Print <num> columns
EOF
}

unset backg
max=255

while [ "$#" -gt 0 ]; do
  # shellcheck disable=SC2249
  case "$1" in
    -b | --bg)
      backg=$2
      shift
      ;;
    -m | --max)
      max=$2
      shift
      ;;
    -h | --help)
      usage
      exit 0
      ;;
  esac
  shift
done

for i in $(seq 0 "${max}"); do
  # normal font
  tput sgr0
  printf "%4d" "${i}"
  tput setaf "${i}"
  [ -n "${backg}" ] && tput setab "${backg}"
  printf " Hallo "
  tput setab "${i}"
  printf "%10s" ""

  # empty column
  tput sgr0
  printf "%10s" ""

  # bold font
  tput bold
  printf "%4d" "${i}"
  tput setaf "${i}"
  [ -n "${backg}" ] && tput setab "${backg}"
  printf " Hallo "
  tput setab "${i}"
  printf "%10s" ""

  # end of this line
  tput sgr0
  echo
done | less -FX
