3 ms·
First, switch it to alternative screen mode... printf("\033?1047h"); then clear and move and such with other similar prints. See the list here : http://invisibl
by destructionator 10y ago
First, switch it to alternative screen mode... printf("\033?1047h"); then clear and move and such with other similar prints. See the list here : http://invisible-island.net/xterm/ctlseqs/ctlseqs.html http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
It really is pretty simple. The big benefit of ncurses is if you want to target terminals other than xterm compatible ones, and they are so rare nowadays that you can really just ignore them....
Input is quite a pain though (however, ncurses sometimes get it wrong too), but the same thing applies, you just need to switch to raw mode with tcsetattr and then have some kind of select() loop or something to watch for escape sequences then translate them into interesting key presses.
Mouse events are the same btw: you write out a sequence to turn them on, then the terminal sends them as sequences to stdin.
I wrote a terminal library myself for the D programming language (and a terminal emulator too!), it is kinda ugly code but it isn't hard.
- voltagex_ 10y agoI wonder if these codes work in cmd.exe now that Windows 10 TH2 supports (some of) the features.
- destructionator 10y agoI haven't checked but I kinda doubt it... and I kinda hope not - the windows console API is so much nicer than the unix terminal system it would be a pity to make it an ugly hybrid. Of course, you can run a terminal emulator inside the windows console and handle those sequences too! If I had to guess, I'd say that's what Microsoft would have implemented.
- gnuvince 10y agoThanks for the info, very useful info; I was most interested to learn that ncurses provides compatibility for terminals that are rare.