]> jfr.im git - z_archive/twitter.git/blobdiff - twitter/util.py
Improved display of multiline tweets.
[z_archive/twitter.git] / twitter / util.py
index 8d66c4e8e8e56e58bd4bd468e2708405072e9602..7e4d6ab3f891aa70cdd818ace8b0b33c49c615e8 100644 (file)
@@ -10,6 +10,7 @@ from __future__ import print_function
 import contextlib
 import re
 import sys
+import textwrap
 import time
 
 try:
@@ -134,3 +135,12 @@ def parse_host_list(list_of_hosts):
         m.group(1) for m in re.finditer("\s*([^,\s]+)\s*,?\s*", list_of_hosts))
     return p
 
+
+def align_text(text, left_margin=16, max_width=80):
+    lines = []
+    for line in text.split('\n'):
+        temp_lines = textwrap.wrap(line, max_width - left_margin)
+        temp_lines = [(' ' * left_margin + line) for line in temp_lines]
+        lines.append('\n'.join(temp_lines))
+    ret = '\n'.join(lines)
+    return ret.lstrip()