aboutsummaryrefslogtreecommitdiff
path: root/ponycenter.py
diff options
context:
space:
mode:
authorjaseg <s@jaseg.de>2013-03-31 21:01:13 +0200
committerjaseg <s@jaseg.de>2013-03-31 21:01:13 +0200
commit7ea7c59e7181533ebd79d948d168b31ccfd85401 (patch)
treeba96837ada19bc785bf91515c688ce7cfa6f8ea5 /ponycenter.py
parenta72c728ab47d440b292ae9ed17a2b1524114d07f (diff)
downloadponysay-7ea7c59e7181533ebd79d948d168b31ccfd85401.tar.gz
ponysay-7ea7c59e7181533ebd79d948d168b31ccfd85401.tar.bz2
ponysay-7ea7c59e7181533ebd79d948d168b31ccfd85401.zip
Rewrite completed. <100lines.
Diffstat (limited to 'ponycenter.py')
-rwxr-xr-xponycenter.py39
1 files changed, 0 insertions, 39 deletions
diff --git a/ponycenter.py b/ponycenter.py
deleted file mode 100755
index 66e64fe..0000000
--- a/ponycenter.py
+++ /dev/null
@@ -1,39 +0,0 @@
-#!/usr/bin/env python3
-
-import os,sys,time, itertools
-import argparse
-from subprocess import *
-try:
- import re2 as re
-except:
- import re
-
-'''
-Gets the size of the terminal in (rows, columns)
-
-@return (rows, columns):(int, int) The number or lines and the number of columns in the terminal's display area, [24, 80] if the size cannot be found
-'''
-def gettermsize():
- return [int(x) for x in
- next(itertools.chain(
- (x for x in
- (Popen(['stty', 'size'], stdout=PIPE, stdin=fd, stderr=PIPE).communicate()[0].split()
- for fd in [sys.stdin, sys.stdout, sys.stderr])
- if x),
- [[24, 80]]
- )
- )
- ]
-
-parser = argparse.ArgumentParser(description='Center stuff on terminals')
-parser.add_argument('string', nargs='*', type=str)
-args = parser.parse_args()
-
-for e in [sys.stdin] + args.string:
- lines = [e] if isinstance(e, str) else e.readlines()
- if lines:
- width = max(map(len, map(lambda s: re.sub(r'\x1B\[[0-9;]+m|\$.*\$', '', s), lines)))
- pad = int((gettermsize()[1]- width)/2)
- for line in lines:
- print(' '*pad + re.sub(r'\$.*\$|\n', '', line))
-