我想用ncurses / python编写一个小程序,使其能够使用/输入法语和日语。我知道应该设置区域设置并使用Unicode标准。
但是如何处理来自screen.getch()的结果?我想在ncurses窗口中显示键入的字符,而不管使用的语言是什么。
我知道需要进行一些Unicode转换,但找不到该怎么做(我已经搜索了很多:对于业余爱好者来说,这个字符转换业务并不容易理解)。
附加问题:似乎对于非ASCII字符,我们必须使用addstr()而不是addch()。同样,我是否应该使用getstr()而不是getch()?
但是如何处理来自screen.getch()的结果?我想在ncurses窗口中显示键入的字符,而不管使用的语言是什么。
我知道需要进行一些Unicode转换,但找不到该怎么做(我已经搜索了很多:对于业余爱好者来说,这个字符转换业务并不容易理解)。
附加问题:似乎对于非ASCII字符,我们必须使用addstr()而不是addch()。同样,我是否应该使用getstr()而不是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)