apply and generalize patch from Ronny regarding dumb terminals, add doc note
--HG-- branch : trunk
This commit is contained in:
parent
fdd50fcfd7
commit
045a135786
|
@ -129,6 +129,10 @@ def ansi_print(text, esc, file=None, newline=True, flush=False):
|
||||||
if flush:
|
if flush:
|
||||||
file.flush()
|
file.flush()
|
||||||
|
|
||||||
|
def should_do_markup(file):
|
||||||
|
return hasattr(file, 'isatty') and file.isatty() \
|
||||||
|
and os.environ.get('TERM') != 'dumb'
|
||||||
|
|
||||||
class TerminalWriter(object):
|
class TerminalWriter(object):
|
||||||
_esctable = dict(black=30, red=31, green=32, yellow=33,
|
_esctable = dict(black=30, red=31, green=32, yellow=33,
|
||||||
blue=34, purple=35, cyan=36, white=37,
|
blue=34, purple=35, cyan=36, white=37,
|
||||||
|
@ -146,7 +150,7 @@ class TerminalWriter(object):
|
||||||
file = WriteFile(file)
|
file = WriteFile(file)
|
||||||
self._file = file
|
self._file = file
|
||||||
self.fullwidth = get_terminal_width()
|
self.fullwidth = get_terminal_width()
|
||||||
self.hasmarkup = hasattr(file, 'isatty') and file.isatty()
|
self.hasmarkup = should_do_markup(file)
|
||||||
|
|
||||||
def _escaped(self, text, esc):
|
def _escaped(self, text, esc):
|
||||||
if esc and self.hasmarkup:
|
if esc and self.hasmarkup:
|
||||||
|
@ -217,7 +221,7 @@ class Win32ConsoleWriter(object):
|
||||||
file = WriteFile(file)
|
file = WriteFile(file)
|
||||||
self._file = file
|
self._file = file
|
||||||
self.fullwidth = get_terminal_width()
|
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):
|
def sep(self, sepchar, title=None, fullwidth=None, **kw):
|
||||||
if fullwidth is None:
|
if fullwidth is None:
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import py
|
import py
|
||||||
import os, sys
|
import os, sys
|
||||||
from py.__.io import terminalwriter
|
from py.__.io import terminalwriter
|
||||||
|
import StringIO
|
||||||
|
|
||||||
def skip_win32():
|
def skip_win32():
|
||||||
if sys.platform == 'win32':
|
if sys.platform == 'win32':
|
||||||
|
@ -20,6 +21,14 @@ def test_terminalwriter_default_instantiation():
|
||||||
tw = py.io.TerminalWriter(stringio=True)
|
tw = py.io.TerminalWriter(stringio=True)
|
||||||
assert hasattr(tw, 'stringio')
|
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:
|
class BaseTests:
|
||||||
def test_line(self):
|
def test_line(self):
|
||||||
tw = self.getwriter()
|
tw = self.getwriter()
|
||||||
|
|
Loading…
Reference in New Issue