Re: ncurses getch & unicode (was: decoding keyboard input when usingcurses)

Discussion in 'Python' started by Thomas Dickey, Aug 21, 2009.

  1. On Aug 20, 6:12 pm, Iñigo Serna <> wrote:
    > Hi again,
    >
    > 2009/8/20 Iñigo Serna <>
    > > I have the same problem mentioned inhttp://groups.google.com/group/comp..lang.python/browse_thread/thread/...some months ago.

    >
    > > Python 2.6 program which usesncursesmodule in a terminal configured to use UTF-8 encoding.

    >
    > > When trying to get input from keyboard, a non-ascii character (like ç) is returned as 2 integers < 255, needing 2 calls to getch method to get both.
    > > These two integers \xc3 \xa7 forms the utf-8 encoded representation of ç character.

    >
    > >ncursesget_wch documentation states the function should return an unique integer > 255 with the ordinal representation of that unicode char encoded in UTF-8, \xc3a7.

    >
    > Answering myself, I've copied at the bottom of this email a working
    > solution, but the question still remains: why win.getch() doesn't
    > return the correct value?


    The code looks consistent with the curses functions...

    > Kind regards,
    > Iñigo Serna
    >
    > ######################################################################
    > # test.py
    > import curses
    >
    > import locale
    > locale.setlocale(locale.LC_ALL, '')
    > print locale.getpreferredencoding()
    >
    > def get_char(win):
    >     def get_check_next_byte():
    >         c = win.getch()


    You're using "getch", not "get_wch" (Python's ncurses binding may/may
    not have the latter).
    curses getch returns 8-bit values, get_wch would return wider values.
    Thomas Dickey, Aug 21, 2009
    #1
    1. Advertising

  2. 2009/8/21 Thomas Dickey <>:
    > On Aug 20, 6:12 pm, Iñigo Serna <> wrote:
    >>         c = win.getch()

    >
    > You're using "getch", not "get_wch" (Python's ncurses binding may/may
    > not have the latter).
    > curses getch returns 8-bit values, get_wch would return wider values.


    you are right, ncurses binding does not have get_wch, only getch, and
    this last is the only one called in ncurses library bindings.


    Anyway, I've written a patch to include the get_wch method in the bindings.
    See http://bugs.python.org/issue6755


    Thanks for the clarification,
    Iñigo
    Iñigo Serna, Aug 21, 2009
    #2
    1. Advertising

  3. On Fri, 21 Aug 2009, Iñigo Serna wrote:

    > 2009/8/21 Thomas Dickey <>:
    >> On Aug 20, 6:12 pm, Iñigo Serna <> wrote:
    >>>         c = win.getch()

    >>
    >> You're using "getch", not "get_wch" (Python's ncurses binding may/may
    >> not have the latter).
    >> curses getch returns 8-bit values, get_wch would return wider values.

    >
    > you are right, ncurses binding does not have get_wch, only getch, and
    > this last is the only one called in ncurses library bindings.
    >
    >
    > Anyway, I've written a patch to include the get_wch method in the bindings.
    > See http://bugs.python.org/issue6755
    >
    >
    > Thanks for the clarification,


    no problem (report bugs)

    > Iñigo
    >


    --
    Thomas E. Dickey
    http://invisible-island.net
    ftp://invisible-island.net
    Thomas Dickey, Aug 21, 2009
    #3
    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. Patrick M.

    Exiting a getch() if no input received...

    Patrick M., Sep 15, 2005, in forum: C Programming
    Replies:
    2
    Views:
    473
    Patrick M.
    Sep 15, 2005
  2. Sankar

    Linux: getch() skips my input

    Sankar, Feb 12, 2007, in forum: C Programming
    Replies:
    5
    Views:
    485
    Jack Klein
    Feb 13, 2007
  3. Arnaud Delobelle

    decoding keyboard input when using curses

    Arnaud Delobelle, May 30, 2009, in forum: Python
    Replies:
    6
    Views:
    1,341
    Chris Jones
    May 31, 2009
  4. William Morgan
    Replies:
    0
    Views:
    514
    William Morgan
    Feb 12, 2005
  5. Kenneth McDonald
    Replies:
    1
    Views:
    146
    Nit Khair
    Sep 27, 2008
Loading...

Share This Page