From eb59a770c36996131b2e3e9661175323112ca732 Mon Sep 17 00:00:00 2001 From: Tony Duckles Date: Sun, 27 Jan 2013 10:26:26 -0600 Subject: [PATCH] bin/colortable: Print a color table of ANSI colors (normal+bright) * Introduce bin/colortable which prints a grid of all the standard ANSI colors for each possible foreground + background combo, including handling for no-background and bright fore+back colors. * Delete bin/colordump because it wasn't a useful 256 color utility and I'm not using any 256 color terminals currently. --- bin/colordump | 19 ------------------- bin/colortable | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 19 deletions(-) delete mode 100755 bin/colordump create mode 100755 bin/colortable diff --git a/bin/colordump b/bin/colordump deleted file mode 100755 index c2661a4..0000000 --- a/bin/colordump +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh -# Usage: colordump -# Dump 256 ansi colors to the terminal. - -printf "How each ANSI color is displayed on your terminal:\n\n" - -i=0 -row=0 -while [ $i -lt 255 ]; -do - newrow=$(expr $i / 10) - test $newrow -ne $row && printf "\n" - row=$newrow - printf "\e[%dm %03d \e[0m" $i $i - i=$(expr $i + 1) -done - -printf '\n\n e.g., "\\e[41mTEXT\\e[0m" ' -printf "\e[41m(for TEXT like this)\e[0m\n" diff --git a/bin/colortable b/bin/colortable new file mode 100755 index 0000000..1c7c453 --- /dev/null +++ b/bin/colortable @@ -0,0 +1,35 @@ +#!/usr/bin/perl +# Usage: colortable +# Print a color table of ANSI colors (normal+bright) + +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"); + } +} + +# No background +for ($bg=0; $bg<=0; $bg++) { + printrow $bg; +} +# Background 40-47 (standard) +for ($bg=40; $bg<48; $bg++) { + printrow $bg; +} -- 2.47.1