[svn r62857] Always substract the last column from the Win32 terminal console:

otherwise the last char wraps and the \n causes an empty line.

This allows more tests to pass.

--HG--
branch : trunk
This commit is contained in:
afa 2009-03-11 13:55:44 +01:00
parent 4be27f5078
commit f56310d178
2 changed files with 3 additions and 6 deletions

View File

@ -63,7 +63,9 @@ if sys.platform == 'win32':
info = CONSOLE_SCREEN_BUFFER_INFO() info = CONSOLE_SCREEN_BUFFER_INFO()
ctypes.windll.kernel32.GetConsoleScreenBufferInfo( ctypes.windll.kernel32.GetConsoleScreenBufferInfo(
handle, ctypes.byref(info)) handle, ctypes.byref(info))
return info.dwSize.Y, info.dwSize.X # Substract one from the width, otherwise the cursor wraps
# and the ending \n causes an empty line to display.
return info.dwSize.Y, info.dwSize.X - 1
def get_terminal_width(): def get_terminal_width():
try: try:
@ -218,9 +220,6 @@ class Win32ConsoleWriter(object):
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:
fullwidth = self.fullwidth fullwidth = self.fullwidth
# On a Windows console, writing in the last column
# causes a line feed.
fullwidth -= 1
# the goal is to have the line be as long as possible # the goal is to have the line be as long as possible
# under the condition that len(line) <= fullwidth # under the condition that len(line) <= fullwidth
if title is not None: if title is not None:

View File

@ -40,7 +40,6 @@ class BaseTests:
tw.sep("-", fullwidth=60) tw.sep("-", fullwidth=60)
l = self.getlines() l = self.getlines()
assert len(l) == 1 assert len(l) == 1
skip_win32()
assert l[0] == "-" * 60 + "\n" assert l[0] == "-" * 60 + "\n"
def test_sep_with_title(self): def test_sep_with_title(self):
@ -48,7 +47,6 @@ class BaseTests:
tw.sep("-", "hello", fullwidth=60) tw.sep("-", "hello", fullwidth=60)
l = self.getlines() l = self.getlines()
assert len(l) == 1 assert len(l) == 1
skip_win32()
assert l[0] == "-" * 26 + " hello " + "-" * 27 + "\n" assert l[0] == "-" * 26 + " hello " + "-" * 27 + "\n"
def test__escaped(self): def test__escaped(self):