I am having trouble with python3 curses and unicode:
#!/usr/bin/env python3
import curses
import locale
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
def doStuff(stdscr):
offset = 3
stdscr.addstr(0, 0, "わたし")
stdscr.addstr(0, offset, 'hello', curses.A_BOLD)
stdscr.getch() # pauses until a key's hit
curses.wrapper(doStuff)
I can display unicode characters just fine, but the y-offset argument to addstr ("offset" in my code) is not acting as expected; my screen displays "わたhello" instead of "わたしhello"
In fact the offset has very strange behavior:
- 0:hello
- 1:わhello
- 2:わhello
- 3:わたhello
- 4:わたhello
- 5:わたしhello
- 6:わたしhello
- 7:わたし hello
- 8:わたし hello
- 9:わたし hello
Note that the offset is not in bytes, since the characters are 3-byte unicode characters:
>>>len("わ".encode('utf-8'))
3
>>> len("わ")
1
I'm running python 4.8.3 and curses.version is "b'2.2'".
Does anyone know what's going on or how to debug this? Thanks in advance.