diff --git a/IPython/core/display.py b/IPython/core/display.py index 32ffb11..724d164 100644 --- a/IPython/core/display.py +++ b/IPython/core/display.py @@ -657,35 +657,15 @@ class Image(DisplayObject): return unicode(s.split('.')[-1].lower()) -def clear_output(stdout=True, stderr=True, other=True): - """Clear the output of the current cell receiving output. - - Optionally, each of stdout/stderr or other non-stream data (e.g. anything - produced by display()) can be excluded from the clear event. - - By default, everything is cleared. - - Parameters - ---------- - stdout : bool [default: True] - Whether to clear stdout. - stderr : bool [default: True] - Whether to clear stderr. - other : bool [default: True] - Whether to clear everything else that is not stdout/stderr - (e.g. figures,images,HTML, any result of display()). - """ +def clear_output(): + """Clear the output of the current cell receiving output.""" from IPython.core.interactiveshell import InteractiveShell if InteractiveShell.initialized(): - InteractiveShell.instance().display_pub.clear_output( - stdout=stdout, stderr=stderr, other=other, - ) + InteractiveShell.instance().display_pub.clear_output() else: from IPython.utils import io - if stdout: - print('\033[2K\r', file=io.stdout, end='') - io.stdout.flush() - if stderr: - print('\033[2K\r', file=io.stderr, end='') - io.stderr.flush() + print('\033[2K\r', file=io.stdout, end='') + io.stdout.flush() + print('\033[2K\r', file=io.stderr, end='') + io.stderr.flush() diff --git a/IPython/core/displaypub.py b/IPython/core/displaypub.py index 254a5d5..f351730 100644 --- a/IPython/core/displaypub.py +++ b/IPython/core/displaypub.py @@ -108,14 +108,12 @@ class DisplayPublisher(Configurable): if 'text/plain' in data: print(data['text/plain'], file=io.stdout) - def clear_output(self, stdout=True, stderr=True, other=True): + def clear_output(self): """Clear the output of the cell receiving output.""" - if stdout: - print('\033[2K\r', file=io.stdout, end='') - io.stdout.flush() - if stderr: - print('\033[2K\r', file=io.stderr, end='') - io.stderr.flush() + print('\033[2K\r', file=io.stdout, end='') + io.stdout.flush() + print('\033[2K\r', file=io.stderr, end='') + io.stderr.flush() class CapturingDisplayPublisher(DisplayPublisher): @@ -125,8 +123,8 @@ class CapturingDisplayPublisher(DisplayPublisher): def publish(self, source, data, metadata=None): self.outputs.append((source, data, metadata)) - def clear_output(self, stdout=True, stderr=True, other=True): - super(CapturingDisplayPublisher, self).clear_output(stdout, stderr, other) + def clear_output(self): + super(CapturingDisplayPublisher, self).clear_output() if other: # empty the list, *do not* reassign a new list del self.outputs[:] diff --git a/IPython/html/static/notebook/js/codecell.js b/IPython/html/static/notebook/js/codecell.js index 492b902..3ccc9f8 100644 --- a/IPython/html/static/notebook/js/codecell.js +++ b/IPython/html/static/notebook/js/codecell.js @@ -240,7 +240,7 @@ var IPython = (function (IPython) { * @method execute */ CodeCell.prototype.execute = function () { - this.output_area.clear_output(true, true, true); + this.output_area.clear_output(); this.set_input_prompt('*'); this.element.addClass("running"); var callbacks = { @@ -386,8 +386,8 @@ var IPython = (function (IPython) { }; - CodeCell.prototype.clear_output = function (stdout, stderr, other) { - this.output_area.clear_output(stdout, stderr, other); + CodeCell.prototype.clear_output = function () { + this.output_area.clear_output(); }; diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js index e4be4dd..88891ac 100644 --- a/IPython/html/static/notebook/js/notebook.js +++ b/IPython/html/static/notebook/js/notebook.js @@ -1339,7 +1339,7 @@ var IPython = (function (IPython) { var cells = this.get_cells(); for (var i=0; i= 0; i--) { - var out = this.outputs[i]; - var output_type = out.output_type; - if (output_type == "display_data" && other) { - this.outputs.splice(i,1); - } else if (output_type == "stream") { - if (stdout && out.stream == "stdout") { - this.outputs.splice(i,1); - } else if (stderr && out.stream == "stderr") { - this.outputs.splice(i,1); - } - } - } + return; }; diff --git a/IPython/kernel/zmq/zmqshell.py b/IPython/kernel/zmq/zmqshell.py index 27d8113..5b0bfb0 100644 --- a/IPython/kernel/zmq/zmqshell.py +++ b/IPython/kernel/zmq/zmqshell.py @@ -86,14 +86,11 @@ class ZMQDisplayPublisher(DisplayPublisher): parent=self.parent_header, ident=self.topic, ) - def clear_output(self, stdout=True, stderr=True, other=True): - content = dict(stdout=stdout, stderr=stderr, other=other) - - if stdout: - print('\r', file=sys.stdout, end='') - if stderr: - print('\r', file=sys.stderr, end='') - + def clear_output(self): + content = {} + + print('\r', file=sys.stdout, end='') + print('\r', file=sys.stderr, end='') self._flush_streams() self.session.send( diff --git a/examples/widgets/directview/directview.js b/examples/widgets/directview/directview.js index 7eed2ad..37c6ab4 100644 --- a/examples/widgets/directview/directview.js +++ b/examples/widgets/directview/directview.js @@ -108,7 +108,7 @@ DirectViewWidget.prototype.set_kernel = function (kernel) { DirectViewWidget.prototype.execute = function () { - this.output_area.clear_output(true, true, true); + this.output_area.clear_output(); this.element.addClass("running"); var callbacks = { 'execute_reply': $.proxy(this._handle_execute_reply, this),