Show More
@@ -21,7 +21,8 b' from linefrontendbase import LineFrontEndBase, common_prefix' | |||
|
21 | 21 | |
|
22 | 22 | from IPython.ipmaker import make_IPython |
|
23 | 23 | from IPython.ipapi import IPApi |
|
24 |
from IPython.kernel.core. |
|
|
24 | from IPython.kernel.core.file_like import FileLike | |
|
25 | from IPython.kernel.core.output_trap import OutputTrap | |
|
25 | 26 | |
|
26 | 27 | from IPython.genutils import Term |
|
27 | 28 | import pydoc |
@@ -33,13 +34,10 b' import os' | |||
|
33 | 34 | def xterm_system(command): |
|
34 | 35 | """ Run a command in a separate console window. |
|
35 | 36 | """ |
|
36 | os.system(""" | |
|
37 | xterm -title "%s" -e \'/bin/sh -c "%s ; | |
|
38 | printf \\"\\\\n\\"; | |
|
39 | printf \\"press a key to close\\" ; | |
|
40 | printf \\"\x1b]0;%s (finished -- press a key to close)\x07\\" ; | |
|
41 | read foo;"\' | |
|
42 | """ % (command, command, command) ) | |
|
37 | os.system(("""xterm -title "%s" -e \'/bin/sh -c "%s ; """ | |
|
38 | """echo; echo press enter to close ; """ | |
|
39 | # """echo \\"\x1b]0;%s (finished -- press enter to close)\x07\\" ; | |
|
40 | """read foo;"\' """) % (command, command) ) | |
|
43 | 41 | |
|
44 | 42 | #------------------------------------------------------------------------------- |
|
45 | 43 | # Frontend class using ipython0 to do the prefiltering. |
@@ -70,8 +68,10 b' class PrefilterFrontEnd(LineFrontEndBase):' | |||
|
70 | 68 | setattr(_ip.IP, 'magic_%s' % alias_name, magic) |
|
71 | 69 | # FIXME: I should create a real file-like object dedicated to this |
|
72 | 70 | # terminal |
|
73 |
self.shell.output_trap = |
|
|
74 |
|
|
|
71 | self.shell.output_trap = OutputTrap( | |
|
72 | out=FileLike(write_callback=self.write), | |
|
73 | err=FileLike(write_callback=self.write), | |
|
74 | ) | |
|
75 | 75 | # Capture and release the outputs, to make sure all the |
|
76 | 76 | # shadow variables are set |
|
77 | 77 | self.capture_output() |
@@ -142,6 +142,7 b' class PrefilterFrontEnd(LineFrontEndBase):' | |||
|
142 | 142 | def complete(self, line): |
|
143 | 143 | word = line.split('\n')[-1].split(' ')[-1] |
|
144 | 144 | completions = self.ipython0.complete(word) |
|
145 | # FIXME: The proper sort should be done in the complete method. | |
|
145 | 146 | key = lambda x: x.replace('_', '') |
|
146 | 147 | completions.sort(key=key) |
|
147 | 148 | if completions: |
@@ -1,6 +1,6 b'' | |||
|
1 | 1 | # encoding: utf-8 |
|
2 | 2 | |
|
3 | """ Redirects stdout/stderr to given write methods.""" | |
|
3 | """ File like object that redirects its write calls to a given callback.""" | |
|
4 | 4 | |
|
5 | 5 | __docformat__ = "restructuredtext en" |
|
6 | 6 | |
@@ -11,12 +11,7 b' __docformat__ = "restructuredtext en"' | |||
|
11 | 11 | # the file COPYING, distributed as part of this software. |
|
12 | 12 | #------------------------------------------------------------------------------- |
|
13 | 13 | |
|
14 | #------------------------------------------------------------------------------- | |
|
15 | # Imports | |
|
16 | #------------------------------------------------------------------------------- | |
|
17 | ||
|
18 | 14 | import sys |
|
19 | from IPython.kernel.core.output_trap import OutputTrap | |
|
20 | 15 | |
|
21 | 16 | class FileLike(object): |
|
22 | 17 | """ FileLike object that redirects all write to a callback. |
@@ -26,8 +21,8 b' class FileLike(object):' | |||
|
26 | 21 | """ |
|
27 | 22 | closed = False |
|
28 | 23 | |
|
29 | def __init__(self, write): | |
|
30 | self.write = write | |
|
24 | def __init__(self, write_callback): | |
|
25 | self.write = write_callback | |
|
31 | 26 | |
|
32 | 27 | def flush(self): |
|
33 | 28 | pass |
@@ -45,23 +40,10 b' class FileLike(object):' | |||
|
45 | 40 | def getvalue(self): |
|
46 | 41 | return '' |
|
47 | 42 | |
|
43 | def reset(self): | |
|
44 | pass | |
|
48 | 45 | |
|
49 | class SyncOutputTrap(OutputTrap): | |
|
50 | """ Object which redirect text sent to stdout and stderr to write | |
|
51 | callbacks. | |
|
52 | """ | |
|
53 | ||
|
54 | def __init__(self, write_out, write_err): | |
|
55 | # Store callbacks | |
|
56 | self.out = FileLike(write_out) | |
|
57 | self.err = FileLike(write_err) | |
|
58 | ||
|
59 | # Boolean to check if the stdout/stderr hook is set. | |
|
60 | self.out_set = False | |
|
61 | self.err_set = False | |
|
62 | ||
|
63 | def clear(self): | |
|
64 | """ Clear out the buffers. | |
|
65 | """ | |
|
46 | def truncate(self): | |
|
66 | 47 | pass |
|
67 | 48 | |
|
49 |
@@ -23,10 +23,16 b' class OutputTrap(object):' | |||
|
23 | 23 | """ Object which can trap text sent to stdout and stderr. |
|
24 | 24 | """ |
|
25 | 25 | |
|
26 | def __init__(self): | |
|
26 | def __init__(self, out=None, err=None): | |
|
27 | 27 | # Filelike objects to store stdout/stderr text. |
|
28 | self.out = StringIO() | |
|
29 |
self. |
|
|
28 | if out is None: | |
|
29 | self.out = StringIO() | |
|
30 | else: | |
|
31 | self.out = out | |
|
32 | if err is None: | |
|
33 | self.err = StringIO() | |
|
34 | else: | |
|
35 | self.err = err | |
|
30 | 36 | |
|
31 | 37 | # Boolean to check if the stdout/stderr hook is set. |
|
32 | 38 | self.out_set = False |
@@ -72,11 +78,11 b' class OutputTrap(object):' | |||
|
72 | 78 | """ Clear out the buffers. |
|
73 | 79 | """ |
|
74 | 80 | |
|
75 |
self.out. |
|
|
76 |
self.out |
|
|
81 | self.out.reset() | |
|
82 | self.out.truncate() | |
|
77 | 83 | |
|
78 |
self.err. |
|
|
79 |
self.err |
|
|
84 | self.err.reset() | |
|
85 | self.err.truncate() | |
|
80 | 86 | |
|
81 | 87 | def add_to_message(self, message): |
|
82 | 88 | """ Add the text from stdout and stderr to the message from the |
General Comments 0
You need to be logged in to leave comments.
Login now