Skip to content

Line-wrapped syntax highlighting in Python shell spills over into program output #152068

Description

@DroneBetter

Bug report

Bug description:

As shown here, when I make the input long enough that the range gets wrapped with a backtick, all subsequent lines until the next command prompt become the same cyan as the text of range.
Image
Tangentially, is there any way to have Python itself stop doing this when the VScode terminal already did it for me in a way I find preferable (since it doesn't insert line-breaks into long one-liners copied from the shell)?

issue 140334 is similar, but this affects the shell, not just IDLE.

CPython versions tested on:

3.14

Operating systems tested on:

macOS, in both VScode and the terminal.

Linked PRs

Activity

  1. StanFromIreland commented on Jun 24, 2026

    @StanFromIreland
    Member

    I'm struggling to reproduce this issue:

    Image
  2. edvilme commented on Jun 24, 2026

    @edvilme
    Contributor

    This seems to me like an ANSI issue. Is this with the default Terminal.app or some other?

    Edit: It appears the code explicitly singles out Terminal.app

    self.is_apple_terminal = (
    platform.system() == "Darwin"
    and os.getenv("TERM_PROGRAM") == "Apple_Terminal"
    )

    and overrides the line wrapping
    # Apple Terminal will re-wrap lines for us unless we preempt the
    # damage.
    if self.is_apple_terminal:
    os.write(self.output_fd, b"\033[?7l")

    which could be causing the bug of the reset ANSI escape code not being appended properly to the second line.

  3. added
    stdlibStandard Library Python modules in the Lib/ directory
    topic-replRelated to the interactive shell
    on Jun 24, 2026
  4. edvilme commented on Jun 25, 2026

    @edvilme
    Contributor

    I'm struggling to reproduce this issue:

    Image

    I was also struggling to replicate the issue. If the cursor jumps to the new line as you are typing, the ANSI escape sequence is added correctly. If you modify the inside, causing a keyword (not at cursor position) to be split, then the error occurs.

    Image
  5. StanFromIreland commented on Jun 25, 2026

    @StanFromIreland
    Member

    Thanks for the information. I'm not on a mac however, so I can't reproduce it anyway.

  6. edvilme commented on Jun 25, 2026

    @edvilme
    Contributor

    Thanks for the information. I'm not on a mac however, so I can't reproduce it anyway.

    Ah that's right I forgot haha. It is a flaky use case but tried the fix and seems to work :)

  7. added a commit that references this issue on Jun 25, 2026
  8. added a commit that references this issue on Jul 2, 2026
  9. added 2 commits that reference this issue on Jul 4, 2026
  10. added a commit that references this issue on Jul 21, 2026
  11. added a commit that references this issue on Aug 20, 2026
  12. added a commit that references this issue on Sep 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS-macstdlibStandard Library Python modules in the Lib/ directorytopic-replRelated to the interactive shelltype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions