Thanks to visit codestin.com
Credit goes to github.com

Skip to content

IDLE: usually include prompts when save or copy shell #95191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
terryjreedy opened this issue Jul 24, 2022 · 2 comments · Fixed by #95558, #95554 or #95557
Closed

IDLE: usually include prompts when save or copy shell #95191

terryjreedy opened this issue Jul 24, 2022 · 2 comments · Fixed by #95558, #95554 or #95557
Labels
3.10 only security fixes 3.11 only security fixes 3.12 only security fixes topic-IDLE type-bug An unexpected behavior, bug, or error

Comments

@terryjreedy
Copy link
Member

Up through 3.9, saving the shell saved saved the contents of the underlying text widget, which saved user input with the primary prompt and weird indents. In 3.10, the primary prompt was moved to a sidebar and secondary prompts added, allowing proper indents in the text widget. However, we left File => Save as saving the text widget text, which meant saving without the prompts. Keeping the same implementation changed the result. Prompted by a complaint by Raymond Hettinger, I regard this as a regression whose fix, by including prompts as the default mode of saving, is a high priority.

Saving both input and output without prompts had no precedent and does not seem useful, so I don't plan to keep it as an option. A useful option, already intended, is to save only code and that without prompts, so the saved code can be loaded into an editor. A possible variation would be to include output as comment blocks. Either way, this is a separate issue.

Selecting and copying is a bit trickier. In 3.9, one could select a single statement (and maybe its output) with or without the leading '>>>'. Selecting multiple statements necessarily included any output, uncommented, and prompts after the first. In 3.10, one can select text in the text area, as normal, or select lines in the sidebar with click and drag. Right click offers 2 copy options: 'copy' copies the selection as is; 'copy with prompts' extends any incomplete lines and adds prompts to input lines. Extending the lines makes the selection the same as if it had been done by a sidebar click and drag. (Adding a 'copy code' option, as discussed above, would be part of a separate issue.) I intend to keep both options, but change 'copy' to 'copy as is' or 'copy selection' and put it second.

Currently Edit=>Copy (or its hotkey, such as ^-C) copies as is. For people who select more than just one statement, this is a regression and adding prompts would be much better. When one selects at most one statement, adding a prompt might be surprising and unwanted.

We could split the Edit Copy option into 'Copy with prompts' and 'Copy as is'. (But see below.) If we do, which should get ^-C or current equivalent as hotkey. Adding another hotkey for the other is possible, but somewhat of a pain. Removing it later would be even more painful. (Again, see below.)

@rhettinger If we do not split Edit Copy, which copy option should it do? If we do split it, what should the current copy hotkey do?

I will soon open an issue that could remove the prompt sidebar from the history area and instead insert them into the text widget when a statement is execution. The history area would then look like the executed statement area of the REPL (at least as in Windows Command Prompt). Splitting Edit Copy as proposed above would then be a mistake. I will start with fixing saves.

@terryjreedy terryjreedy added type-bug An unexpected behavior, bug, or error topic-IDLE 3.12 only security fixes labels Jul 24, 2022
@terryjreedy
Copy link
Member Author

The 'Copy with prompts' code in pyshell.py is in copy_with_prompts_callback, lines 989 to 1023. Some middle portion could be extracted as a useful function for both that method and saving. Text to be saved is now retrieved in iomenu.py line 258 in fixline(). An add_prompts function would have to be called before the returned text is encoded in writefile(), line 241. The problems are getting a function that works for both uses and arranging it to be called when saving.

Both functions currently get the text widget get as a joined string that is immediately split back into lines. Getting a list of text lines might or might not be more efficient.

@terryjreedy terryjreedy added 3.11 only security fixes 3.10 only security fixes labels Aug 2, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Aug 2, 2022
(cherry picked from commit b85411f)

Co-authored-by: Terry Jan Reedy <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Aug 2, 2022
(cherry picked from commit b85411f)

Co-authored-by: Terry Jan Reedy <[email protected]>
terryjreedy added a commit that referenced this issue Aug 2, 2022
(cherry picked from commit b85411f)

Co-authored-by: Terry Jan Reedy <[email protected]>
erlend-aasland pushed a commit that referenced this issue Aug 2, 2022
(cherry picked from commit b85411f)

Co-authored-by: Terry Jan Reedy <[email protected]>
@erlend-aasland erlend-aasland moved this to Done in IDLE Issues Aug 2, 2022
terryjreedy added a commit to terryjreedy/cpython that referenced this issue Aug 4, 2022
terryjreedy added a commit to terryjreedy/cpython that referenced this issue Aug 4, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Aug 4, 2022
(cherry picked from commit c569526)

Co-authored-by: Terry Jan Reedy <[email protected]>
miss-islington added a commit that referenced this issue Aug 4, 2022
(cherry picked from commit c569526)

Co-authored-by: Terry Jan Reedy <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Aug 4, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Aug 4, 2022
miss-islington added a commit that referenced this issue Aug 4, 2022
(cherry picked from commit bcc74d5)

Co-authored-by: Terry Jan Reedy <[email protected]>
miss-islington added a commit that referenced this issue Aug 4, 2022
(cherry picked from commit bcc74d5)

Co-authored-by: Terry Jan Reedy <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.10 only security fixes 3.11 only security fixes 3.12 only security fixes topic-IDLE type-bug An unexpected behavior, bug, or error
Projects
Status: Done
3 participants
@erlend-aasland @terryjreedy and others