mirror of
https://github.com/python/cpython.git
synced 2025-07-09 20:35:26 +00:00
gh-111201: A new Python REPL (GH-111567)
Co-authored-by: Łukasz Langa <lukasz@langa.pl> Co-authored-by: Marta Gómez Macías <mgmacias@google.com> Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
parent
40cc809902
commit
f27f8c790a
41 changed files with 5328 additions and 170 deletions
18
Lib/_pyrepl/utils.py
Normal file
18
Lib/_pyrepl/utils.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
import re
|
||||
import unicodedata
|
||||
|
||||
ANSI_ESCAPE_SEQUENCE = re.compile(r"\x1b\[[ -@]*[A-~]")
|
||||
|
||||
|
||||
def str_width(c: str) -> int:
|
||||
w = unicodedata.east_asian_width(c)
|
||||
if w in ('N', 'Na', 'H', 'A'):
|
||||
return 1
|
||||
return 2
|
||||
|
||||
|
||||
def wlen(s: str) -> int:
|
||||
length = sum(str_width(i) for i in s)
|
||||
|
||||
# remove lengths of any escape sequences
|
||||
return length - sum(len(i) for i in ANSI_ESCAPE_SEQUENCE.findall(s))
|
Loading…
Add table
Add a link
Reference in a new issue