##// END OF EJS Templates
Configurable display hook
vivainio -
Show More
@@ -2,7 +2,7 b''
2 """
2 """
3 Classes for handling input/output prompts.
3 Classes for handling input/output prompts.
4
4
5 $Id: Prompts.py 1005 2006-01-12 08:39:26Z fperez $"""
5 $Id: Prompts.py 1020 2006-01-14 13:22:58Z vivainio $"""
6
6
7 #*****************************************************************************
7 #*****************************************************************************
8 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
8 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
@@ -525,19 +525,11 b' class CachedOutput:'
525 def _display(self,arg):
525 def _display(self,arg):
526 """Default printer method, uses pprint.
526 """Default printer method, uses pprint.
527
527
528 This can be over-ridden by the users to implement special formatting
528 Do ip.set_hook("result_display", my_displayhook) for custom result
529 of certain types of output."""
529 display, e.g. when your own objects need special formatting.
530
530 """
531 if self.Pprint:
531
532 out = pformat(arg)
532 self.shell.hooks.result_display(arg)
533 if '\n' in out:
534 # So that multi-line strings line up with the left column of
535 # the screen, instead of having the output prompt mess up
536 # their first line.
537 Term.cout.write('\n')
538 print >>Term.cout, out
539 else:
540 print >>Term.cout, arg
541
533
542 # Assign the default display method:
534 # Assign the default display method:
543 display = _display
535 display = _display
@@ -32,7 +32,7 b" ip_set_hook('editor',myiphooks.calljed)"
32 The ip_set_hook function is put by IPython into the builtin namespace, so it
32 The ip_set_hook function is put by IPython into the builtin namespace, so it
33 is always available from all running code.
33 is always available from all running code.
34
34
35 $Id: hooks.py 1019 2006-01-14 13:02:12Z vivainio $"""
35 $Id: hooks.py 1020 2006-01-14 13:22:58Z vivainio $"""
36
36
37 #*****************************************************************************
37 #*****************************************************************************
38 # Copyright (C) 2005 Fernando Perez. <fperez@colorado.edu>
38 # Copyright (C) 2005 Fernando Perez. <fperez@colorado.edu>
@@ -47,10 +47,12 b' __license__ = Release.license'
47 __version__ = Release.version
47 __version__ = Release.version
48
48
49 import os,bisect
49 import os,bisect
50 from genutils import Term
51 from pprint import pformat
50
52
51 # List here all the default hooks. For now it's just the editor functions
53 # List here all the default hooks. For now it's just the editor functions
52 # but over time we'll move here all the public API for user-accessible things.
54 # but over time we'll move here all the public API for user-accessible things.
53 __all__ = ['editor', 'fix_error_editor']
55 __all__ = ['editor', 'fix_error_editor', 'result_display']
54
56
55 def editor(self,filename, linenum=None):
57 def editor(self,filename, linenum=None):
56 """Open the default editor at the given filename and linenumber.
58 """Open the default editor at the given filename and linenumber.
@@ -133,4 +135,15 b' class CommandChainDispatcher:'
133 """ Add a func to the cmd chain with given priority """
135 """ Add a func to the cmd chain with given priority """
134 bisect.insort(self.chain,(priority,func))
136 bisect.insort(self.chain,(priority,func))
135
137
138 def result_display(self,arg):
139 if self.rc.pprint:
140 out = pformat(arg)
141 if '\n' in out:
142 # So that multi-line strings line up with the left column of
143 # the screen, instead of having the output prompt mess up
144 # their first line.
145 Term.cout.write('\n')
146 print >>Term.cout, out
147 else:
148 print >>Term.cout, arg
136 No newline at end of file
149
@@ -13,8 +13,8 b''
13 as "chain of command", with priority. API stays the same,
13 as "chain of command", with priority. API stays the same,
14 TryNext exception raised by a hook function signals that
14 TryNext exception raised by a hook function signals that
15 current hook failed and next hook should try handling it, as
15 current hook failed and next hook should try handling it, as
16 suggested by Walter Dörwald <walter@livinglogic.de>.
16 suggested by Walter Dörwald <walter@livinglogic.de>. Walter also
17
17 requested configurable display hook, which is now implemented.
18
18
19 2006-01-13 Ville Vainio <vivainio@gmail.com>
19 2006-01-13 Ville Vainio <vivainio@gmail.com>
20
20
General Comments 0
You need to be logged in to leave comments. Login now