I want to make a small program with ncurses/python and to be able to use/type in french and japanese. I understand that I should set the locale and use unicode standard.
But how to deal with the result from screen.getch() ? I would like to display the typed character within the ncurses window regardless of the language.
I understand that some unicode conversion is necessary but can't find what to do (and i've searched quite a bit : this character conversion bussiness isnt easy to understand for amateurs).
Additional question : it seems that for non ascii characters we must used addstr() instead of addch(). Similarly should I use getstr() instead of getch() ?
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import curses
from curses import wrapper
import locale
locale.setlocale(locale.LC_ALL, '')
def main(scr):
# Following lines are some sort of "proof of concept"
# Indeed it print latin or japanese characters allright
scr.addstr(0, 0, u'\u3042'.encode('utf-8')) # print あ
scr.addstr(1, 0, 'é'.encode('utf-8')) # print é
# But here I would like to type in a character and have it displayed onscreen
while (True):
car = scr.getch()
if car == 27: # = Escape key
break
else:
# What should I put between those parenthesis to
# print the typed character on the third line of the screen
scr.addstr(3, 0, ???? )
wrapper(main)