Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: ncurses getch & unicode (was: decoding keyboard input when usingcurses)

Reply
Thread Tools

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

 
 
Thomas Dickey
Guest
Posts: n/a
 
      08-21-2009
On Aug 20, 6:12*pm, Iigo Serna <(E-Mail Removed)> wrote:
> Hi again,
>
> 2009/8/20 Iigo Serna <(E-Mail Removed)>
> > 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,
> Iigo 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.
 
Reply With Quote
 
 
 
 
Iñigo Serna
Guest
Posts: n/a
 
      08-21-2009
2009/8/21 Thomas Dickey <(E-Mail Removed)>:
> On Aug 20, 6:12*pm, Iñigo Serna <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Thomas Dickey
Guest
Posts: n/a
 
      08-21-2009
On Fri, 21 Aug 2009, Iñigo Serna wrote:

> 2009/8/21 Thomas Dickey <(E-Mail Removed)>:
>> On Aug 20, 6:12*pm, Iñigo Serna <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
decoding keyboard input when using curses Arnaud Delobelle Python 6 05-31-2009 10:23 PM
Ncurses.init_pair no longer seems to exist in the 'ncurses' package. Kenneth McDonald Ruby 1 09-27-2008 03:18 AM
Linux: getch() skips my input Sankar C Programming 5 02-13-2007 04:07 AM
Exiting a getch() if no input received... Patrick M. C Programming 2 09-15-2005 10:58 PM
curses, ncurses, threads and non-blocking getch William Morgan Ruby 0 02-12-2005 05:32 PM



Advertisments