summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib/pyshell.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-08-02 06:14:19 (GMT)
committerGitHub <noreply@github.com>2022-08-02 06:14:19 (GMT)
commit8570f6d1a09a71e11f860fdb6f338f48995b5b36 (patch)
treeab2b380de00f841ae13d2ed4192c84de361dcfbd /Lib/idlelib/pyshell.py
parent118851b8baf3bfe87f073b3b2f495de5dd8b8f84 (diff)
downloadcpython-8570f6d1a09a71e11f860fdb6f338f48995b5b36.zip
cpython-8570f6d1a09a71e11f860fdb6f338f48995b5b36.tar.gz
cpython-8570f6d1a09a71e11f860fdb6f338f48995b5b36.tar.bz2
gh-95191: IDLE: Include prompts when saving Shell GH-95554 (#95557)
(cherry picked from commit b85411fc5e9e223a6bd44f89f674ee3b2e29b99e) Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Diffstat (limited to 'Lib/idlelib/pyshell.py')
-rwxr-xr-xLib/idlelib/pyshell.py35
1 files changed, 19 insertions, 16 deletions
diff --git a/Lib/idlelib/pyshell.py b/Lib/idlelib/pyshell.py
index 3806122..e68233a 100755
--- a/Lib/idlelib/pyshell.py
+++ b/Lib/idlelib/pyshell.py
@@ -986,6 +986,23 @@ class PyShell(OutputWindow):
def get_standard_extension_names(self):
return idleConf.GetExtensions(shell_only=True)
+ def get_prompt_text(self, first, last):
+ """Return text between first and last with prompts added."""
+ text = self.text.get(first, last)
+ lineno_range = range(
+ int(float(first)),
+ int(float(last))
+ )
+ prompts = [
+ self.shell_sidebar.line_prompts.get(lineno)
+ for lineno in lineno_range
+ ]
+ return "\n".join(
+ line if prompt is None else f"{prompt} {line}"
+ for prompt, line in zip(prompts, text.splitlines())
+ ) + "\n"
+
+
def copy_with_prompts_callback(self, event=None):
"""Copy selected lines to the clipboard, with prompts.
@@ -1002,23 +1019,9 @@ class PyShell(OutputWindow):
sellast = text.index('sel.last')
if sellast[-1] != '0':
sellast = text.index("sel.last+1line linestart")
-
- selected_text = self.text.get(selfirst, sellast)
- selection_lineno_range = range(
- int(float(selfirst)),
- int(float(sellast))
- )
- prompts = [
- self.shell_sidebar.line_prompts.get(lineno)
- for lineno in selection_lineno_range
- ]
- selected_text_with_prompts = "\n".join(
- line if prompt is None else f"{prompt} {line}"
- for prompt, line in zip(prompts, selected_text.splitlines())
- ) + "\n"
-
text.clipboard_clear()
- text.clipboard_append(selected_text_with_prompts)
+ prompt_text = self.get_prompt_text(selfirst, sellast)
+ text.clipboard_append(prompt_text)
reading = False
executing = False