1 new commit in py:
https://bitbucket.org/hpk42/py/changeset/4dfde5019cb3/ changeset: 4dfde5019cb3 user: hpk42 date: 2012-06-09 13:11:04 summary: improve terminalwriter reline/line printing behaviour (as used by detox) affected #: 3 files diff -r 3b13d4cc842450768ad74639a5612c2d18114479 -r 4dfde5019cb35a1506aca3607d7de5245f762335 CHANGELOG --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,8 @@ - changed iniconfig parsing to better conform, now the chars ";" and "#" only mark a comment at the stripped start of a line - include recent apipkg-1.2 +- change internal terminalwriter.line/reline logic to more nicely + support file spinners Changes between 1.4.7 and 1.4.8 ================================================== diff -r 3b13d4cc842450768ad74639a5612c2d18114479 -r 4dfde5019cb35a1506aca3607d7de5245f762335 py/_io/terminalwriter.py --- a/py/_io/terminalwriter.py +++ b/py/_io/terminalwriter.py @@ -105,8 +105,6 @@ 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: @@ -120,6 +118,7 @@ self._file = file self.fullwidth = get_terminal_width() self.hasmarkup = should_do_markup(file) + self._lastlen = 0 def _escaped(self, text, esc): if esc and self.hasmarkup: @@ -182,31 +181,22 @@ return s def line(self, s='', **kw): - if self._newline == False: - self.write("\n") self.write(s, **kw) + self._checkfill(s) self.write('\n') - self._newline = True - def reline(self, line, **opts): + def reline(self, line, **kw): if not self.hasmarkup: raise ValueError("cannot use rewrite-line without terminal") - if not self._newline: - self.write("\r") - self.write(line, **opts) - # see if we need to fill up some spaces at the end - # xxx have a more exact lastlinelen working from self.write? - lenline = len(line) - try: - lastlen = self._lastlinelen - except AttributeError: - pass - else: - if lenline < lastlen: - self.write(" " * (lastlen - lenline + 1)) - self._lastlinelen = lenline - self._newline = False + self.write(line, **kw) + self._checkfill(line) + self.write('\r') + self._lastlen = len(line) + def _checkfill(self, line): + diff2last = self._lastlen - len(line) + if diff2last > 0: + self.write(" " * diff2last) class Win32ConsoleWriter(TerminalWriter): def write(self, s, **kw): diff -r 3b13d4cc842450768ad74639a5612c2d18114479 -r 4dfde5019cb35a1506aca3607d7de5245f762335 testing/io_/test_terminalwriter.py --- a/testing/io_/test_terminalwriter.py +++ b/testing/io_/test_terminalwriter.py @@ -106,6 +106,7 @@ io.seek(0) return io.readlines() tw.getlines = getlines + tw.getvalue = lambda: "".join(getlines()) return tw def test_line(self, tw): @@ -170,18 +171,19 @@ pytest.raises(ValueError, lambda: tw.reline("x")) tw.hasmarkup = True tw.reline("0 1 2") - l = "".join(tw.getlines()).split("\n") + tw.getlines() + l = tw.getvalue().split("\n") assert len(l) == 2 tw.reline("0 1 3") - l = "".join(tw.getlines()).split("\n") + l = tw.getvalue().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].endswith("0 1 3\r") + tw.line("so") + l = tw.getvalue().split("\n") + assert len(l) == 3 assert l[-1] == "" - out = "\n".join(l) - assert out.endswith("\nsomething\n") + assert l[1] == ("0 1 2\r0 1 3\rso ") + assert l[0] == "hello" 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. _______________________________________________ py-svn mailing list py-svn@codespeak.net http://codespeak.net/mailman/listinfo/py-svn