8000 IDLE -- Restrict shell prompt manipulaton to the shell. (#4143) · ultimatecoder/cpython@e86172d · GitHub
[go: up one dir, main page]

Skip to content

Commit e86172d

Browse files
authored
IDLE -- Restrict shell prompt manipulaton to the shell. (python#4143)
Editor and output windows only see an empty last prompt line. This simplifies the code and fixes a minor bug when newline is inserted. Sys.ps1, if present, is read on Shell start-up, but is not set or changed.
1 parent ed6554c commit e86172d

File tree

3 files changed

+19
-24
lines changed

3 files changed

+19
-24
lines changed

Lib/idlelib/editor.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,6 @@ def __init__(self, flist=None, filename=None, key=None, root=None):
9999
self.flist = flist
100100
root = root or flist.root
101101
self.root = root
102-
try:
103-
sys.ps1
104-
except AttributeError:
105-
sys.ps1 = '>>> '
106102
self.menubar = Menu(root)
107103
self.top = top = windows.ListedToplevel(root, menu=self.menubar)
108104
if flist:
@@ -116,6 +112,8 @@ def __init__(self, flist=None, filename=None, key=None, root=None):
116112
self.top.instance_dict = {}
117113
self.recent_files_path = os.path.join(
118114
idleConf.userdir, 'recent-files.lst')
115+
116+
self.prompt_last_line = '' # Override in PyShell
119117
self.text_frame = text_frame = Frame(top)
120118
self.vbar = vbar = Scrollbar(text_frame, name='vbar')
121119
self.width = idleConf.GetOption('main', 'EditorWindow',
@@ -1213,13 +1211,9 @@ def smart_backspace_event(self, event):
12131211
assert have > 0
12141212
want = ((have - 1) // self.indentwidth) * self.indentwidth
12151213
# Debug prompt is multilined....
1216-
if self.context_use_ps1:
1217-
last_line_of_prompt = sys.ps1.split('\n')[-1]
1218-
else:
1219-
last_line_of_prompt = ''
12201214
ncharsdeleted = 0
12211215
while 1:
1222-
if chars == last_line_of_prompt:
1216+
if chars == self.prompt_last_line: # '' unless PyShell
12231217
break
12241218
chars = chars[:-1]
12251219
ncharsdeleted = ncharsdeleted + 1
@@ -1288,8 +1282,7 @@ def newline_and_indent_event(self, event):
12881282
indent = line[:i]
12891283
# strip whitespace before insert point unless it's in the prompt
12901284
i = 0
1291-
last_line_of_prompt = sys.ps1.split('\n')[-1]
1292-
while line and line[-1] in " \t" and line != last_line_of_prompt:
1285+
while line and line[-1] in " \t" and line != self.prompt_last_line:
12931286
line = line[:-1]
12941287
i = i+1
12951288
if i:

Lib/idlelib/pyshell.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -857,15 +857,17 @@ def __init__(self, flist=None):
857857
fixwordbreaks(root)
858858
root.withdraw()
859859
flist = PyShellFileList(root)
860-
#
860+
861861
OutputWindow.__init__(self, flist, None, None)
862-
#
863-
## self.config(usetabs=1, indentwidth=8, context_use_ps1=1)
862+
864863
self.usetabs = True
865864
# indentwidth must be 8 when using tabs. See note in EditorWindow:
866865
self.indentwidth = 8
867-
self.context_use_ps1 = True
868-
#
866+
867+
self.sys_ps1 = sys.ps1 if hasattr(sys, 'ps1') else '>>> '
868+
self.prompt_last_line = self.sys_ps1.split('\n')[-1]
869+
self.prompt = self.sys_ps1 # Changes when debug active
870+
869871
text = self.text
870872
text.configure(wrap="char")
871873
text.bind("<<newline-and-indent>>", self.enter_callback)
@@ -878,7 +880,7 @@ def __init__(self, flist=None):
878880
if use_subprocess:
879881
text.bind("<<view-restart>>", self.view_restart_mark)
880882
text.bind("<<restart-shell>>", self.restart_shell)
881-
#
883+
882884
self.save_stdout = sys.stdout
883885
self.save_stderr = sys.stderr
884886
self.save_stdin = sys.stdin
@@ -951,7 +953,7 @@ def close_debugger(self):
951953
debugger_r.close_remote_debugger(self.interp.rpcclt)
952954
self.resetoutput()
953955
self.console.write("[DEBUG OFF]\n")
954-
sys.ps1 = ">>> "
956+
self.prompt = self.sys_ps1
955957
self.showprompt()
956958
self.set_debugger_indicator()
957959

@@ -963,7 +965,7 @@ def open_debugger(self):
963965
dbg_gui = debugger.Debugger(self)
964966
self.interp.setdebugger(dbg_gui)
965967
dbg_gui.load_breakpoints()
966-
sys.ps1 = "[DEBUG ON]\n>>> "
968+
self.prompt = "[DEBUG ON]\n" + self.sys_ps1
967969
self.showprompt()
968970
self.set_debugger_indicator()
969971

@@ -1248,11 +1250,7 @@ def restart_shell(self, event=None):
12481250

12491251
def showprompt(self):
12501252
self.resetoutput()
1251-
try:
1252-
s = str(sys.ps1)
1253-
except:
1254-
s = ""
1255-
self.console.write(s)
1253+
self.console.write(self.prompt)
12561254
self.text.mark_set("insert", "end-1c")
12571255
self.set_line_and_column()
12581256
self.io.reset_undo()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
IDLE -- Restrict shell prompt manipulaton to the shell. Editor and output
2+
windows only see an empty last prompt line. This simplifies the code and
3+
fixes a minor bug when newline is inserted. Sys.ps1, if present, is read on
4+
Shell start-up, but is not set or changed.

0 commit comments

Comments
 (0)
0