Show More
@@ -17,6 +17,8 b' Authors:' | |||||
17 | # Imports |
|
17 | # Imports | |
18 | #----------------------------------------------------------------------------- |
|
18 | #----------------------------------------------------------------------------- | |
19 |
|
19 | |||
|
20 | from __future__ import print_function | |||
|
21 | ||||
20 | from xml.dom import minidom |
|
22 | from xml.dom import minidom | |
21 |
|
23 | |||
22 | from .displaypub import ( |
|
24 | from .displaypub import ( | |
@@ -496,6 +498,16 b' def clear_output(stdout=True, stderr=True, other=True):' | |||||
496 | (e.g. figures,images,HTML, any result of display()). |
|
498 | (e.g. figures,images,HTML, any result of display()). | |
497 | """ |
|
499 | """ | |
498 | from IPython.core.interactiveshell import InteractiveShell |
|
500 | from IPython.core.interactiveshell import InteractiveShell | |
499 | InteractiveShell.instance().display_pub.clear_output( |
|
501 | if InteractiveShell.initialized(): | |
500 | stdout=stdout, stderr=stderr, other=other, |
|
502 | InteractiveShell.instance().display_pub.clear_output( | |
501 | ) |
|
503 | stdout=stdout, stderr=stderr, other=other, | |
|
504 | ) | |||
|
505 | else: | |||
|
506 | from IPython.utils import io | |||
|
507 | if stdout: | |||
|
508 | print('\033[2K\r', file=io.stdout, end='') | |||
|
509 | io.stdout.flush() | |||
|
510 | if stderr: | |||
|
511 | print('\033[2K\r', file=io.stderr, end='') | |||
|
512 | io.stderr.flush() | |||
|
513 |
@@ -30,6 +30,7 b' Authors:' | |||||
30 | from __future__ import print_function |
|
30 | from __future__ import print_function | |
31 |
|
31 | |||
32 | from IPython.config.configurable import Configurable |
|
32 | from IPython.config.configurable import Configurable | |
|
33 | from IPython.utils import io | |||
33 |
|
34 | |||
34 | #----------------------------------------------------------------------------- |
|
35 | #----------------------------------------------------------------------------- | |
35 | # Main payload class |
|
36 | # Main payload class | |
@@ -99,14 +100,20 b' class DisplayPublisher(Configurable):' | |||||
99 | arbitrary key, value pairs that frontends can use to interpret |
|
100 | arbitrary key, value pairs that frontends can use to interpret | |
100 | the data. |
|
101 | the data. | |
101 | """ |
|
102 | """ | |
102 | from IPython.utils import io |
|
103 | ||
103 | # The default is to simply write the plain text data using io.stdout. |
|
104 | # The default is to simply write the plain text data using io.stdout. | |
104 | if data.has_key('text/plain'): |
|
105 | if data.has_key('text/plain'): | |
105 | print(data['text/plain'], file=io.stdout) |
|
106 | print(data['text/plain'], file=io.stdout) | |
106 |
|
107 | |||
107 |
|
|
108 | def clear_output(self, stdout=True, stderr=True, other=True): | |
108 |
|
|
109 | """Clear the output of the cell receiving output.""" | |
109 | pass |
|
110 | if stdout: | |
|
111 | print('\033[2K\r', file=io.stdout, end='') | |||
|
112 | io.stdout.flush() | |||
|
113 | if stderr: | |||
|
114 | print('\033[2K\r', file=io.stderr, end='') | |||
|
115 | io.stderr.flush() | |||
|
116 | ||||
110 |
|
117 | |||
111 |
|
118 | |||
112 | def publish_display_data(source, data, metadata=None): |
|
119 | def publish_display_data(source, data, metadata=None): |
@@ -81,8 +81,15 b' class ZMQDisplayPublisher(DisplayPublisher):' | |||||
81 | ) |
|
81 | ) | |
82 |
|
82 | |||
83 | def clear_output(self, stdout=True, stderr=True, other=True): |
|
83 | def clear_output(self, stdout=True, stderr=True, other=True): | |
84 | self._flush_streams() |
|
|||
85 | content = dict(stdout=stdout, stderr=stderr, other=other) |
|
84 | content = dict(stdout=stdout, stderr=stderr, other=other) | |
|
85 | ||||
|
86 | if stdout: | |||
|
87 | print('\r', file=sys.stdout, end='') | |||
|
88 | if stderr: | |||
|
89 | print('\r', file=sys.stderr, end='') | |||
|
90 | ||||
|
91 | self._flush_streams() | |||
|
92 | ||||
86 | self.session.send( |
|
93 | self.session.send( | |
87 | self.pub_socket, u'clear_output', content, |
|
94 | self.pub_socket, u'clear_output', content, | |
88 | parent=self.parent_header |
|
95 | parent=self.parent_header |
General Comments 0
You need to be logged in to leave comments.
Login now