Skip to content

Commit 1b8a228

Browse files
committed
fix: close issue #128636 for mac make is_mac at init
Signed-off-by: yihong0618 <[email protected]>
1 parent 282e885 commit 1b8a228

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

Lib/_pyrepl/reader.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ def __post_init__(self) -> None:
274274
self.cxy = self.pos2xy()
275275
self.lxy = (self.pos, 0)
276276
self.can_colorize = _colorize.can_colorize()
277+
if self.can_colorize:
278+
self.theme = THEME()
277279

278280
self.last_refresh_cache.screeninfo = self.screeninfo
279281
self.last_refresh_cache.pos = self.pos
@@ -491,7 +493,7 @@ def get_prompt(self, lineno: int, cursor_on_line: bool) -> str:
491493
prompt = self.ps1
492494

493495
if self.can_colorize:
494-
t = THEME()
496+
t = self.theme
495497
prompt = f"{t.prompt}{prompt}{t.reset}"
496498
return prompt
497499

Lib/_pyrepl/unix_console.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ def __init__(
159159
self.pollob.register(self.input_fd, select.POLLIN)
160160
self.terminfo = terminfo.TermInfo(term or None)
161161
self.term = term
162+
self.is_mac = platform.system() == "Darwin" and os.getenv("TERM_PROGRAM") == "Apple_Terminal"
162163

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

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

345346
self.screen = []
@@ -370,7 +371,7 @@ def restore(self):
370371
self.flushoutput()
371372
tcsetattr(self.input_fd, termios.TCSADRAIN, self.__svtermstate)
372373

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

376377
if hasattr(self, "old_sigwinch"):

0 commit comments

Comments
 (0)