UTF-8 Support of Curses in Python 2.5

Discussion in 'Python' started by shrek2099@yahoo.com, Jul 4, 2007.

  1. Guest

    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)
     
    , Jul 4, 2007
    #1
    1. Advertisements

  2. Andrey Guest

    Yes, it does solve the problem.
    Compile python with ncursesw library.
    Btw Ubuntu 7 has it "out of the box".
     
    Andrey, Jul 21, 2007
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.