#14266: Pretty Console Output --> ascii art
---------------------------------------+------------------------------------
       Reporter:  elixyre              |         Owner:  was         
           Type:  task                 |        Status:  needs_review
       Priority:  major                |     Milestone:  sage-5.10   
      Component:  user interface       |    Resolution:              
       Keywords:  ascii-art            |   Work issues:              
Report Upstream:  N/A                  |     Reviewers:              
        Authors:  Jean-Baptiste Priez  |     Merged in:              
   Dependencies:                       |      Stopgaps:              
---------------------------------------+------------------------------------

Comment (by vbraun):

 I don't like your approach for changing the output, you are monkey-
 patching sage.misc.displayhook to change its behavior from another module.
 Thats usually a no-no in production code (unless you cannot control the
 source that you are patching, which is not the case here). The problem is
 that if anybody is going to edit sage.misc.displayhook later on, they will
 inadvertently break your construction since noting in the source code of
 the displayhook knowns that this is not the actual code that is used when
 Sage is running. The standard solution to associating state with a
 function is to use a functionoid, that is, a class with a `__call__`
 method:
 {{{
 class FormatObj():
     def __init__(self):
         self._display = False

     def set_ascii_art(self, ascii_art):
         self._display = bool(ascii_art)

     def __call__(self, obj):
         if self._display:
              ...
         else:
              ....

 format_obj = FormatObj()
 }}}
 As a bonus, your code then wouldn't need layers of indirection
 `format_obj` -> `pretty_format` -> `simple_format_obj`.

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/14266#comment:30>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to