diff options
author | Anton Khirnov <anton@khirnov.net> | 2021-11-28 11:52:43 +0100 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2021-11-28 11:52:43 +0100 |
commit | 857ee2f667349ab4aed69161e080106b4400ce40 (patch) | |
tree | 67887625c35246237502cdef2e94442d9472aa74 | |
parent | 3c63393ea9a33f3641e3242c7b18fd634c1aee04 (diff) |
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).
-rwxr-xr-x | bin/colortable | 33 | ||||
-rwxr-xr-x | bin/colortable.sh | 15 |
2 files changed, 33 insertions, 15 deletions
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 |