LdB
Posts: 556
Joined: Wed Dec 07, 2016 2:29 pm

Re: [SOLVED] Non Blocking getchar()? [SOLVED]

Tue Mar 21, 2017 2:43 am

I understand UTF8 and UTF16 inside and out and it's use with C, I use it everyday as I write multilingual programs.

So you are saying Davids code would pick up UTF8 if he just used ncursesw and the get_wch(), I am off to try this as it is actually the real solution because it stops all the codepage nonsense.

I know why it's a separate library because the two schemas are not compatible I have written a ton of these for embedded systems. You have to do some fancy footwork with a FIFO peek buffer if you want both online at the same time which is why it took MS ages to fix it Windows.

User avatar
jojopi
Posts: 2993
Joined: Tue Oct 11, 2011 8:38 pm

Re: [SOLVED] Non Blocking getchar()? [SOLVED]

Tue Mar 21, 2017 1:08 pm

LdB wrote:So you are saying Davids code would pick up UTF8 if he just used ncursesw and the get_wch()
No, I am saying that the examples in this thread are already reading UTF-8, whether they realize it or not. If you change them to read wide characters, they will instead get UTF-32.

Again, whether you use char or wchar_t internally is something to think about. Programs like "sort" can work fine with just char arrays, because strcoll() knows the current locale's multi-byte encoding and alphabet rules.

(I would not normally recommended curses for terminal input, unless you are also using its output features such as cursor positioning. Standard output does not mix well with curses output, and it is a fight to stop curses from clearing the screen at startup.)
I know why it's a separate library because the two schemas are not compatible
At first glance, all the wide character functions have an extra "w" in their names and take different arguments, so I do not immediately see why they could not be in the same library, like getchar() and getwchar() are both in libc.

UTF-8 is unambiguous without lookahead. I still do not understand your point about Windows having to expose a special console API.

LdB
Posts: 556
Joined: Wed Dec 07, 2016 2:29 pm

Re: [SOLVED] Non Blocking getchar()? [SOLVED]

Wed Mar 22, 2017 6:57 am

jojopi wrote:UTF-8 is unambiguous without lookahead. I still do not understand your point about Windows having to expose a special console API.
Same sorts of problems I am no doubt going to ask you about if this all works. How do I select the font onto the console etc.

So when Windows changed the console to draw using unicode etc it could suddenly be resize to any scale. They added a whole pile of stuff you need to be able to play width absolute screen size, font size, colours etc etc. You can see it all by right clicking on the top right icon of the console and it has its own dialog. Obviously we also need to be able to access all that stuff from within the console program so I can choose my size and font etc myself.

The original console was a shell it had no message queue or thread so no way to communicate to real Windows stuff. Long and short you need allow the console to access parts of the subsystem all the while maintaining security so they set it on it's own API. It your interested here is the full list

https://msdn.microsoft.com/en-us/librar ... s.85).aspx

The ones we would definitely need are the Linux equivalents to
SetCurrentConsoleFontEx .... change the console font obviously
SetConsoleTextAttribute ... change the text colour arrangements
probably set screen size but that is not so important users can do that and set default

You will note on windows they API the keyboard with it's own calls
PeekConsoleInput
ReadConsole

They tell you why on the functions "it can read in either Unicode (wide-character) or ANSI mode." basically it knows what to do by what font I have selected.

That was what I was saying to David you don't even write console apps that way on Windows anymore that is for old DOS zealots and die hards. Obviously that old legacy junk works for now but it's pretty ugly when you have a gleaming new API with all the calls just sitting there waiting for you. It's child play to write multilingual Apps it requires one step select an appropriate font for the console.

Return to “C/C++”

Who is online

Users browsing this forum: No registered users and 14 guests