Created
December 19, 2014 03:02
-
-
Save flyinghyrax/873a4a1e4d17b531348a to your computer and use it in GitHub Desktop.
Cleaned up version of random terminal color test script from the interwebz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Copyright (C) 2006 by Johannes Zellner, <[email protected]> | |
# modified by [email protected] to fit my output needs | |
# modified by [email protected] to fit my output needs | |
# modified by [email protected] (2014) | |
# - use if __name__ == "__main__" to run script stand-alone | |
# - organize and define more reusable functions (could be more idiomatic) | |
import sys | |
import os | |
def echo(msg): | |
os.system('echo -n "' + str(msg) + '"') | |
def out(n): | |
os.system("tput setab " + str(n) + "; echo -n " + ("\"% 4d\"" % n)) | |
os.system("tput setab 0") | |
def print_16(): | |
print_color_range(0, 15, 8) | |
echo("\n") | |
def print_231(): | |
print_color_range(16, 231) | |
echo("\n") | |
def print_grayscale(): | |
print_color_range(232, 255) | |
echo("\n") | |
def print_color_range(lo, hi, line_len=6): | |
n = lo | |
while n <= hi: | |
i = 0 | |
while i < line_len and n <= hi: | |
out(n) | |
i += 1 | |
n += 1 | |
echo("\n") | |
def print_colors(): | |
os.system("tput setaf 16") | |
print_16() | |
print_231() | |
print_grayscale() | |
os.system("tput setaf 7") | |
os.system("tput setab 0") | |
if __name__ == "__main__": | |
print_colors() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment