From e7006b3e5bc6809459917e7c56d217595d388f7f 2006-05-19 17:48:27 From: walter.doerwald Date: 2006-05-19 17:48:27 Subject: [PATCH] Only use alignment specification if it's the first yielded result. Reuse ipipe.xformat() in ibrowse.ibrowse.getrow(). --- diff --git a/IPython/Extensions/ibrowse.py b/IPython/Extensions/ibrowse.py index 89302b1..2a0fe4f 100644 --- a/IPython/Extensions/ibrowse.py +++ b/IPython/Extensions/ibrowse.py @@ -291,30 +291,8 @@ class _BrowserLevel(object): value = exc # only store attribute if it exists (or we got an exception) if value is not ipipe.noitem: - parts = [] - totallength = 0 - align = None - full = True - # Collect parts until we have enough - for part in ipipe.xrepr(value, "cell"): - # part gives (alignment, stop) - # instead of (style, text) - if isinstance(part[0], int): - # only consider the first occurence - if align is None: - align = part[0] - full = part[1] - else: - parts.append(part) - totallength += len(part[1]) - if totallength >= self.browser.maxattrlength and not full: - parts.append((astyle.style_ellisis, "...")) - totallength += 3 - break - if align is None: - align = -1 - # remember alignment, length and colored parts - row[attrname] = (align, totallength, parts) + # remember alignment, length and colored text + row[attrname] = ipipe.xformat(value, "cell", self.browser.maxattrlength) return row def calcwidths(self): diff --git a/IPython/Extensions/ipipe.py b/IPython/Extensions/ipipe.py index be83394..ef73ed7 100644 --- a/IPython/Extensions/ipipe.py +++ b/IPython/Extensions/ipipe.py @@ -1616,17 +1616,20 @@ def xformat(value, mode, maxlength): full = True width = 0 text = astyle.Text() - for part in xrepr(value, mode): - # part is (alignment, stop) - if isinstance(part[0], int): - # only consider the first occurence - if align is None: - align = part[0] - full = part[1] - # part is (style, text) - else: - text.append(part) - width += len(part[1]) + for (style, part) in xrepr(value, mode): + # only consider the first result + if align is None: + if isinstance(style, int): + # (style, text) really is (alignment, stop) + align = style + full = part + continue + else: + align = -1 + full = True + if not isinstance(style, int): + text.append((style, part)) + width += len(part) if width >= maxlength and not full: text.append((astyle.style_ellisis, "...")) width += 3