diff options
-rwxr-xr-x | colorcube.py | 21 | ||||
-rwxr-xr-x | pixelterm/colorcube.py | 25 | ||||
-rwxr-xr-x | pixelterm/gifterm.py (renamed from gifterm.py) | 5 | ||||
-rw-r--r-- | pixelterm/pixelterm.py (renamed from pixelterm.py) | 6 | ||||
-rwxr-xr-x | pixelterm/pngmeta.py | 16 | ||||
-rwxr-xr-x | pixelterm/resolvecolor.py | 17 | ||||
-rw-r--r-- | pixelterm/unpixelterm.py (renamed from unpixelterm.py) | 6 | ||||
-rw-r--r-- | pixelterm/xtermcolors.py (renamed from xtermcolors.py) | 0 | ||||
-rwxr-xr-x | pngmeta.py | 11 | ||||
-rwxr-xr-x | resolvecolor.py | 13 | ||||
-rwxr-xr-x | setup.py | 15 |
11 files changed, 80 insertions, 55 deletions
diff --git a/colorcube.py b/colorcube.py deleted file mode 100755 index d87af0c..0000000 --- a/colorcube.py +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env python - -# Display an xterm-256color color palette on the terminal, including color ids - -reset_sequence = '\033[39;49m' - -def esc(i): - return '\033[48;5;'+str(i)+'m' - -print(''.join([str(i).ljust(4) for i in range(16)])) -print(' '.join([esc(i) for i in range(16)])+' ' + reset_sequence) - -for j in range(6): - for k in range(6): - c = 16+j*6+k*6*6 - print(''.join([str(c+i).ljust(4) for i in range(6)])) - print(' '.join([esc(c+i) for i in range(6)])+' ' + reset_sequence) - -print(''.join([str(i).ljust(4) for i in range(16+6*6*6, 16+6*6*6+24)])) -print(' '.join([esc(i) for i in range(16+6*6*6, 16+6*6*6+24)])+' ' + reset_sequence) - diff --git a/pixelterm/colorcube.py b/pixelterm/colorcube.py new file mode 100755 index 0000000..b7fe65c --- /dev/null +++ b/pixelterm/colorcube.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python + +# Display an xterm-256color color palette on the terminal, including color ids + +reset_sequence = '\033[39;49m' + +def esc(i): + return '\033[48;5;'+str(i)+'m' + +def main(): + print(''.join([str(i).ljust(4) for i in range(16)])) + print(' '.join([esc(i) for i in range(16)])+' ' + reset_sequence) + + for j in range(6): + for k in range(6): + c = 16+j*6+k*6*6 + print(''.join([str(c+i).ljust(4) for i in range(6)])) + print(' '.join([esc(c+i) for i in range(6)])+' ' + reset_sequence) + + print(''.join([str(i).ljust(4) for i in range(16+6*6*6, 16+6*6*6+24)])) + print(' '.join([esc(i) for i in range(16+6*6*6, 16+6*6*6+24)])+' ' + reset_sequence) + +if __name__ == '__main__': + main() + diff --git a/gifterm.py b/pixelterm/gifterm.py index 185f741..252e49c 100755 --- a/gifterm.py +++ b/pixelterm/gifterm.py @@ -7,7 +7,7 @@ clear_screen = '\033[H\033[2J' cursor_invisible = '\033[?25l' cursor_visible = '\033[?25h' -if __name__ == '__main__': +def main(): parser = argparse.ArgumentParser(description='Render pixel images on 256-color ANSI terminals') parser.add_argument('image', type=str) parser.add_argument('-s', '--size', type=str, help='Terminal size, [W]x[H]') @@ -48,3 +48,6 @@ if __name__ == '__main__': print(frame) time.sleep(img.info['duration']/1000.0) +if __name__ == '__main__': + main() + diff --git a/pixelterm.py b/pixelterm/pixelterm.py index 8b4fabf..4239b98 100644 --- a/pixelterm.py +++ b/pixelterm/pixelterm.py @@ -69,7 +69,7 @@ def termify_pixels(img): out = (out.rstrip() if bg == (0,0,0,0) else out) + '\n' return out[:-1] + reset_sequence + '\n' -if __name__ == '__main__': +def main(): import os, sys, argparse, os.path, json from multiprocessing import Pool from PIL import Image, PngImagePlugin @@ -103,3 +103,7 @@ if __name__ == '__main__': p = Pool() p.map(convert, args.image) + +if __name__ == '__main__': + main() + diff --git a/pixelterm/pngmeta.py b/pixelterm/pngmeta.py new file mode 100755 index 0000000..5ddde98 --- /dev/null +++ b/pixelterm/pngmeta.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python + +import os, sys, argparse +from PIL import Image, PngImagePlugin + +def main(): + parser = argparse.ArgumentParser(description='Print PNG metadata') + parser.add_argument('image', type=str) + args = parser.parse_args() + img = Image.open(args.image) + for k, v in img.info.items(): + print('{:15}: {}'.format(k, v)) + +if __name__ == '__main__': + main() + diff --git a/pixelterm/resolvecolor.py b/pixelterm/resolvecolor.py new file mode 100755 index 0000000..83c1330 --- /dev/null +++ b/pixelterm/resolvecolor.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python + +def main(): + import os, sys, argparse, os.path, json, re + import xtermcolors + + # Resolve HTML-style hex RGB color codes to xterm-256color color numbers + + if len(sys.argv) != 2: + print('Usage: resolvecolor.py #RRGGBB') + exit() + + print(xtermcolors.closest_color(*[int(s, 16) for s in re.match('#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})', sys.argv[1]).groups()])) + +if __name__ == '__main__': + main() + diff --git a/unpixelterm.py b/pixelterm/unpixelterm.py index d9b1498..8d1c120 100644 --- a/unpixelterm.py +++ b/pixelterm/unpixelterm.py @@ -90,7 +90,7 @@ def unpixelterm(text): x, y = 0, y+2 return img, metadata -if __name__ == '__main__': +def main(): import argparse, json parser = argparse.ArgumentParser(description='Convert images rendered by pixelterm-like utilities back to PNG') @@ -116,3 +116,7 @@ if __name__ == '__main__': if args.output_dir: output = os.path.join(args.output_dir, os.path.basename(output)) img.save(output, 'PNG', pnginfo=pnginfo) + +if __name__ == '__main__': + main() + diff --git a/xtermcolors.py b/pixelterm/xtermcolors.py index 36cddc6..36cddc6 100644 --- a/xtermcolors.py +++ b/pixelterm/xtermcolors.py diff --git a/pngmeta.py b/pngmeta.py deleted file mode 100755 index e6d9b6b..0000000 --- a/pngmeta.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python - -import os, sys, argparse -from PIL import Image, PngImagePlugin - -parser = argparse.ArgumentParser(description='Print PNG metadata') -parser.add_argument('image', type=str) -args = parser.parse_args() -img = Image.open(args.image) -for k, v in img.info.items(): - print('{:15}: {}'.format(k, v)) diff --git a/resolvecolor.py b/resolvecolor.py deleted file mode 100755 index 988b5cd..0000000 --- a/resolvecolor.py +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env python - -import os, sys, argparse, os.path, json, re -import xtermcolors - -# Resolve HTML-style hex RGB color codes to xterm-256color color numbers - -if len(sys.argv) != 2: - print('Usage: resolvecolor.py #RRGGBB') - exit() - -print(xtermcolors.closest_color(*[int(s, 16) for s in re.match('#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})', sys.argv[1]).groups()])) - @@ -22,14 +22,15 @@ setup(name = 'pixelterm', author = 'jaseg', author_email = 'pixelterm@jaseg.net', url = 'https://github.com/jaseg/pixelterm', - py_modules = ['pixelterm', 'unpixelterm', 'xtermcolors'], + py_modules = ['pixelterm'], install_requires=['pillow'], - scripts = ['pixelterm.py', - 'unpixelterm.py', - 'colorcube.py', - 'gifterm.py', - 'resolvecolor.py', - 'pngmeta.py'], + entry_points = {'console_scripts': [ + 'pixelterm=pixelterm.pixelterm:main', + 'unpixelterm=pixelterm.unpixelterm:main', + 'gifterm=pixelterm.gifterm:main', + 'colorcube=pixelterm.colorcube:main', + 'resolvecolor=pixelterm.resolvecolor:main', + 'pngmeta=pixelterm.pngmeta:main']}, zip_safe = True, classifiers = [ 'Development Status :: 5 - Production/Stable', |