aboutsummaryrefslogtreecommitdiff
path: root/termcenter
diff options
context:
space:
mode:
authorjaseg <s@jaseg.de>2013-07-29 19:29:32 +0200
committerjaseg <s@jaseg.de>2013-07-29 19:56:31 +0200
commit13f954f4ecace0c4888e194c75a26666fa3fc305 (patch)
tree73935ab0012f0e722efee915ecb77af58b930350 /termcenter
parent1466970c712fbd3f8579fdc995acc80e0e115299 (diff)
downloadponysay-13f954f4ecace0c4888e194c75a26666fa3fc305.tar.gz
ponysay-13f954f4ecace0c4888e194c75a26666fa3fc305.tar.bz2
ponysay-13f954f4ecace0c4888e194c75a26666fa3fc305.zip
Added a proper setup.py
Diffstat (limited to 'termcenter')
-rwxr-xr-xtermcenter22
1 files changed, 22 insertions, 0 deletions
diff --git a/termcenter b/termcenter
new file mode 100755
index 0000000..54fffa0
--- /dev/null
+++ b/termcenter
@@ -0,0 +1,22 @@
+#!/usr/bin/env python3
+
+import os,sys,time, itertools
+import argparse
+from subprocess import *
+try:
+ import re2 as re
+except:
+ import re
+
+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((os.get_terminal_size()[0]- width)/2)
+ for line in lines:
+ print(' '*pad + re.sub(r'\$.*\$|\n', '', line))
+