Skip to content

Commit bc7ea75

Browse files
committed
Replace ps1/ps2 with the default if values are not usable (fixes #896)
This is a workaround and should be replaced with a better solution in the future.
1 parent feae0f1 commit bc7ea75

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

bpython/curtsiesfrontend/repl.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from enum import Enum
1414

1515
import blessings
16+
import cwcwidth
1617
import greenlet
1718
from curtsies import (
1819
FSArray,
@@ -275,6 +276,14 @@ def _find_module(self, fullname, path=None):
275276
return ImportLoader(self.watcher, loader)
276277

277278

279+
def _process_ps(ps, default_ps: str):
280+
"""Replace ps1/ps2 with the default if the user specified value contains control characters."""
281+
if not isinstance(ps, str):
282+
return ps
283+
284+
return ps if cwcwidth.wcswidth(ps) >= 0 else default_ps
285+
286+
278287
class BaseRepl(Repl):
279288
"""Python Repl
280289
@@ -2051,6 +2060,14 @@ def process():
20512060

20522061
return "\n".join(process())
20532062

2063+
@property
2064+
def ps1(self):
2065+
return _process_ps(super().ps1, ">>> ")
2066+
2067+
@property
2068+
def ps2(self):
2069+
return _process_ps(super().ps2, "... ")
2070+
20542071

20552072
def is_nop(char):
20562073
return unicodedata.category(str(char)) == "Cc"

0 commit comments

Comments
 (0)