That way we get a chance to disable line wrapping, which is interesting, for example for pretty printing to non-terminals (html, etc.) --- sympy/printing/pretty/pretty.py | 18 +++++++++++++----- sympy/printing/pretty/tests/test_pretty_unicode.py | 6 ++++++ 2 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/sympy/printing/pretty/pretty.py b/sympy/printing/pretty/pretty.py index 9a31e46..afa4dcd 100644 --- a/sympy/printing/pretty/pretty.py +++ b/sympy/printing/pretty/pretty.py @@ -14,20 +14,23 @@ class PrettyPrinter(Printer): """Printer, which converts an expression into 2D ascii-art figure.""" - def __init__(self, profile=None): + def __init__(self, profile=None, wrap=True): Printer.__init__(self) self.emptyPrinter = lambda x : prettyForm(xstr(x)) self._settings = { "full_prec" : "auto", "use_unicode" : True, + "wrap" : wrap, } if profile is not None: self._settings.update(profile) def doprint(self, expr): - return self._print(expr).terminal_string() + if self._settings["wrap"]: + return self._print(expr).terminal_string() + return unicode( self._print(expr) ) # empty op so _print(stringPict) returns the same def _print_stringPict(self, e): @@ -591,9 +594,14 @@ def __print_set(self, s): def pretty(expr, profile=None, **kargs): """ - Returns a string containing the prettified form of expr. If use_unicode - is set to True then certain expressions will use unicode characters, - such as the greek letter pi for Pi instances. + Returns a string containing the prettified form of expr. + + Arguments + --------- + expr: the expression to print + wrap: line wrapping enabled/disabled, should be a boolean value (default to True) + use_unicode: use unicode characters, such as the greek letter pi instead of + the string pi. Values should be boolean or None """ if profile is not None: profile.update(kargs) diff --git a/sympy/printing/pretty/tests/test_pretty_unicode.py b/sympy/printing/pretty/tests/test_pretty_unicode.py index ee7bb16..cccfbd0 100644 --- a/sympy/printing/pretty/tests/test_pretty_unicode.py +++ b/sympy/printing/pretty/tests/test_pretty_unicode.py @@ -386,3 +386,9 @@ def test_upretty_seq_even(): """ assert u == s +def test_pretty_nowrap(): + huge_expr = 0 + for i in range(20): + huge_expr += i*sin(i+x) + assert pretty(huge_expr ).find('\n') != -1 + assert pretty(huge_expr, wrap=False).find('\n') == -1 -- 1.6.1.2 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sympy-patches" group. To post to this group, send email to sympy-patches@googlegroups.com To unsubscribe from this group, send email to sympy-patches+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sympy-patches?hl=en -~----------~----~----~----~------~----~------~--~---