[py-svn] commit/py: hpk42: implement rewriting functionality for TerminalWriter,
Bitbucket
commits-noreply at bitbucket.org
Fri Jan 20 19:38:58 CET 2012
1 new commit in py:
https://bitbucket.org/hpk42/py/changeset/e97d7c933a74/
changeset: e97d7c933a74
user: hpk42
date: 2012-01-20 19:38:44
summary: implement rewriting functionality for TerminalWriter,
allowing to implement spinners by rewriting a line multiple times.
affected #: 4 files
diff -r bc37161ccd8c2fb1ff19662ffe154e6151b73a55 -r e97d7c933a74e34f45e704e8b129c67424cd11ce py/__init__.py
--- a/py/__init__.py
+++ b/py/__init__.py
@@ -8,7 +8,7 @@
(c) Holger Krekel and others, 2004-2010
"""
-__version__ = '1.4.7.dev2'
+__version__ = '1.4.7.dev3'
from py import _apipkg
diff -r bc37161ccd8c2fb1ff19662ffe154e6151b73a55 -r e97d7c933a74e34f45e704e8b129c67424cd11ce py/_io/terminalwriter.py
--- a/py/_io/terminalwriter.py
+++ b/py/_io/terminalwriter.py
@@ -105,6 +105,8 @@
Blue=44, Purple=45, Cyan=46, White=47,
bold=1, light=2, blink=5, invert=7)
+ _newline = None # the last line printed
+
# XXX deprecate stringio argument
def __init__(self, file=None, stringio=False, encoding=None):
if file is None:
@@ -180,8 +182,24 @@
return s
def line(self, s='', **kw):
+ if self._newline == False:
+ self.write("\n")
self.write(s, **kw)
self.write('\n')
+ self._newline = True
+
+ def reline(self, line, **opts):
+ if not self.hasmarkup:
+ raise ValueError("cannot use rewrite-line without terminal")
+ if not self._newline:
+ self.write("\r")
+ self.write(line, **opts)
+ lastlen = getattr(self, '_lastlinelen', None)
+ self._lastlinelen = lenlastline = len(line)
+ if lenlastline < lastlen:
+ self.write(" " * (lastlen - lenlastline + 1))
+ self._newline = False
+
class Win32ConsoleWriter(TerminalWriter):
def write(self, s, **kw):
diff -r bc37161ccd8c2fb1ff19662ffe154e6151b73a55 -r e97d7c933a74e34f45e704e8b129c67424cd11ce setup.py
--- a/setup.py
+++ b/setup.py
@@ -12,7 +12,7 @@
name='py',
description='library with cross-python path, ini-parsing, io, code, log facilities',
long_description = open('README.txt').read(),
- version='1.4.7.dev2',
+ version='1.4.7.dev3',
url='http://pylib.org',
license='MIT license',
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],
diff -r bc37161ccd8c2fb1ff19662ffe154e6151b73a55 -r e97d7c933a74e34f45e704e8b129c67424cd11ce testing/io_/test_terminalwriter.py
--- a/testing/io_/test_terminalwriter.py
+++ b/testing/io_/test_terminalwriter.py
@@ -2,6 +2,7 @@
import os, sys
from py._io import terminalwriter
import codecs
+import pytest
def test_get_terminal_width():
x = py.io.get_terminal_width
@@ -163,6 +164,26 @@
l = tw.getlines()
assert len(l[0]) == len(l[1])
+ def test_reline(self, tw):
+ tw.line("hello")
+ tw.hasmarkup = False
+ pytest.raises(ValueError, lambda: tw.reline("x"))
+ tw.hasmarkup = True
+ tw.reline("0 1 2")
+ l = "".join(tw.getlines()).split("\n")
+ assert len(l) == 2
+ tw.reline("0 1 3")
+ l = "".join(tw.getlines()).split("\n")
+ assert len(l) == 2
+ assert l[1].endswith("\r0 1 3")
+ tw.line("something")
+ l = "".join(tw.getlines()).split("\n")
+ assert len(l) == 4
+ assert l[-1] == ""
+ out = "\n".join(l)
+ assert out.endswith("\nsomething\n")
+
+
def test_attr_hasmarkup():
tw = py.io.TerminalWriter(stringio=True)
Repository URL: https://bitbucket.org/hpk42/py/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the pytest-commit
mailing list