From mboxrd@z Thu Jan 1 00:00:00 1970 From: wmorgan-sup@masanjin.net (William Morgan) Date: Wed, 01 Jul 2009 08:28:46 -0700 Subject: [sup-talk] ncurses-ruby-1.2.3 + ncursesw hack breaks search In-Reply-To: <1246437271-sup-7636@cannonball> References: <1246437271-sup-7636@cannonball> Message-ID: <1246461233-sup-208@entry> Reformatted excerpts from Ingmar Vanhassel's message of 2009-07-01: > [1] http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=477366#52 Interesting thread. I disagree with the conclusion that a separate libncursesw-ruby package should be created. Maybe I'll respond. The analysis of Sup is wrong. He says: "Looking at the source code of the mailer I'd say that it is not really suited for UTF-8 encoded strings yet, as it still assumes that the length of a string in bytes is equal to the number of characters in the string." This is not really true. What Sup assumes is that String#length gives the length of the string in characters. This is obviously false in Ruby 1.8 (without monkeypatching), but it is true in Ruby 1.9. What *does* need to happen for Sup to really, actually, correctly display non-ASCII characters, besides having a ncurses library that's linked against ncursesw, is to be able to call the 'wcwidth' and 'wcswidth' functions. The current #display_length function is a hack that's broken for e.g. Chinese characters. One way to do this would be to use dl/import like we do for setlocale(). I've played around with this but haven't really gotten it to work. If someone can get any further than the below, please let me know: require 'dl/import' module LibC extend DL.const_defined?(:Importer) ? DL::Importer : DL::Importable dlload "libc.so.6" extern "void setlocale(int, const char *)" extern "int wcwidth(int)" extern "int wcswidth(const int*, int)" end That "works", as in doesn't throw any exceptions, but then calling LibC.wcswidth doesn't return the right thing, presumably because the Ruby string isn't being converted into an array of ints, or something. I don't really know how this works. > Has anyone noticed that newer versions of ncurses-ruby plus that > ncursesw hack [1] (to link to ncurses with widechar support) breaks > search? I don't have these newer versions available on my system yet (Ubuntu). > When I search for 'foo', sup launches a search for a bunch of weird > characters, not for 'foo', which obviously returns nothing useful. Disturbing. -- William