Skip to content

Commit d4058ac

Browse files
initial commit
0 parents  commit d4058ac

File tree

4 files changed

+124
-0
lines changed

4 files changed

+124
-0
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
include
2+
lib
3+
share
4+
lib64
5+
bin
6+
pyvenv.cfg
7+
*.swp

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# python_colors

colortest.py

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#!/c/Users/david/OneDrive/Documents/localServer/python_colors/bin/python3
2+
''' Resources
3+
4+
* https://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html
5+
* https://askubuntu.com/questions/821157/print-a-256-color-test-pattern-in-the-terminal
6+
'''
7+
8+
9+
# Python colors
10+
import sys
11+
import argparse
12+
13+
# Dull Colors
14+
def dullForegroundColors():
15+
print("Standard (Dull) Colors")
16+
for i in range(30, 38):
17+
print('\033[{}m {} \033[0m \\033[{}m'.format(i, i, i))
18+
19+
# Bright Colors
20+
def brightForegroundColors():
21+
print("Bright Colors")
22+
for i in range (30, 38):
23+
print('\033[{};1m {} \033[0m \\033[{};1m'.format(i, i, i,))
24+
25+
# 256 Color range
26+
def allForegroundColors():
27+
print("All 256 Colors")
28+
for i in range(0, 257):
29+
num = str(i)
30+
color = f'\033[38;5;{num}m {num} \033[0m \\033[38;5;{num}m'
31+
sys.stdout.write(color.ljust(4))
32+
if i % 5 == 0 and i != 0:
33+
print('')
34+
35+
# Background Dull Colors
36+
def dullBackgroundColors():
37+
print("Background Dull Colors")
38+
for i in range(40, 48):
39+
print(f'\033[{i}m {i} \033[0m \\033[{i}m')
40+
41+
# Background Bright Colors
42+
def brightBackgroundColors():
43+
print("Background Bright Colors")
44+
for i in range(40, 48):
45+
print(f'\033[{i};1m {i} \033[0m \\033[{i};1m')
46+
47+
# Background 256 Colors
48+
def allBackgroundColors():
49+
print("All 256 Color Backgrounds")
50+
for i in range(0, 257):
51+
num = str(i)
52+
color = f'\033[48;5;{num}m {num} \033[0m \\033[48;5;{num}m'
53+
sys.stdout.write(color.ljust(4))
54+
if i % 5 == 0 and i != 0:
55+
print('')
56+
57+
# Getting Crazy with it
58+
def allForegroundAllBackground():
59+
for i in range(0, 257):
60+
for j in range(0, 257):
61+
foreground = str(j)
62+
background = str(i)
63+
color = f'\033[38;5;{foreground}m\033[48;5;{background}m {foreground} on {background}\033[0m '
64+
sys.stdout.write(color.ljust(4))
65+
if j % 16 == 0 and j != 0:
66+
print('')
67+
68+
# Test out a foreground on a background
69+
def testForegroundOnBackground(foreground, background):
70+
if foreground and background in range(0, 257):
71+
print(f'Testing {foreground} on {background}')
72+
print(f'\n\\033[38;5;{foreground}m\\033[48;5;{background}m TEXT HERE \\033[0m\n')
73+
print(f'\033[38;5;{foreground}m\033[48;5;{background}m{foreground} on {background} test\033[0m')
74+
print(f'\033[38;5;{foreground}m\033[48;5;{background}mThe quick brown fox jumps over the lazy dog. \033[0m')
75+
print(f'\033[38;5;{foreground}m\033[48;5;{background}mABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789\033[0m')
76+
77+
# Print out all 256 foreground and background
78+
def allForegroundAndAllBackground():
79+
allForegroundColors()
80+
allBackgroundColors()
81+
82+
83+
parser = argparse.ArgumentParser()
84+
subparsers = parser.add_subparsers(title='commands', dest='command')
85+
86+
dullForegroundColorsParser = subparsers.add_parser('dullForegroundColors', help='display the 8 dull foreground colors')
87+
brightForegroundColorsParser = subparsers.add_parser('brightForegroundColors', help='display the 8 bright foreground colors')
88+
dullBackgroundColorsParser = subparsers.add_parser('dullBackgroundColors', help='display the 8 dull background colors')
89+
backgroundBrightColorsParser = subparsers.add_parser('brightBackgroundColors', help='display the 8 bright background colors')
90+
allForegroundColorsParser = subparsers.add_parser('allForegroundColors', help='display 256 foreground colors')
91+
allBackgroundColorsParser = subparsers.add_parser('allBackgroundColors', help='display 256 background colors')
92+
allForegroundAllBackgroundParser = subparsers.add_parser('allForegroundAllBackground', help='display all 256 foreground and background colors separately')
93+
testForegroundOnBackgroundParser = subparsers.add_parser('testFgAndBg', help='Enter a foreground code and a background code and test it out')
94+
testForegroundOnBackgroundParser.add_argument('FOREGROUND', type=int, help='foreground, must be between 0 and 256')
95+
testForegroundOnBackgroundParser.add_argument('BACKGROUND', type=int, help='background, must be between 0 and 256')
96+
args = parser.parse_args()
97+
98+
if args.command == 'dullForegroundColors':
99+
dullForegroundColors()
100+
elif args.command == 'brightForegroundColors':
101+
brightForegroundColors()
102+
elif args.command == 'dullBackgroundColors':
103+
dullBackgroundColors()
104+
elif args.command == 'brightBackgroundColors':
105+
brightBackgroundColors()
106+
elif args.command == 'allForegroundColors':
107+
allForegroundColors()
108+
elif args.command == 'allBackgroundColors':
109+
allBackgroundColors()
110+
elif args.command == 'allForegroundAllBackground':
111+
allForegroundAndAllBackground()
112+
elif args.command == 'testFgAndBg':
113+
testForegroundOnBackground(args.FOREGROUND, args.BACKGROUND)
114+
else:
115+
parser.print_help()

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pkg-resources==0.0.0

0 commit comments

Comments
 (0)