Skip to content

Pasting long line in new REPL causes text to appear after >>> #123177

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
Siecje opened this issue Aug 20, 2024 · 16 comments
Closed

Pasting long line in new REPL causes text to appear after >>> #123177

Siecje opened this issue Aug 20, 2024 · 16 comments
Labels
topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error

Comments

@Siecje
Copy link
Contributor

Siecje commented Aug 20, 2024

Bug report

Bug description:

When I paste code that is one line and my REPL window is small the text that would not be shown because it is offscreen is displayed after pressing enter.

For example I am pasting

thread = threading.Thread(target=lambda: threading.current_thread().name == 'MainThread')

After I paste and then press enter to create the object I see

>>> read')

I can't remove the text or use the arrow keys to navigate the letters since the >>> prompt is empty.

When the window is smaller more text is shown after >>>.

>>> thread = threading.Thread(target=lambda: threading.current_thread()\
                                                                                                                        >
>>> name == 'MainThread')

CPython versions tested on:

3.13

Operating systems tested on:

macOS

Linked PRs

@Siecje Siecje added the type-bug An unexpected behavior, bug, or error label Aug 20, 2024
@picnixz picnixz added the topic-repl Related to the interactive shell label Aug 20, 2024
@skirpichev
Copy link
Member

Hmm, can someone reproduce this on recent main? Is this Mac-specific? I can't reproduce this on Linux.

@pablogsal
Copy link
Member

I cannot reproduce exactly this, but there is something weird happening with macOS terminal application (I could not reproduce this with iTerm):

Screen.Recording.2024-08-23.at.14.20.38.mov

@pablogsal
Copy link
Member

This seems partially related to the cache but not fully. Removing the line cache shows the following problem:

Screen.Recording.2024-08-23.at.14.34.00.mov

@pablogsal
Copy link
Member

For some reason this only happens in the terminal app and not in iterm

@pablogsal
Copy link
Member

Another problem: seems like the cache forces lines that warp around to also start with >>> (but they should not).

@pablogsal
Copy link
Member

@godlygeek could you take a look at this if you have some free cycles?

@Siecje
Copy link
Contributor Author

Siecje commented Aug 23, 2024

When I type random words like that as soon as I get to the end of the line I see strange behaviour including >>> moving.

Screen.Recording.2024-08-23.at.9.39.44.AM.mov

@pablogsal
Copy link
Member

What terminal are you using?

@pablogsal
Copy link
Member

Can you try if #123267 fixes the other problem for you?

@Siecje
Copy link
Contributor Author

Siecje commented Aug 23, 2024

What terminal are you using?

The default "Terminal"

@pablogsal
Copy link
Member

Can you run echo $TERM_PROGRAM?

@Siecje
Copy link
Contributor Author

Siecje commented Aug 23, 2024

Apple_Terminal

@godlygeek
Copy link
Contributor

Seems like there's two separate issues here, one with how Apple Terminal behaves when something is written to the last column of a line, and one with the cache. I understand what's causing the cache bug, but I'm still deciding how best to fix it.

@pablogsal
Copy link
Member

Seems like there's two separate issues here, one with how Apple Terminal behaves when something is written to the last column of a line, and one with the cache. I understand what's causing the cache bug, but I'm still deciding how best to fix it.

The apple terminal one it's being handled here: #123267

miss-islington pushed a commit to miss-islington/cpython that referenced this issue Aug 25, 2024
…des in the new REPL (pythonGH-123267)

(cherry picked from commit fdb3f9b)

Co-authored-by: Pablo Galindo Salgado <[email protected]>
pablogsal added a commit that referenced this issue Aug 25, 2024
…odes in the new REPL (GH-123267) (#123322)

gh-123177: Deactivate line wrap for Apple Terminal via scape codes in the new REPL (GH-123267)
(cherry picked from commit fdb3f9b)

Co-authored-by: Pablo Galindo Salgado <[email protected]>
godlygeek added a commit to godlygeek/cpython that referenced this issue Aug 25, 2024
When display lines above the cursor come from the cache, the first line
to not come from the cache may be a wrapped line, starting half way
through a logical line in the buffer. Detect and handle this case to
avoid accidentally drawing a stray prompt in the middle of a logical
line.
@godlygeek
Copy link
Contributor

#123324 fixes the cache bug, and adds a test to exercise prompts with wrapping.

pablogsal pushed a commit that referenced this issue Aug 25, 2024
When display lines above the cursor come from the cache, the first line
to not come from the cache may be a wrapped line, starting half way
through a logical line in the buffer. Detect and handle this case to
avoid accidentally drawing a stray prompt in the middle of a logical
line.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Aug 25, 2024
)

When display lines above the cursor come from the cache, the first line
to not come from the cache may be a wrapped line, starting half way
through a logical line in the buffer. Detect and handle this case to
avoid accidentally drawing a stray prompt in the middle of a logical
line.
(cherry picked from commit 602fcf9)

Co-authored-by: Matt Wozniski <[email protected]>
pablogsal pushed a commit that referenced this issue Aug 26, 2024
…123327)

gh-123177: Fix prompt for wrapped lines in pyrepl (GH-123324)

When display lines above the cursor come from the cache, the first line
to not come from the cache may be a wrapped line, starting half way
through a logical line in the buffer. Detect and handle this case to
avoid accidentally drawing a stray prompt in the middle of a logical
line.
(cherry picked from commit 602fcf9)

Co-authored-by: Matt Wozniski <[email protected]>
@pablogsal
Copy link
Member

Thanks for the report @Siecje and @godlygeek for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

5 participants