[py-svn] r36269 - in py/dist/py: misc test/terminal

cfbolz at codespeak.net cfbolz at codespeak.net
Mon Jan 8 14:50:00 CET 2007


Author: cfbolz
Date: Mon Jan  8 14:49:46 2007
New Revision: 36269

Added:
   py/dist/py/misc/terminal_helper.py
Modified:
   py/dist/py/test/terminal/out.py
Log:
introduce a terminal_helper file that contains ansi_print and terminal_width,
currently. use this from the terminal output of py.test


Added: py/dist/py/misc/terminal_helper.py
==============================================================================
--- (empty file)
+++ py/dist/py/misc/terminal_helper.py	Mon Jan  8 14:49:46 2007
@@ -0,0 +1,21 @@
+import sys, os
+
+terminal_width = int(os.environ.get('COLUMNS', 80))-1
+
+def ansi_print(text, esc, file=None, newline=True, flush=False):
+    if file is None:
+        file = sys.stderr
+    text = text.rstrip()
+    if esc and sys.platform != "win32" and file.isatty():
+        if not isinstance(esc, tuple):
+            esc = (esc,)
+        text = (''.join(['\x1b[%sm' % cod for cod in esc])  +  
+                text +
+                '\x1b[0m')     # ANSI color code "reset"
+    if newline:
+        text += '\n'
+    file.write(text)
+    if flush:
+        file.flush()
+
+

Modified: py/dist/py/test/terminal/out.py
==============================================================================
--- py/dist/py/test/terminal/out.py	(original)
+++ py/dist/py/test/terminal/out.py	Mon Jan  8 14:49:46 2007
@@ -2,10 +2,11 @@
 import sys
 import os
 import py
+from py.misc import terminal_helper
 
 class Out(object):
     tty = False
-    fullwidth = int(os.environ.get('COLUMNS', 80))-1
+    fullwidth = terminal_helper.terminal_width
     def __init__(self, file):
         self.file = py.io.dupfile(file)
 



More information about the pytest-commit mailing list