On Mon, Sep 5, 2011 at 9:27 PM, Roberto Colistete Jr. <[email protected]> wrote: > On 12 ago, 03:10, Aaron Meurer <[email protected]> wrote: >> Unfortunately, it seems it is not possible to supply a custom terminal >> width. It would be great to add this as a setting to PrettyPrinter. >> It would flow through to the render() function in that file you >> mentioned, and would override the value calculated from >> terminal_width() (the default setting would be None, which would do >> what it does now). > > Hi Aaron Meurer, > > I think I have succeeded with the following changes to add a > "num_columns" setting (with default None so it reads the terminal > width) to "init_printing" and "pretty"/"pretty_print"/"pprint" : > > file "interactive/printing.py" : > Function init_printing, line 64 before : > def init_printing(pretty_print=True, order=None, use_unicode=None, > wrap_line=None, no_global=False, ip=None): > after : > def init_printing(pretty_print=True, order=None, use_unicode=None, > wrap_line=None, num_columns=None, no_global=False, ip=None): > Function init_printing, line 79 before : > stringify_func = lambda expr: _stringify_func(expr, > order=order, use_unicode=use_unicode, wrap_line=wrap_line) > after : > stringify_func = lambda expr: _stringify_func(expr, > order=order, use_unicode=use_unicode, wrap_line=wrap_line, > num_columns=num_columns) > > printing/pretty/pretty.py : > Inside class PrettyPrinter(Printer), line 25-26 before : > "wrap_line": True, > } > after : > "wrap_line": True, > "num_columns": None > } > Inside function pretty(expr, **settings), line 1166 before : > wrap_line: line wrapping enabled/disabled, should be a boolean > value (default to True) > after : > wrap_line: line wrapping enabled/disabled, should be a boolean > value (default to True) > num_columns: number of columns before line breaking (default to > None which reads the > terminal width), it is useful when using SymPy without > terminal. > > printing/pretty/stringpict.py : > Inside function render(self, * args, **kwargs), line 244 before : > # Attempt to get a terminal width > ncols = self.terminal_width() > after : > if (kwargs["num_columns"] is not None) and > (isinstance(kwargs["num_columns"], int)):
I would remove this isinstance call. > # Read the argument num_columns if it is an integer number > ncols = kwargs["num_columns"] > else: > # Attempt to get a terminal width > ncols = self.terminal_width() > > What do you think ? About the name of the setting (num_columns) and > the implementation above ? Other than that one comment, this looks good. I didn't try applying it to test it, though (I'll wait for the actual patch to do that). Aaron Meurer > > So "pretty_print(expr, num_columns=40)" sets the pretty printing > output to 40 columns. > > >> If you could implement this, it would be great. We can help you with >> the patch. Do you already know how to use git? We have an extensive >> guide on all aspects of patch submission >> athttps://github.com/sympy/sympy/wiki/Development-workflow#wiki-how-to-... >> if you need guidance (or just ask us here). > > > If everything above is ok (I want to hear the opinions from the > SymPy community), the I > will try to submit using git (for the 1st time...). > > Roberto Colistete Jr. > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/sympy?hl=en. > > -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sympy?hl=en.
