##// END OF EJS Templates
Prompt messages are now implemented for both in/out prompts.
Brian Granger -
Show More
@@ -27,7 +27,7 b' from IPython.config.configurable import Configurable'
27 from IPython.core import prompts
27 from IPython.core import prompts
28 import IPython.utils.generics
28 import IPython.utils.generics
29 import IPython.utils.io
29 import IPython.utils.io
30 from IPython.utils.traitlets import Instance
30 from IPython.utils.traitlets import Instance, Int
31 from IPython.utils.warn import warn
31 from IPython.utils.warn import warn
32
32
33 #-----------------------------------------------------------------------------
33 #-----------------------------------------------------------------------------
@@ -54,6 +54,8 b' class DisplayHook(Configurable):'
54 """
54 """
55
55
56 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC')
56 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC')
57 # Each call to the In[] prompt raises it by 1, even the first.
58 prompt_count = Int(0)
57
59
58 def __init__(self, shell=None, cache_size=1000,
60 def __init__(self, shell=None, cache_size=1000,
59 colors='NoColor', input_sep='\n',
61 colors='NoColor', input_sep='\n',
@@ -100,9 +102,6 b' class DisplayHook(Configurable):'
100 pad_left=pad_left)
102 pad_left=pad_left)
101 self.set_colors(colors)
103 self.set_colors(colors)
102
104
103 # other more normal stuff
104 # b/c each call to the In[] prompt raises it by 1, even the first.
105 self.prompt_count = 0
106 # Store the last prompt string each time, we need it for aligning
105 # Store the last prompt string each time, we need it for aligning
107 # continuation and auto-rewrite prompts
106 # continuation and auto-rewrite prompts
108 self.last_prompt = ''
107 self.last_prompt = ''
@@ -371,7 +371,14 b' class Prompt1(BasePrompt):'
371 # auto-call prompts used in the auto_rewrite() method.
371 # auto-call prompts used in the auto_rewrite() method.
372 self.col_p_ni = self.col_p.replace('\001','').replace('\002','')
372 self.col_p_ni = self.col_p.replace('\001','').replace('\002','')
373 self.col_norm_ni = Colors.normal
373 self.col_norm_ni = Colors.normal
374
374
375 def peek_next_prompt(self):
376 """Get the next prompt, but don't increment the counter."""
377 self.cache.prompt_count += 1
378 next_prompt = str_safe(self.p_str)
379 self.cache.prompt_count -= 1
380 return next_prompt
381
375 def __str__(self):
382 def __str__(self):
376 self.cache.prompt_count += 1
383 self.cache.prompt_count += 1
377 self.cache.last_prompt = str_safe(self.p_str_nocolor).split('\n')[-1]
384 self.cache.last_prompt = str_safe(self.p_str_nocolor).split('\n')[-1]
@@ -352,6 +352,7 b' class FrontendWidget(HistoryConsoleWidget):'
352 # before writing a new prompt.
352 # before writing a new prompt.
353 self.kernel_manager.sub_channel.flush()
353 self.kernel_manager.sub_channel.flush()
354
354
355 # TODO: The reply now has the next_prompt and prompt_number keys.
355 status = reply['content']['status']
356 status = reply['content']['status']
356 if status == 'error':
357 if status == 'error':
357 self._handle_execute_error(reply)
358 self._handle_execute_error(reply)
@@ -16,7 +16,6 b' Things to do:'
16
16
17 # Standard library imports.
17 # Standard library imports.
18 import __builtin__
18 import __builtin__
19 from code import CommandCompiler
20 import os
19 import os
21 import sys
20 import sys
22 import time
21 import time
@@ -31,9 +30,7 b' from IPython.zmq.zmqshell import ZMQInteractiveShell'
31 from IPython.external.argparse import ArgumentParser
30 from IPython.external.argparse import ArgumentParser
32 from IPython.utils.traitlets import Instance
31 from IPython.utils.traitlets import Instance
33 from IPython.zmq.session import Session, Message
32 from IPython.zmq.session import Session, Message
34 from completer import KernelCompleter
35 from iostream import OutStream
33 from iostream import OutStream
36 from displayhook import DisplayHook
37 from exitpoller import ExitPollerUnix, ExitPollerWindows
34 from exitpoller import ExitPollerUnix, ExitPollerWindows
38
35
39 #-----------------------------------------------------------------------------
36 #-----------------------------------------------------------------------------
@@ -58,7 +55,7 b' class Kernel(Configurable):'
58
55
59 # Build dict of handlers for message types
56 # Build dict of handlers for message types
60 msg_types = [ 'execute_request', 'complete_request',
57 msg_types = [ 'execute_request', 'complete_request',
61 'object_info_request' ]
58 'object_info_request', 'prompt_request' ]
62 self.handlers = {}
59 self.handlers = {}
63 for msg_type in msg_types:
60 for msg_type in msg_types:
64 self.handlers[msg_type] = getattr(self, msg_type)
61 self.handlers[msg_type] = getattr(self, msg_type)
@@ -120,7 +117,15 b' class Kernel(Configurable):'
120 reply_content = exc_content
117 reply_content = exc_content
121 else:
118 else:
122 reply_content = {'status' : 'ok'}
119 reply_content = {'status' : 'ok'}
123
120
121 # Compute the prompt information
122 prompt_number = self.shell.displayhook.prompt_count
123 reply_content['prompt_number'] = prompt_number
124 prompt_string = self.shell.displayhook.prompt1.peek_next_prompt()
125 next_prompt = {'prompt_string' : prompt_string,
126 'prompt_number' : prompt_number+1}
127 reply_content['next_prompt'] = next_prompt
128
124 # Flush output before sending the reply.
129 # Flush output before sending the reply.
125 sys.stderr.flush()
130 sys.stderr.flush()
126 sys.stdout.flush()
131 sys.stdout.flush()
@@ -200,6 +205,15 b' class Kernel(Configurable):'
200
205
201 return symbol, []
206 return symbol, []
202
207
208 def prompt_request(self, ident, parent):
209 prompt_number = self.shell.displayhook.prompt_count
210 prompt_string = self.shell.displayhook.prompt1.peek_next_prompt()
211 content = {'prompt_string' : prompt_string,
212 'prompt_number' : prompt_number+1}
213 msg = self.session.send(self.reply_socket, 'prompt_reply',
214 content, parent, ident)
215 print >> sys.__stdout__, msg
216
203 def start(self):
217 def start(self):
204 while True:
218 while True:
205 ident = self.reply_socket.recv()
219 ident = self.reply_socket.recv()
@@ -9,7 +9,7 b' from IPython.utils.traitlets import Instance, Type, Dict'
9 from IPython.zmq.session import extract_header
9 from IPython.zmq.session import extract_header
10
10
11
11
12 class ZMQDisplayTrap(DisplayHook):
12 class ZMQDisplayHook(DisplayHook):
13
13
14 session = Instance('IPython.zmq.session.Session')
14 session = Instance('IPython.zmq.session.Session')
15 pub_socket = Instance('zmq.Socket')
15 pub_socket = Instance('zmq.Socket')
@@ -42,7 +42,7 b' class ZMQDisplayTrap(DisplayHook):'
42 class ZMQInteractiveShell(InteractiveShell):
42 class ZMQInteractiveShell(InteractiveShell):
43 """A subclass of InteractiveShell for ZMQ."""
43 """A subclass of InteractiveShell for ZMQ."""
44
44
45 displayhook_class = Type(ZMQDisplayTrap)
45 displayhook_class = Type(ZMQDisplayHook)
46
46
47 def system(self, cmd):
47 def system(self, cmd):
48 cmd = self.var_expand(cmd, depth=2)
48 cmd = self.var_expand(cmd, depth=2)
General Comments 0
You need to be logged in to leave comments. Login now