-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathterminalcolors
executable file
·108 lines (91 loc) · 2.8 KB
/
terminalcolors
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env python
# Copyright (C) 2006 by Johannes Zellner, <johannes@zellner.org>
# modified by mac@calmar.ws to fit my output needs
# modified by crncosta@carloscosta.org to fit my output needs
#
# modified by <liangguohuan@gmail.com> http://www.github.com/liangguohuan:
# 1. argsparse component inject
# 2. print 256 color support setting columns
# 3. extend for printing ansi color
#
from __future__ import print_function, division, unicode_literals
import sys
import os
import argparse
def group(lst, n):
num = len(lst) % n
zipped = zip(*[iter(lst)] * n)
return zipped if not num else zipped + [lst[-num:], ]
def partition(lst, n):
return group(lst, int(math.ceil(len(lst)/n)))
def echo(msg):
# os.system('echo -n "' + str(msg) + '"')
print('')
def out(n):
# os.system("tput setab " + str(n) + "; echo -n " + ("\"% 4d\"" % n))
# os.system("tput setab 0")
print('\x1b[48;5;%dm% -4d\x1b[2m' % (n, n), end='')
def print_format_table_256(col=3):
"""
print 256 color table
"""
# normal colors 1 - 16
os.system("tput setaf 16")
for n in range(8):
out(n)
echo("\n")
for n in range(8, 16):
out(n)
echo("\n")
echo("\n")
# print color table support setting color
boxsize = 36
unit = 6
l = group(range(16, 232), 36*col)
for box in l:
_box = group(list(box), boxsize)
for k, __box in enumerate(_box):
_box[k] = list(group(list(__box), unit))
for x in zip(*_box):
for y in x:
for e in y:
out(e)
echo("\n")
echo("\n")
# y=16
# while y < 231:
# for z in range(0,6):
# out(y)
# y += 1
# echo("\n")
for n in range(232, 256):
out(n)
if n == 237 or n == 243 or n == 249:
echo("\n")
echo("\n")
os.system("tput setaf 7")
os.system("tput setab 0")
# => extend ansi color print
def print_format_table_ansi():
"""
print ansi color table
"""
for style in range(8):
for fg in range(30,38):
s1 = ''
for bg in range(40,48):
format = ';'.join([str(style), str(fg), str(bg)])
s1 += '\x1b[%sm %s \x1b[0m' % (format, format)
print(s1)
print('')
def main():
parser = argparse.ArgumentParser(description='Encrypt Or Decrypt binaryfile.')
parser.add_argument('-n', metavar='column', type=int, default=3, help='256 color table column, default: 3')
parser.add_argument('-f', metavar='format', nargs='?', default='256', help='suport 256 and ansi')
args = parser.parse_args()
if args.f == '256':
print_format_table_256(args.n)
else:
print_format_table_ansi()
if __name__ == '__main__':
main()