- Subject: Re: [slang-users] Welcome to the "slang-users-l" mailing list
- From: "John E. Davis" <davis@xxxxxxxxxxxxx>
- Date: Mon, 17 Jan 2011 11:55:21 -0500
Ian Langworth <ian.langworth@xxxxxxxxx> wrote:
> I'm attempting to print a UTF-8 encoded character to the screen in a
> Unicode-capable terminal:
There are a couple of things wrong:
>
> #include <slang.h>
> #include <stdio.h>
>
> int main(int argc, char* argv[]) {
> SLtt_get_terminfo();
> SLang_init_tty(-1, 1, 0);
> SLsmg_init_smg();
>
> SLutf8_enable(-1);
SLutf8_enable has to be called first before any of the other
functions. I should document this requirement.
> SLsmg_cls();
> SLsmg_gotorc(0, 0);
> SLsmg_write_string("黑\n");
> SLsmg_write_nchars("黑", 1);
SLsmg_write_nchars predates slang's UTF-8 support. It should more
properly be called SLsmg_write_nbytes. As such, yiu are writing the
first byte of the string to the display. You need to use strlen
here to write all the bytes.
Here is a corrected version that should work for you. Thanks, --John
#include <slang.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char* argv[])
{
char *str = "黑";
SLutf8_enable(-1);
SLtt_get_terminfo();
SLang_init_tty(-1, 1, 0);
SLsmg_init_smg();
SLsmg_cls();
SLsmg_gotorc(0, 0);
SLsmg_write_string("黑\n");
SLsmg_write_nchars (str, strlen(str));
SLsmg_gotorc(5, 0);
SLsmg_refresh();
SLang_getkey();
SLsmg_reset_smg();
SLang_reset_tty();
return 0;
}
_______________________________________________
slang-users-l mailing list
slang-users-l@xxxxxxxxxxx
http://mailman.jedsoft.org/mailman/listinfo/slang-users-l
[2011 date index]
[2011 thread index]
[Thread Prev] [Thread Next]
[Date Prev] [Date Next]