##// 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 27 from IPython.core import prompts
28 28 import IPython.utils.generics
29 29 import IPython.utils.io
30 from IPython.utils.traitlets import Instance
30 from IPython.utils.traitlets import Instance, Int
31 31 from IPython.utils.warn import warn
32 32
33 33 #-----------------------------------------------------------------------------
@@ -54,6 +54,8 b' class DisplayHook(Configurable):'
54 54 """
55 55
56 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 60 def __init__(self, shell=None, cache_size=1000,
59 61 colors='NoColor', input_sep='\n',
@@ -100,9 +102,6 b' class DisplayHook(Configurable):'
100 102 pad_left=pad_left)
101 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 105 # Store the last prompt string each time, we need it for aligning
107 106 # continuation and auto-rewrite prompts
108 107 self.last_prompt = ''
@@ -371,7 +371,14 b' class Prompt1(BasePrompt):'
371 371 # auto-call prompts used in the auto_rewrite() method.
372 372 self.col_p_ni = self.col_p.replace('\001','').replace('\002','')
373 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 382 def __str__(self):
376 383 self.cache.prompt_count += 1
377 384 self.cache.last_prompt = str_safe(self.p_str_nocolor).split('\n')[-1]
@@ -352,6 +352,7 b' class FrontendWidget(HistoryConsoleWidget):'
352 352 # before writing a new prompt.
353 353 self.kernel_manager.sub_channel.flush()
354 354
355 # TODO: The reply now has the next_prompt and prompt_number keys.
355 356 status = reply['content']['status']
356 357 if status == 'error':
357 358 self._handle_execute_error(reply)
@@ -16,7 +16,6 b' Things to do:'
16 16
17 17 # Standard library imports.
18 18 import __builtin__
19 from code import CommandCompiler
20 19 import os
21 20 import sys
22 21 import time
@@ -31,9 +30,7 b' from IPython.zmq.zmqshell import ZMQInteractiveShell'
31 30 from IPython.external.argparse import ArgumentParser
32 31 from IPython.utils.traitlets import Instance
33 32 from IPython.zmq.session import Session, Message
34 from completer import KernelCompleter
35 33 from iostream import OutStream
36 from displayhook import DisplayHook
37 34 from exitpoller import ExitPollerUnix, ExitPollerWindows
38 35
39 36 #-----------------------------------------------------------------------------
@@ -58,7 +55,7 b' class Kernel(Configurable):'
58 55
59 56 # Build dict of handlers for message types
60 57 msg_types = [ 'execute_request', 'complete_request',
61 'object_info_request' ]
58 'object_info_request', 'prompt_request' ]
62 59 self.handlers = {}
63 60 for msg_type in msg_types:
64 61 self.handlers[msg_type] = getattr(self, msg_type)
@@ -120,7 +117,15 b' class Kernel(Configurable):'
120 117 reply_content = exc_content
121 118 else:
122 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 129 # Flush output before sending the reply.
125 130 sys.stderr.flush()
126 131 sys.stdout.flush()
@@ -200,6 +205,15 b' class Kernel(Configurable):'
200 205
201 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 217 def start(self):
204 218 while True:
205 219 ident = self.reply_socket.recv()
@@ -9,7 +9,7 b' from IPython.utils.traitlets import Instance, Type, Dict'
9 9 from IPython.zmq.session import extract_header
10 10
11 11
12 class ZMQDisplayTrap(DisplayHook):
12 class ZMQDisplayHook(DisplayHook):
13 13
14 14 session = Instance('IPython.zmq.session.Session')
15 15 pub_socket = Instance('zmq.Socket')
@@ -42,7 +42,7 b' class ZMQDisplayTrap(DisplayHook):'
42 42 class ZMQInteractiveShell(InteractiveShell):
43 43 """A subclass of InteractiveShell for ZMQ."""
44 44
45 displayhook_class = Type(ZMQDisplayTrap)
45 displayhook_class = Type(ZMQDisplayHook)
46 46
47 47 def system(self, cmd):
48 48 cmd = self.var_expand(cmd, depth=2)
General Comments 0
You need to be logged in to leave comments. Login now