ncurses wgetch and flicker.
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > ncurses wgetch and flicker.




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    ncurses wgetch and flicker.  
sir.eggplantalot@gmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-20-05 10: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






[ Post a follow-up to this message ]



    Re: ncurses wgetch and flicker.  
Hubble


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-21-05 07: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.






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 09:29 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register