M EditorWindow.py

M PyShell.py

1. PyShell Rev 1.39, EditorWindow Rev 1.37 fix was not handling a
   multiline prompt.
2. The same fix introduced a bug where hitting <enter> at a previous
   prompt-only line would copy the prompt to the iomark.
3. Move the setting of sys.ps1 earlier, into PyShell.main(), to allow
   this code to work before a shell is started up.
4. If cursor is on the input line in the prompt, and you hit <enter>,
   process the line instead of complaining.
5. If line has no stdin range (this includes the last line before shell
   restart) strip any prompt before recalling.
This commit is contained in:
Kurt B. Kaiser 2002-12-29 22:03:38 +00:00
parent af72d5221f
commit 4ada7ad3bc
2 changed files with 20 additions and 16 deletions

View file

@ -952,9 +952,11 @@ class EditorWindow:
have = len(chars.expandtabs(tabwidth)) have = len(chars.expandtabs(tabwidth))
assert have > 0 assert have > 0
want = ((have - 1) // self.indentwidth) * self.indentwidth want = ((have - 1) // self.indentwidth) * self.indentwidth
# Debug prompt is multilined....
last_line_of_prompt = sys.ps1.split('\n')[-1]
ncharsdeleted = 0 ncharsdeleted = 0
while 1: while 1:
if chars == sys.ps1: if chars == last_line_of_prompt:
break break
chars = chars[:-1] chars = chars[:-1]
ncharsdeleted = ncharsdeleted + 1 ncharsdeleted = ncharsdeleted + 1
@ -1011,19 +1013,18 @@ class EditorWindow:
text.mark_set("insert", first) text.mark_set("insert", first)
line = text.get("insert linestart", "insert") line = text.get("insert linestart", "insert")
i, n = 0, len(line) i, n = 0, len(line)
if line == sys.ps1:
return "break"
while i < n and line[i] in " \t": while i < n and line[i] in " \t":
i = i+1 i = i+1
if i == n: if i == n:
# the cursor is in or at leading indentation; just inject # the cursor is in or at leading indentation in a continuation
# an empty line at the start # line; just inject an empty line at the start
text.insert("insert linestart", '\n') text.insert("insert linestart", '\n')
return "break" return "break"
indent = line[:i] indent = line[:i]
# strip whitespace before insert point # strip whitespace before insert point unless it's in the prompt
i = 0 i = 0
while line and line[-1] in " \t": last_line_of_prompt = sys.ps1.split('\n')[-1]
while line and line[-1] in " \t" and line != last_line_of_prompt:
line = line[:-1] line = line[:-1]
i = i+1 i = i+1
if i: if i:

View file

@ -825,10 +825,6 @@ class PyShell(OutputWindow):
self.write("Python %s on %s\n%s\nIDLEfork %s\n" % self.write("Python %s on %s\n%s\nIDLEfork %s\n" %
(sys.version, sys.platform, self.COPYRIGHT, (sys.version, sys.platform, self.COPYRIGHT,
idlever.IDLE_VERSION)) idlever.IDLE_VERSION))
try:
sys.ps1
except AttributeError:
sys.ps1 = ">>> "
self.showprompt() self.showprompt()
import Tkinter import Tkinter
Tkinter._default_root = None Tkinter._default_root = None
@ -943,14 +939,17 @@ class PyShell(OutputWindow):
if next and self.text.compare("insert lineend", ">=", next[0]): if next and self.text.compare("insert lineend", ">=", next[0]):
self.recall(self.text.get(next[0], next[1])) self.recall(self.text.get(next[0], next[1]))
return "break" return "break"
# No stdin mark -- just get the current line # No stdin mark -- just get the current line, less any prompt
self.recall(self.text.get("insert linestart", "insert lineend")) line = self.text.get("insert linestart", "insert lineend")
last_line_of_prompt = sys.ps1.split('\n')[-1]
if line.startswith(last_line_of_prompt):
line = line[len(last_line_of_prompt):]
self.recall(line)
return "break" return "break"
# If we're between the beginning of the line and the iomark, i.e. # If we're between the beginning of the line and the iomark, i.e.
# in the prompt area, complain. # in the prompt area, move to the end of the prompt
if self.text.compare("insert", "<", "iomark"): if self.text.compare("insert", "<", "iomark"):
self.text.bell() self.text.mark_set("insert", "iomark")
return "break"
# If we're in the current input and there's only whitespace # If we're in the current input and there's only whitespace
# beyond the cursor, erase that whitespace first # beyond the cursor, erase that whitespace first
s = self.text.get("insert", "end-1c") s = self.text.get("insert", "end-1c")
@ -1135,6 +1134,10 @@ def main():
cmd = None cmd = None
script = None script = None
startup = False startup = False
try:
sys.ps1
except AttributeError:
sys.ps1 = '>>> '
try: try:
opts, args = getopt.getopt(sys.argv[1:], "c:deihr:st:") opts, args = getopt.getopt(sys.argv[1:], "c:deihr:st:")
except getopt.error, msg: except getopt.error, msg: