From 6d4e9ce8a8d212d3255fc24117e02b40087eb5c7 Mon Sep 17 00:00:00 2001 From: Tony Duckles Date: Tue, 29 Jan 2013 22:03:16 -0600 Subject: [PATCH] bin/colortable: Rewrite in bash, columns for background colors --- bin/colortable | 79 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 47 insertions(+), 32 deletions(-) diff --git a/bin/colortable b/bin/colortable index 1c7c453..718ef1e 100755 --- a/bin/colortable +++ b/bin/colortable @@ -1,35 +1,50 @@ -#!/usr/bin/perl +#!/bin/bash # Usage: colortable -# Print a color table of ANSI colors (normal+bright) +# +# Print a color table of ANSI colors (normal+bright) to demonstrate what +# colors are available. Each line is the color code of one foreground +# color, out of 17 (default + 16 escapes), followed by a test use of that +# color on all nine background colors (default + 8 escapes). +# +# (Based on: http://www.faqs.org/docs/Linux-HOWTO/Bash-Prompt-HOWTO.html) -sub printrow { - $bg = $_[0]; - for ($bright = 0; $bright < 2; $bright++) { - # Normal background - $bgc = $bg; - printf("\x1b[0m %2s ",$bgc); - for ($fg=30; $fg<=37; $fg++) { - $fgc = $bright == 1 ? ($fg+60) : $fg; - printf("\x1b[%sm\x1b[%sm %2s ", $bgc, $fgc, $fgc); - } - if ($bg > 0) { - # Bright background - $bgc = $bg+60; - printf("\x1b[0m %3s ",$bgc); - for ($fg=30; $fg<=37; $fg++) { - $fgc = $bright == 1 ? ($fg+60) : $fg; - printf("\x1b[%sm\x1b[%sm %2s ", $bgc, $fgc, $fgc); - } - } - printf("\x1b[0m\n"); - } -} +T='gYw' # The test text -# No background -for ($bg=0; $bg<=0; $bg++) { - printrow $bg; -} -# Background 40-47 (standard) -for ($bg=40; $bg<48; $bg++) { - printrow $bg; -} +# Standard background colors +echo -e "\n 40m 41m 42m 43m 44m 45m 46m 47m"; +for FGs in ' m' ' 1m' \ + ' 30m' ' 90m' '1;30m' \ + ' 31m' ' 91m' '1;31m' \ + ' 32m' ' 92m' '1;32m' \ + ' 33m' ' 93m' '1;33m' \ + ' 34m' ' 94m' '1;34m' \ + ' 35m' ' 95m' '1;35m' \ + ' 36m' ' 96m' '1;36m' \ + ' 37m' ' 97m' '1;37m'; do + FG=${FGs// /} + echo -en " $FGs \033[$FG $T \033[0m" + for BG in 40m 41m 42m 43m 44m 45m 46m 47m; do + echo -en " \033[$FG\033[$BG $T \033[0m"; + done + echo; +done + +# Bright background colors +echo -e "\n 100m 101m 102m 103m 104m 105m 106m 107m"; +for FGs in ' m' ' 1m' \ + ' 30m' ' 90m' '1;30m' \ + ' 31m' ' 91m' '1;31m' \ + ' 32m' ' 92m' '1;32m' \ + ' 33m' ' 93m' '1;33m' \ + ' 34m' ' 94m' '1;34m' \ + ' 35m' ' 95m' '1;35m' \ + ' 36m' ' 96m' '1;36m' \ + ' 37m' ' 97m' '1;37m'; do + FG=${FGs// /} + echo -en " $FGs \033[$FG $T \033[0m" + for BG in 100m 101m 102m 103m 104m 105m 106m 107m; do + echo -en " \033[$FG\033[$BG $T \033[0m"; + done + echo; +done +echo -- 2.45.2