From 857ee2f667349ab4aed69161e080106b4400ce40 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sun, 28 Nov 2021 11:52:43 +0100 Subject: bin/colortable.sh: replace by a rewritten python version It is more flexible, allowing to display how all foregrounds look on a given background (and vice versa). --- bin/colortable | 33 +++++++++++++++++++++++++++++++++ bin/colortable.sh | 15 --------------- 2 files changed, 33 insertions(+), 15 deletions(-) create mode 100755 bin/colortable delete mode 100755 bin/colortable.sh diff --git a/bin/colortable b/bin/colortable new file mode 100755 index 0000000..816461e --- /dev/null +++ b/bin/colortable @@ -0,0 +1,33 @@ +#!/usr/bin/python3 + +import sys + +def display(text, fg, bg): + if fg is None: + setfg = '39' + else: + setfg = '38;5;%d' % fg + if bg is None: + setbg = '49' + else: + setbg = '48;5;%d' % bg + + sys.stdout.write('\x1b[%s;%sm %s\t\x1b[0m' % (setfg, setbg, text)) + +default_fg = None +default_bg = None + +if len(sys.argv) >= 2 and sys.argv[1]: + default_fg = int(sys.argv[1]) +if len(sys.argv) >= 3 and sys.argv[2]: + default_bg = int(sys.argv[2]) + +for i in range(256): + display(str(i), i, default_bg) + if ((i + 1) % 16) == 0: + sys.stdout.write('\n') + +for i in range(256): + display(str(i), default_fg, i) + if ((i + 1) % 16) == 0: + sys.stdout.write('\n') diff --git a/bin/colortable.sh b/bin/colortable.sh deleted file mode 100755 index 66ebcc8..0000000 --- a/bin/colortable.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -for fgbg in 38 48 #Foreground/Background -do - for color in {0..255} #Colors - do - #Display the color - echo -en "\e[${fgbg};5;${color}m ${color}\t\e[0m" - #Display 10 colors per lines - if [ $((($color + 1) % 10)) == 0 ] ; then - echo -en '\n' - fi - done - echo -en '\n' -done -- cgit v1.2.3