Skip to content

Commit a29ac35

Browse files
committed
Windows codepoint width testing
1 parent 7aad9ce commit a29ac35

1 file changed

Lines changed: 25 additions & 16 deletions

File tree

apsw/unicode.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,30 +1662,39 @@ def fmt(text):
16621662
print("),")
16631663

16641664
elif options.function == "widthcheck":
1665-
import atexit
16661665

1667-
import ctypes, ctypes.util
1666+
if sys.platform != "win32":
1667+
import atexit
16681668

1669-
libc = ctypes.cdll.LoadLibrary(ctypes.util.find_library("c"))
1670-
libc.wcswidth.argtypes = [ctypes.c_wchar_p, ctypes.c_size_t]
1671-
libc.wcswidth.restype = ctypes.c_int
1669+
import ctypes, ctypes.util
16721670

1673-
import wcwidth
1671+
libc = ctypes.cdll.LoadLibrary(ctypes.util.find_library("c"))
1672+
libc.wcswidth.argtypes = [ctypes.c_wchar_p, ctypes.c_size_t]
1673+
libc.wcswidth.restype = ctypes.c_int
16741674

1675-
tty_in = open("/dev/tty", "r")
1676-
tty_out = open("/dev/tty", "w")
1677-
import tty
1678-
import termios
1675+
import wcwidth
16791676

1680-
term_mode = termios.tcgetattr(tty_in)
1677+
tty_in = open("/dev/tty", "r")
1678+
tty_out = open("/dev/tty", "w")
1679+
import tty
1680+
import termios
16811681

1682-
def finish():
1683-
termios.tcsetattr(tty_in, termios.TCSAFLUSH, term_mode)
1684-
print("", flush=True, file=tty_out)
1682+
term_mode = termios.tcgetattr(tty_in)
16851683

1686-
atexit.register(finish)
1684+
def finish():
1685+
termios.tcsetattr(tty_in, termios.TCSAFLUSH, term_mode)
1686+
print("", flush=True, file=tty_out)
16871687

1688-
tty.setraw(tty_in)
1688+
atexit.register(finish)
1689+
1690+
tty.setraw(tty_in)
1691+
else:
1692+
tty_in = os.open("CONIN$", os.O_RDONLY)
1693+
tty_out = os.open("CONOUT$", os.WRONLY)
1694+
class dummy:
1695+
def wcswidth(*args):
1696+
return 1
1697+
libc = wcwidth = dummy()
16891698

16901699
def get_pos():
16911700
print("\x1b[6n", flush=True, file=tty_out, end="")

0 commit comments

Comments
 (0)