ncurses and Unicode

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
Post Reply
Bad_Idea
Posts: 8
Joined: Sep 11, 2017 3:46

ncurses and Unicode

Post by Bad_Idea »

Hello :)

I want to print unicode-characters with ncurses. I tried the following as suggested by several other forums:

Code: Select all

#Include Once "curses.bi"
#Include Once "crt/locale.bi"
setlocale(LC_ALL,"C-UTF-8")
initscr()
cbreak()
noecho()

addstr("\u250C")
addch(&h250C)
printw(WChr(&h250C))

refresh()
The "addstr" will just print that string, "addch" prints nothing in this case (addch(34) works though) and "printw" prints garbage.
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: ncurses and Unicode

Post by caseih »

The FB compiler does not do string escaping by default, so \u notation does nothing as you found out. In general FB really has very little support for unicode. If your .bas file encoded in UTF-8 format you can put unicode characters in string literals, which become UTF-8 bytes. You should be able to do this, for example:

Code: Select all

print "┌"
Be sure to save the .bas file as UTF-8 text or it won't work right. In bytes, "┌" is chr(&he2, &h94, &h8c).

As far as ncurses go, ncurses also has little to no support for unicode. But it does work with bytes and since your terminal is already decoding utf-8 bytes, you can just pass utf-8 bytes to the ncurses functions and it should work because your terminal knows what to do with UTF-8 bytes. addch will not work with a unicode code point; you'll have to send it UTF-8 bytes individually instead.
Post Reply