apply and generalize patch from Ronny regarding dumb terminals, add doc note

--HG--
branch : trunk
This commit is contained in:
holger krekel 2009-05-13 13:06:32 +02:00
parent fdd50fcfd7
commit 045a135786
2 changed files with 15 additions and 2 deletions

View File

@ -129,6 +129,10 @@ def ansi_print(text, esc, file=None, newline=True, flush=False):
if flush:
file.flush()
def should_do_markup(file):
return hasattr(file, 'isatty') and file.isatty() \
and os.environ.get('TERM') != 'dumb'
class TerminalWriter(object):
_esctable = dict(black=30, red=31, green=32, yellow=33,
blue=34, purple=35, cyan=36, white=37,
@ -146,7 +150,7 @@ class TerminalWriter(object):
file = WriteFile(file)
self._file = file
self.fullwidth = get_terminal_width()
self.hasmarkup = hasattr(file, 'isatty') and file.isatty()
self.hasmarkup = should_do_markup(file)
def _escaped(self, text, esc):
if esc and self.hasmarkup:
@ -217,7 +221,7 @@ class Win32ConsoleWriter(object):
file = WriteFile(file)
self._file = file
self.fullwidth = get_terminal_width()
self.hasmarkup = hasattr(file, 'isatty') and file.isatty()
self.hasmarkup = should_do_markup(file)
def sep(self, sepchar, title=None, fullwidth=None, **kw):
if fullwidth is None:

View File

@ -1,6 +1,7 @@
import py
import os, sys
from py.__.io import terminalwriter
import StringIO
def skip_win32():
if sys.platform == 'win32':
@ -20,6 +21,14 @@ def test_terminalwriter_default_instantiation():
tw = py.io.TerminalWriter(stringio=True)
assert hasattr(tw, 'stringio')
def test_terminalwriter_dumb_term_no_markup(monkeypatch):
monkeypatch.setattr(os, 'environ', {'TERM': 'dumb', 'PATH': ''})
monkeypatch.setattr(sys, 'stdout', StringIO.StringIO())
monkeypatch.setattr(sys.stdout, 'isatty', lambda:True)
assert sys.stdout.isatty()
tw = py.io.TerminalWriter()
assert not tw.hasmarkup
class BaseTests:
def test_line(self):
tw = self.getwriter()