Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/_pyrepl/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ def get_prompt(self, lineno: int, cursor_on_line: bool) -> str:
prompt = self.ps1

if self.can_colorize:
t = THEME()
t = THEME(force_color=self.can_colorize)
prompt = f"{t.prompt}{prompt}{t.reset}"
return prompt

Expand Down
5 changes: 3 additions & 2 deletions Lib/_pyrepl/unix_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def __init__(
self.pollob.register(self.input_fd, select.POLLIN)
self.terminfo = terminfo.TermInfo(term or None)
self.term = term
self.is_mac = platform.system() == "Darwin" and os.getenv("TERM_PROGRAM") == "Apple_Terminal"

@overload
def _my_getstr(cap: str, optional: Literal[False] = False) -> bytes: ...
Expand Down Expand Up @@ -339,7 +340,7 @@ def prepare(self):
tcsetattr(self.input_fd, termios.TCSADRAIN, raw)

# In macOS terminal we need to deactivate line wrap via ANSI escape code
if platform.system() == "Darwin" and os.getenv("TERM_PROGRAM") == "Apple_Terminal":
if self.is_mac:
os.write(self.output_fd, b"\033[?7l")

self.screen = []
Expand Down Expand Up @@ -370,7 +371,7 @@ def restore(self):
self.flushoutput()
tcsetattr(self.input_fd, termios.TCSADRAIN, self.__svtermstate)

if platform.system() == "Darwin" and os.getenv("TERM_PROGRAM") == "Apple_Terminal":
if self.is_mac:
os.write(self.output_fd, b"\033[?7h")

if hasattr(self, "old_sigwinch"):
Expand Down
12 changes: 12 additions & 0 deletions Lib/test/test_pyrepl/test_unix_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,15 @@ def test_getheightwidth_with_invalid_environ(self, _os_write):
self.assertIsInstance(console.getheightwidth(), tuple)
os.environ = []
self.assertIsInstance(console.getheightwidth(), tuple)

def test_mac_with_invalid_environ(self, _os_write):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def test_mac_with_invalid_environ(self, _os_write):
def test_is_mac_with_invalid_environ(self, _os_write):

# gh-128636 for macOS
if sys.platform == "darwin":
console = UnixConsole(term="xterm")
with os_helper.EnvironmentVarGuard() as env:
if os.getenv("TERM_PROGRAM") == "Apple_Terminal":
self.assertEqual(console.is_mac, True)
else:
self.assertEqual(console.is_mac, False)
os.environ = []
self.assertIsInstance(console.getheightwidth(), tuple)
Loading