changeset 12:5b70bbff04b1

STUB: textshaper/main.py
author Jeff Hammel <k0scist@gmail.com>
date Sat, 25 Jan 2014 18:09:48 -0800
parents 0d0db0d79bfd
children c3df7dccb02b
files textshaper/main.py
diffstat 1 files changed, 14 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/textshaper/main.py	Sat Jan 18 09:31:05 2014 -0800
+++ b/textshaper/main.py	Sat Jan 25 18:09:48 2014 -0800
@@ -11,11 +11,21 @@
 import sys
 import time
 
-def display(content):
+def info(content):
+    """gathers info about the content and returns a dict"""
+    lines = content.splitlines()
+    return {'lines': len(lines),
+            'chars': len(content),
+            'columns': max([len(line) for line in lines])
+        }
+
+def display(content, keys=('lines', 'chars', 'columns'), hr='--'):
     print content
-    print '--'
-    nlines = len(content.splitlines())
-    print '%d lines' % nlines
+    if keys:
+        _info = info(content)
+        print (hr)
+    print ('; '.join(['{}: {}'.format(key, _info[key])
+                      for key in keys])
 
 def add_options(parser):
     """add options to the OptionParser instance"""