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. Advertising

  2. Andrey Guest

    Yes, it does solve the problem.
    Compile python with ncursesw library.
    Btw Ubuntu 7 has it "out of the box".


    > 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)
    Andrey, Jul 21, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ian Ward

    Problem with curses and UTF-8

    Ian Ward, Feb 7, 2006, in forum: Python
    Replies:
    30
    Views:
    1,810
    Ian Ward
    Feb 10, 2006
  2. Jean-Paul Calderone
    Replies:
    2
    Views:
    423
    Joel Hedlund
    Feb 9, 2006
  3. Daniele C.

    Curses for win32 with VT100/ANSI support

    Daniele C., May 20, 2006, in forum: C Programming
    Replies:
    48
    Views:
    1,546
    Dave Thompson
    Jun 8, 2006
  4. Grzegorz ¦liwiñski
    Replies:
    2
    Views:
    940
    Grzegorz ¦liwiñski
    Jan 19, 2011
  5. Steven D'Aprano

    Curses unicode support

    Steven D'Aprano, Sep 1, 2012, in forum: Python
    Replies:
    1
    Views:
    243
Loading...

Share This Page