UTF-8 Support of Curses in Python 2.5

shrek2099 at yahoo.com shrek2099 at yahoo.com
Wed Jul 4 05:08:12 CEST 2007


Hi All,

Recently I ran into a problem with UTF-8 surrport when using curses
library in python 2.5 in Fedora 7. I found out that the program using
curses cannot print out unicode characters correctly on UTF-8 enabled
console. I googled around and got an impression that the reason for
this problem is that python is linked with libcurses library instead
of libcursesw. The latter one is said to be able to solve this
problem. Has anybody tried this? How to manually let python use
libcursesw? Thanks a lot!

Here is a test program:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import curses
def keyloop(stdscr):
    # Clear the screen and display the menu of keys
    stdscr_y, stdscr_x = stdscr.getmaxyx()
    menu_y = (stdscr_y-3)-1
    str = u'This is my first curses python program. Press \'q\' to
exit. (¤£™)'
    stdscr.addstr(menu_y, 4, str.encode('utf-8'))
    xpos = stdscr_x / 2
    ypos = stdscr_y / 2
    while (1):
        stdscr.move(ypos, xpos)
        c = stdscr.getch()
        if 0 < c < 256:
            c = chr(c)
            if c in 'Qq': break
            else: pass
        elif c == curses.KEY_UP and ypos > 0:               ypos -= 1
        elif c == curses.KEY_DOWN and ypos < stdscr_y - 1:  ypos += 1
        elif c == curses.KEY_LEFT and xpos > 0:             xpos -= 1
        elif c == curses.KEY_RIGHT and xpos < stdscr_x - 1: xpos += 1
        else: pass
def main(stdscr):
    keyloop(stdscr)
if __name__ == '__main__':
    curses.wrapper(main)




More information about the Python-list mailing list