Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add stdin to the notebook #3089

Merged
merged 13 commits into from
Apr 26, 2013
Merged

add stdin to the notebook #3089

merged 13 commits into from
Apr 26, 2013

Conversation

minrk
Copy link
Member

@minrk minrk commented Mar 27, 2013

adds a simple stdin handler to the notebook, so things like raw_input and %debug work.

%debug in action:

debug

This PR depends on #3011 and #3088. Incentive!

@minrk
Copy link
Member Author

minrk commented Mar 27, 2013

The main thing remaining to do here is to prevent shift-enter from executing code while the raw_input filed is active. That can mess things up.

@ellisonbg
Copy link
Member

Minor UI comments:

  • The text area used to type stdin should have the font properties as the regular monospace we are using, namely black.
  • We should probably think about how to size the width of the text area.
  • When a user hits return for stdin, it inserts a static version of the prompt and typed text below the input cell. This static version should have the same margins/padding as the actual prompt/text area, so there isn't a jump when a user presses return.

follow example in rename notebook: remove form, bind keydown for enter,
avoiding shift-enter submitting the cell again.
should fix alignment of raw_input and prompt
@@ -507,6 +507,12 @@ def _inject_cookie_message(self, msg):
# under Python 2.x for some reason
msg = msg.encode('utf8', 'replace')
try:
bsession, msg = msg.split(':', 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the identity should be handled at the level of the handler rather than in the JS code and sent to the handler.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed on HipChat, this isn't possible - the identity of the StdIn and Shell sockets must match for input_request routing, and the only thing that has a handle on both at the same time is the Javascript.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name "bsession" is a bit confusing. Can you rename the variable to emphasize that this is the socket identity and provide some comments reminding us why we have to pass this and what it is for.

@ellisonbg
Copy link
Member

Shouldn't some of the channels have an on_message method that is different from the base class (like a pass)?

@ellisonbg
Copy link
Member

I really like the cleanup/refactor of the zmq handlers. Much cleaner and easy to maintain. Amazing how simple it is!

this.iopub_channel.onmessage = $.proxy(this._handle_iopub_reply,this);
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use stdin rather than input to be consistent in the naming?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also below...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's called an input_request, that's the message type. See our message spec

@ellisonbg
Copy link
Member

OK I have reviewed all of the code. Mostly minor comments and a bit of UI cleanup.

@minrk
Copy link
Member Author

minrk commented Apr 25, 2013

When a user hits return for stdin, it inserts a static version of the prompt and typed text below the input cell. This static version should have the same margins/padding as the actual prompt/text area, so there isn't a jump when a user presses return.

I disagree - it should be a plain pre tag for this, but I'm not sure that I can make an input area with zero margins, so I don't think this is possible.

@minrk
Copy link
Member Author

minrk commented Apr 26, 2013

I spoke too soon, the layout should match reasonably well now.

@ellisonbg
Copy link
Member

OK, the look of the input area matches the pre quite well. Great work! Right now the input area is statically sized to 80 cols. When the notebook window is narrower than that, the layout gets messed up. It looks like it would be difficult to make it variable width. Do you think we need the full 80 cols for this?

bsession, msg = msg.split(':', 1)
self.session.session = bsession.decode('ascii')
except Exception:
logging.error("No bsession!", exc_info=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error message is a bit cryptic.

@ellisonbg
Copy link
Member

Any response to the on_message behavior?

@minrk
Copy link
Member Author

minrk commented Apr 26, 2013

As for 80 cols - no, I don't expect it to be needed often, but I don't know how to make it auto-width.

Sorry I didn't comment, but I did set the IOPub on_message to pass, since IOPub downstream messages don't make any sense.

I also fixed the bsession / error message when the first message is not given.

ellisonbg added a commit that referenced this pull request Apr 26, 2013
add stdin to the notebook
@ellisonbg ellisonbg merged commit c3a9044 into ipython:master Apr 26, 2013
tkf added a commit to tkf/emacs-ipython-notebook that referenced this pull request Jul 10, 2013
IPython changed the way to start channel [1].
fixes #121

[1] see commit ipython/ipython@24dcb6b
in ipython/ipython#3089
@minrk minrk deleted the stdin branch March 31, 2014 23:36
mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014
@v0dro v0dro mentioned this pull request Nov 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants