将 Unicode/UTF8 字符添加到 C 中的 ncurses 显示 [英] Adding Unicode/UTF8 chars to a ncurses display in C

查看:27
本文介绍了将 Unicode/UTF8 字符添加到 C 中的 ncurses 显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 wchar_t Unicode 字符添加到 C 中的 ncurses 显示中.

I'm attempting to add wchar_t Unicode characters to an ncurses display in C.

我有一个数组:

wchar_t characters[]={L'uE030', L'uE029'}; // containing 2 thai letters, for example 

然后我尝试将数组中的 wchar_t 添加到 ncurses 显示中:

And I later try to add a wchar_t from the array to the ncurses display with:

add_wch(characters[0]);

为了提供更多信息,使用 ASCII 执行此操作可以正常工作,使用:

To provide a bit more info, doing this with ASCII works ok, using:

char characters[]={'A', 'B'};

// and later...

addch(characters[0]);

要设置语言环境,我添加了包含...

To setup the locale, I add the include...

#include <locale.h>

// in main()
setlocale(LC_CTYPE,"C-UTF-8");

ncurses 包括:

The ncurses include is:

#include <ncurses.h> 

编译:

(添加了 c99 标准,用于通用字符名称支持.)

(edit: added c99 standard, for universal char name support.)

gcc -o ncursesutf8 ncursesutf8.c -lm -lncurses -Wall -std=c99

我收到以下编译警告(当然可执行文件会失败):

I get the following compilation warning (of course the executable will fail):

ncursesutf8.c:48: warning: implicit declaration of function ‘add_wch’

我试过只使用 addch ,它似乎被宏化以与 wchar_t 一起使用,但是当我这样做时,Unicode 字符不显示,而是显示为 ASCII 字符.

I've tried just using addch which appears to be macro'ed to work with wchar_t but when I do that the Unicode chars do not show up, instead they show as ASCII chars instead.

有什么想法吗?

我使用的是 OS X Snow Leopard,10.6.6

I am using OS X Snow Leopard, 10.6.6

删除了 wchar_t [] 赋值的错误,使用 L'u0E30' 而不是 L"u0E30" 等.我还更新了编译器设置以使用 C99(以添加通用字符名称支持).两种更改都不能解决问题.

removed error on wchar_t [] assignment to use L'u0E30' instead of L"u0E30" etc. I've also updated the compiler settings to use C99 (to add universal char name support). both changes do not fix the problem.

对此仍然没有答案,有没有人知道如何做 Unicode ncurses addchar (add_wchar?) ?!帮助!

Still no answers on this, does anyone know how to do Unicode ncurses addchar (add_wchar?) ?! Help!

推荐答案

宽字符支持由 ncursesw 处理.根据您的发行版,ncurses 可能会也可能不会指向那里(似乎不在您的发行版中).

The wide character support is handled by ncursesw. Depending on your distro, ncurses may or may not point there (seemingly not in yours).

尝试使用 -lncursesw 而不是 -lncurses.

Try using -lncursesw instead of -lncurses.

另外,对于语言环境,尝试调用 setlocale(LC_ALL, "")

Also, for the locale, try calling setlocale(LC_ALL, "")

这篇关于将 Unicode/UTF8 字符添加到 C 中的 ncurses 显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆