|
Home > Archive > Unix Programming > December 2005 > ncurses wgetch and flicker.
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
ncurses wgetch and flicker.
|
|
| sir.eggplantalot@gmail.com 2005-12-20, 5:57 pm |
| I have a program which is spewing junk to std::cout from all over the
place. I would like to be able to catch a keypress without blocking,
and so I have used ncurses to do so. Unfortunately using the wgetch()
function seems to cause a screen clear on each read, which results in
flicker in the application. clearok(w,FALSE) does not seem to work.
My code is:
WINDOW* w = initscr();
nodelay(w,true);
bool q(false);
while(!q)
{
std::cout << "Print junk!\n";
clearok(w,FALSE);
wrefresh(w);
int kk=wgetch(w);
endwin();
switch(kk)
{
case 'q': q=true;
break;
case -1:
break;
default:
std::cout << "A ket!\n";
}
sleep(1);
}
Is there any way to eliminate the flicker? Is the above code
incorrect?
Thank you for any/all help.
don
| |
| Hubble 2005-12-21, 2:52 am |
| >I would like to be able to catch a keypress without blocking,
>and so I have used ncurses to do so. >Unfortunately using the wgetch()
>function seems to cause a screen clear on each read
I do not think that you can use [n]curses functions without letting
curses control the screen.
In similar situations, I use a shell skript using stty and trap to
start the program in raw mode.
Outline (without check), consult man pages of your system!
#!/bin/sh
trap '[ -f .saved ] && stty .saved ; rm -f .saved; exit' 1 2 3 15
# save setting
stty -g >.saved
# no echo, deliver each char (system dependent!!)
stty -echo raw cbreak
yourprogram "$@"
EXITCODE=$?
stty .saved
exit $EXITCODE
The you can use getchar etc. in your program. Note that the skript also
preserves the exit code.
Hubble.
|
|
|
|
|