pancurses icon indicating copy to clipboard operation
pancurses copied to clipboard

Unicode support?

Open saethlin opened this issue 6 years ago • 7 comments

It looks to me like ncurses-sys and pdcurses-sys both have unicode support, but I can't figure out how to enable it here. Is this a planned feature?

saethlin avatar Feb 24 '18 18:02 saethlin

Could you elaborate on what you mean exactly? At least on Windows unicode output works as far as I know, aside from some special cases, and input should as well for both platforms with the release of v0.15. Output with ncurses may require more work, I haven't looked into it for a while.

ihalila avatar Feb 25 '18 09:02 ihalila

I'm looking at a problem with unicode output on linux.

I think all one would need is to insert this call after the initscr() call, but I'm a bit hesitant to suggest just making everyone en-US locale. https://github.com/jeaye/ncurses-rs/blob/85ab2aa9d58eb58ba68cbac47f105cc93cf36aae/examples/ex_7.rs#L19

saethlin avatar Feb 25 '18 17:02 saethlin

setlocale is already called in https://github.com/ihalila/pancurses/blob/65621d5731927dd7090e1055c7d358dfc7354875/src/unix/mod.rs#L15 , so that's not the problem.

I did some testing and Unicode output works as it should for me as long as I have the ncurses/wide feature enabled (exported as just wide in pancurses) and I don't use addch, because that doesn't work correctly. Checking the ncurses manual at http://invisible-island.net/ncurses/man/curs_addch.3x.html it has two relevant bullet points:

  • check if a character can be represented as a single byte in the current locale before attempting call waddch, and
  • call wadd_wch for characters which cannot be handled by waddch.

which leads me to believe that pancurses should really always use wadd_wch, it would probably work correctly. Unfortunately ncurses-rs does not expose that function yet so fixing this requires a change there first.

ihalila avatar Feb 25 '18 18:02 ihalila

I added features = ["wide"] to my Cargo.toml, and unicode output works now! Is there still work to be done? If this feature is incomplete or something I'm interested in helping out.

saethlin avatar Feb 25 '18 19:02 saethlin

The only issue I know of is the one I described in my earlier comment, regarding addch() not working for multibyte characters.

ihalila avatar Feb 25 '18 19:02 ihalila

There is one other problem as described here:

https://github.com/ihalila/pancurses/pull/43#issuecomment-572012502

We can't use Unicode on a terminal created with pancurses::newterm. In order to support this platform_specific::pre_init() should be added to that function as well.

TimonPost avatar Jan 08 '20 13:01 TimonPost

Is there any solution today ?

plefebvre91 avatar Apr 02 '22 07:04 plefebvre91