From d1ecf7fa7a78ba1fa1543b90f239d9a2b5727599 Mon Sep 17 00:00:00 2001 From: Pablo Galindo Date: Fri, 23 Aug 2024 15:59:09 +0100 Subject: [PATCH 1/2] Deactivate line wrap for Apple Terminal via scape codes in the new REPL --- Lib/_pyrepl/unix_console.py | 8 ++++++++ .../2024-08-23-15-59-54.gh-issue-123177.OLcaC5.rst | 2 ++ 2 files changed, 10 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2024-08-23-15-59-54.gh-issue-123177.OLcaC5.rst diff --git a/Lib/_pyrepl/unix_console.py b/Lib/_pyrepl/unix_console.py index 7b8f5a0298b75f..95215800fb6578 100644 --- a/Lib/_pyrepl/unix_console.py +++ b/Lib/_pyrepl/unix_console.py @@ -29,6 +29,7 @@ import struct import termios import time +import platform from fcntl import ioctl from . import curses @@ -334,6 +335,10 @@ def prepare(self): raw.cc[termios.VTIME] = 0 tcsetattr(self.input_fd, termios.TCSADRAIN, raw) + # If in macOS terminal we need to deactivate line wrap via ANSI escape code + if platform.system() == "Darwin" and os.getenv("TERM_PROGRAM") == "Apple_Terminal": + os.write(self.output_fd, b"\033[?7l") + self.screen = [] self.height, self.width = self.getheightwidth() @@ -362,6 +367,9 @@ def restore(self): self.flushoutput() tcsetattr(self.input_fd, termios.TCSADRAIN, self.__svtermstate) + if platform.system() == "Darwin" and os.getenv("TERM_PROGRAM") == "Apple_Terminal": + os.write(self.output_fd, b"\033[?7h") + if hasattr(self, "old_sigwinch"): signal.signal(signal.SIGWINCH, self.old_sigwinch) del self.old_sigwinch diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-08-23-15-59-54.gh-issue-123177.OLcaC5.rst b/Misc/NEWS.d/next/Core and Builtins/2024-08-23-15-59-54.gh-issue-123177.OLcaC5.rst new file mode 100644 index 00000000000000..da688effca3712 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2024-08-23-15-59-54.gh-issue-123177.OLcaC5.rst @@ -0,0 +1,2 @@ +Deactivate line wrap in the Apple Terminal via a ANSI escape code. Patch by +Pablo Galindo From d061372474ecb1e19d7175b41569c3e775e28265 Mon Sep 17 00:00:00 2001 From: Pablo Galindo Salgado Date: Fri, 23 Aug 2024 18:01:27 +0100 Subject: [PATCH 2/2] Apply suggestions from code review --- Lib/_pyrepl/unix_console.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/_pyrepl/unix_console.py b/Lib/_pyrepl/unix_console.py index 95215800fb6578..2f15037129773a 100644 --- a/Lib/_pyrepl/unix_console.py +++ b/Lib/_pyrepl/unix_console.py @@ -335,7 +335,7 @@ def prepare(self): raw.cc[termios.VTIME] = 0 tcsetattr(self.input_fd, termios.TCSADRAIN, raw) - # If in macOS terminal we need to deactivate line wrap via ANSI escape code + # In macOS terminal we need to deactivate line wrap via ANSI escape code if platform.system() == "Darwin" and os.getenv("TERM_PROGRAM") == "Apple_Terminal": os.write(self.output_fd, b"\033[?7l")