diff --git a/IPython/frontend/html/notebook/static/js/codecell.js b/IPython/frontend/html/notebook/static/js/codecell.js index a280ed2a4..6ce4e4f6c 100644 --- a/IPython/frontend/html/notebook/static/js/codecell.js +++ b/IPython/frontend/html/notebook/static/js/codecell.js @@ -245,7 +245,8 @@ var IPython = (function (IPython) { 'execute_reply': $.proxy(this._handle_execute_reply, this), 'output': $.proxy(this.output_area.handle_output, this.output_area), 'clear_output': $.proxy(this.output_area.handle_clear_output, this.output_area), - 'set_next_input': $.proxy(this._handle_set_next_input, this) + 'set_next_input': $.proxy(this._handle_set_next_input, this), + 'input_request': $.proxy(this._handle_input_request, this) }; var msg_id = this.kernel.execute(this.get_text(), callbacks, {silent: false}); }; @@ -260,10 +261,23 @@ var IPython = (function (IPython) { $([IPython.events]).trigger('set_dirty.Notebook', {'value': true}); } + /** + * @method _handle_set_next_input + * @private + */ CodeCell.prototype._handle_set_next_input = function (text) { var data = {'cell': this, 'text': text} $([IPython.events]).trigger('set_next_input.Notebook', data); } + + /** + * @method _handle_input_request + * @private + */ + CodeCell.prototype._handle_input_request = function (content) { + this.output_area.append_raw_input(content); + } + // Basic cell manipulation. diff --git a/IPython/frontend/html/notebook/static/js/kernel.js b/IPython/frontend/html/notebook/static/js/kernel.js index 4bd1cfd7a..162764aeb 100644 --- a/IPython/frontend/html/notebook/static/js/kernel.js +++ b/IPython/frontend/html/notebook/static/js/kernel.js @@ -168,6 +168,10 @@ var IPython = (function (IPython) { this.shell_channel.onmessage = $.proxy(this._handle_shell_reply, this); this.iopub_channel.onmessage = $.proxy(this._handle_iopub_reply, this); this.stdin_channel.onmessage = $.proxy(this._handle_input_request, this); + + $([IPython.events]).on('send_input_reply.Kernel', function(evt, data) { + that.send_input_reply(data); + }); }; /** @@ -283,8 +287,11 @@ var IPython = (function (IPython) { silent : true, user_variables : [], user_expressions : {}, - allow_stdin : true + allow_stdin : false }; + if (callbacks.input_request !== undefined) { + content.allow_stdin = true; + } $.extend(true, content, options) $([IPython.events]).trigger('execution_request.Kernel', {kernel: this, content:content}); var msg = this._get_msg("execute_request", content); @@ -344,8 +351,7 @@ var IPython = (function (IPython) { }; }; - Kernel.prototype.send_input_reply = function (input, header) { - + Kernel.prototype.send_input_reply = function (input) { var content = { value : input, }; @@ -447,7 +453,6 @@ var IPython = (function (IPython) { Kernel.prototype._handle_input_request = function (e) { var request = $.parseJSON(e.data); - console.log("input", request); var header = request.header; var content = request.content; var metadata = request.metadata; @@ -456,7 +461,13 @@ var IPython = (function (IPython) { console.log("Invalid input request!", request); return; } - $([IPython.events]).trigger('input_request.Kernel', {kernel: this, request:request}); + var callbacks = this.get_callbacks_for_msg(request.parent_header.msg_id); + if (callbacks !== undefined) { + var cb = callbacks[msg_type]; + if (cb !== undefined) { + cb(content, metadata); + } + }; }; diff --git a/IPython/frontend/html/notebook/static/js/notebook.js b/IPython/frontend/html/notebook/static/js/notebook.js index b81109dd8..52c50cd43 100644 --- a/IPython/frontend/html/notebook/static/js/notebook.js +++ b/IPython/frontend/html/notebook/static/js/notebook.js @@ -115,34 +115,6 @@ var IPython = (function (IPython) { var index = that.find_cell_index(data.cell); that.select(index); }); - $([IPython.events]).on('input_request.Kernel', function (event, data) { - var dialog = $('
').attr('id','input_form').append( - $('') - .attr("action", "javascript:$('#input_form').parent().find('button').click();") - .append( - $('') - .attr('id', 'input_prompt_dialog') - .attr('type', 'text') - .attr('name', 'input') - )); - $(document).append(dialog); - dialog.dialog({ - resizable: false, - modal: true, - title: data.request.content.prompt, - closeText: '', - buttons : { - "Okay": function () { - IPython.notebook.kernel.send_input_reply( - $("input#input_prompt_dialog").attr('value'), - data.request.header - ); - $(this).dialog('close'); - dialog.remove(); - } - } - }); - }); $(document).keydown(function (event) { diff --git a/IPython/frontend/html/notebook/static/js/outputarea.js b/IPython/frontend/html/notebook/static/js/outputarea.js index 5a11dd285..18c8c8f30 100644 --- a/IPython/frontend/html/notebook/static/js/outputarea.js +++ b/IPython/frontend/html/notebook/static/js/outputarea.js @@ -74,6 +74,7 @@ var IPython = (function (IPython) { OutputArea.prototype.bind_events = function () { var that = this; + this._submit_raw_input_proxy = $.proxy(this._submit_raw_input, this); this.prompt_overlay.dblclick(function () { that.toggle_output(); }); this.prompt_overlay.click(function () { that.toggle_scroll(); }); @@ -448,6 +449,51 @@ var IPython = (function (IPython) { toinsert.append(latex); element.append(toinsert); }; + + OutputArea.prototype.append_raw_input = function (content) { + this.expand(); + this.flush_clear_timeout(); + var area = this.create_output_area(); + area.append( + $("") + .addClass("box-flex1 output_subarea raw_input") + .append( + $("") + .attr("action", "javascript:$([IPython.events]).trigger('submit_raw_input.OutputArea');") + .append( + $("") + .addClass("input_prompt") + .text(content.prompt) + ).append( + $("") + .attr("size", 80) + .addClass("raw_input") + ) + ) + ) + // clear events first + $([IPython.events]).off('submit_raw_input.OutputArea'); + $([IPython.events]).on('submit_raw_input.OutputArea', this._submit_raw_input_proxy); + this.element.append(area); + area.find("input.raw_input").focus(); + } + OutputArea.prototype._submit_raw_input = function (evt) { + var container = this.element.find("div.raw_input"); + var theprompt = container.find("span.input_prompt"); + var theinput = container.find("input.raw_input"); + var value = theinput.attr("value"); + var content = { + output_type : 'stream', + name : 'stdout', + text : theprompt.text() + value + '\n' + } + // remove form container + container.parent().remove(); + // replace with plaintext version in stdout + this.append_output(content, false); + $([IPython.events]).off('submit_raw_input.OutputArea', this._submit_raw_input_proxy); + $([IPython.events]).trigger('send_input_reply.Kernel', value); + } OutputArea.prototype.handle_clear_output = function (content) { diff --git a/IPython/frontend/html/notebook/static/less/notebook.less b/IPython/frontend/html/notebook/static/less/notebook.less index eb88ea0b6..4d1cc9ce9 100644 --- a/IPython/frontend/html/notebook/static/less/notebook.less +++ b/IPython/frontend/html/notebook/static/less/notebook.less @@ -476,4 +476,12 @@ margin-bottom:0; a.heading-anchor:link, a.heading-anchor:visited { text-decoration: none; color: inherit; + +/* raw_input styles */ + +span.input_prompt { + font-family: monospace; +} +input.raw_input { + width: auto; }