##// END OF EJS Templates
Rework multiline input
Gael Varoquaux -
Show More
@@ -28,9 +28,6 b' from IPython.kernel.core.interpreter import Interpreter'
28 #-------------------------------------------------------------------------------
28 #-------------------------------------------------------------------------------
29 class LineFrontEndBase(FrontEndBase):
29 class LineFrontEndBase(FrontEndBase):
30
30
31 # Are we entering multi line input?
32 multi_line_input = False
33
34 # We need to keep the prompt number, to be able to increment
31 # We need to keep the prompt number, to be able to increment
35 # it when there is an exception.
32 # it when there is an exception.
36 prompt_number = 1
33 prompt_number = 1
@@ -90,7 +87,8 b' class LineFrontEndBase(FrontEndBase):'
90
87
91
88
92 def is_complete(self, string):
89 def is_complete(self, string):
93 if ( self.multi_line_input and not re.findall(r"\n[\t ]*$", string)):
90 if ( len(self.get_current_edit_buffer().split('\n'))>1
91 and not re.findall(r"\n[\t ]*$", string)):
94 return False
92 return False
95 else:
93 else:
96 return FrontEndBase.is_complete(self, string)
94 return FrontEndBase.is_complete(self, string)
@@ -113,7 +111,6 b' class LineFrontEndBase(FrontEndBase):'
113 finally:
111 finally:
114 self.prompt_number += 1
112 self.prompt_number += 1
115 self.new_prompt(self.prompt % (result['number'] + 1))
113 self.new_prompt(self.prompt % (result['number'] + 1))
116 self.multi_line_input = False
117 # Start a new empty history entry
114 # Start a new empty history entry
118 self._add_history(None, '')
115 self._add_history(None, '')
119 # The result contains useful information that can be used
116 # The result contains useful information that can be used
@@ -130,10 +127,9 b' class LineFrontEndBase(FrontEndBase):'
130 if self.is_complete(cleaned_buffer):
127 if self.is_complete(cleaned_buffer):
131 self.execute(cleaned_buffer, raw_string=current_buffer)
128 self.execute(cleaned_buffer, raw_string=current_buffer)
132 else:
129 else:
133 if self.multi_line_input:
130 if len(current_buffer.split('\n'))>1:
134 self.write('\n' + self._get_indent_string(current_buffer))
131 self.write('\n' + self._get_indent_string(current_buffer))
135 else:
132 else:
136 self.multi_line_input = True
137 self.write('\n\t')
133 self.write('\n\t')
138
134
139
135
@@ -142,6 +138,7 b' class LineFrontEndBase(FrontEndBase):'
142 #--------------------------------------------------------------------------
138 #--------------------------------------------------------------------------
143
139
144 def _get_indent_string(self, string):
140 def _get_indent_string(self, string):
141 print >>sys.__stderr__, string.split('\n')
145 string = string.split('\n')[-1]
142 string = string.split('\n')[-1]
146 indent_chars = len(string) - len(string.lstrip())
143 indent_chars = len(string) - len(string.lstrip())
147 indent_string = '\t'*(indent_chars // 4) + \
144 indent_string = '\t'*(indent_chars // 4) + \
@@ -232,7 +232,9 b' class ConsoleWidget(editwindow.EditWindow):'
232 # now we update our cursor giving end of prompt
232 # now we update our cursor giving end of prompt
233 self.current_prompt_pos = self.GetLength()
233 self.current_prompt_pos = self.GetLength()
234 self.current_prompt_line = self.GetCurrentLine()
234 self.current_prompt_line = self.GetCurrentLine()
235
235 wx.Yield()
236 self.EnsureCaretVisible()
237
236
238
237 def replace_current_edit_buffer(self, text):
239 def replace_current_edit_buffer(self, text):
238 """ Replace currently entered command line with given text.
240 """ Replace currently entered command line with given text.
@@ -309,6 +311,7 b' class ConsoleWidget(editwindow.EditWindow):'
309 maxrange = self.GetScrollRange(wx.VERTICAL)
311 maxrange = self.GetScrollRange(wx.VERTICAL)
310 self.ScrollLines(maxrange)
312 self.ScrollLines(maxrange)
311
313
314
312 def _on_enter(self):
315 def _on_enter(self):
313 """ Called when the return key is hit.
316 """ Called when the return key is hit.
314 """
317 """
General Comments 0
You need to be logged in to leave comments. Login now