From 43d608e95941fb5ae2b24e00676e79207dc0c351 Mon Sep 17 00:00:00 2001 From: Kirill Smelkov Date: Fri, 25 Jul 2008 21:43:59 +0400 Subject: [PATCH] pretty: fix printing of long strings e.g. pi.evalf(100) (#941) When pretty needs to print long stringPicts, we see at what terminal width is, and wraps the picture. Also currently we add vertical spacer between blocks. For mathematical formulas with height > 1 this is certainly the right thing to do, e.g.: 2 2 3 3 4 4 6*x *y + 4*x*y + 4*y*x + x + y is wrapped into this: 2 2 3 6*x *y + 4*x*y + <-- note vertical spacer 3 4 4 4*y*x + x + y But if we'll look at pi.evalf(100), or long dict or another string which is originally 1-character in height, it seems putting such v-spacers is not convenient: In [2]: pi.evalf(48) | In [2]: pi.evalf(48) Out[2]: | Out[2]: 3.14159265358979323 | 3.14159265358979323 8462643383279502884 | 19716939937 | 8462643383279502884 | | 19716939937 That's why I propose we stop adding this v-spacers if original picture is 1-character in height. Signed-off-by: Kirill Smelkov Signed-off-by: Ondrej Certik --- sympy/printing/pretty/stringpict.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/sympy/printing/pretty/stringpict.py b/sympy/printing/pretty/stringpict.py index 9db6ed0..15afaf8 100644 --- a/sympy/printing/pretty/stringpict.py +++ b/sympy/printing/pretty/stringpict.py @@ -245,14 +245,29 @@ class stringPict(object): if self.width() <= ncols: return type(self.picture[0])(self) + # for one-line pictures we don't need v-spacers. on the other hand, for + # multiline-pictures, we need v-spacers between blocks, compare: + # + # 2 2 3 | a*c*e + a*c*f + a*d | a*c*e + a*c*f + a*d | 3.14159265358979323 + # 6*x *y + 4*x*y + | | *e + a*d*f + b*c*e | 84626433832795 + # | *e + a*d*f + b*c*e | + b*c*f + b*d*e + b | + # 3 4 4 | | *d*f | + # 4*y*x + x + y | + b*c*f + b*d*e + b | | + # | | | + # | *d*f + do_vspacers = (self.height() > 1) + i = 0 svals = [] while i < self.width(): svals.extend([ sval[i:i+ncols] for sval in self.picture ]) - svals.append("") # a vertical spacer + if (self.height() > 1): + svals.append("") # a vertical spacer i += ncols - del svals[-1] # Get rid of the last spacer + if svals[-1] == '': + del svals[-1] # Get rid of the last spacer + _str = type(self.picture[0]) return _str.join(_str("\n"), svals) -- 2.11.4.GIT