Re: ncurses event loop



Wellu wrote:
Hi,

I need to program a simple user interface using ncurses and I'm a bit
stuck with the event loop in it. Basically I need to launch a new
process from a list of processes in my app. Once this new process is
started it starts to send progress information using some IPC
mechanism.

So what I have now is something like:

timeout(10); // timeout to 10 ms

while(1)
{
int ch = getch(); // get character blocking 10 ms at max
if(ch != ERR) // key pressed
{
// do something with the key such as update screen
// or launch another process
}
else
{
// no keypress in last 10 ms so poll progress info
get_progress_info();
}
}


To me this looks weird but that can be due to fact that this is my
first ncurses program :) Anyway.. Is this kind of programming as "bad"
as it looks? Let's say get_progress_info() function takes 10 ms to
respond. That means that CPU-usage would be 100% all the time which is
vey bad thing. Does getch() really sleep when no keypress is coming?

Anyway, I come from Symbian world where event loops built in so
forgive my stupidity ;)

Your IPC from the background task could be a pipe. Then use select() on
that pipe and stdin to wait for something to do. If stdin is ready
call getch() to handle it. If the pipe call get_progress_info() to read it.
.



Relevant Pages

  • ncurses event loop
    ... I need to program a simple user interface using ncurses and I'm a bit ... stuck with the event loop in it. ... Basically I need to launch a new ... Does getchreally sleep when no keypress is coming? ...
    (comp.os.linux.development.apps)
  • Re: NPTL, stdin, and keyboard input
    ... >> I would recommend that you use fork() instead of pthread for ncurses. ... created a pipe between the two processes, ...
    (comp.unix.programmer)
  • Re: The question rather is, will you find dmesg on "all systems"?! ...
    ... menu-like or form-like window object. ... All references to "environment variable" I found talk about ncurses ... how do you do it via a pipe or via a pseudo tty? ...
    (comp.unix.shell)
  • Re: Detect child exit without SIGCHLD?
    ... > event loop process are busy. ... > You could select/poll the pipe fd in question at intervals. ... refactoring I just call waitpid with WNOHANG at periodic intervals. ...
    (comp.unix.programmer)
  • Re: Problem with Tcl_AsyncCreate()
    ... execute some other command on the command line, ... You're not in the event loop. ... set l [gets stdin] ... set eventLoop "done";# terminate the vwait eventloop ...
    (comp.lang.tcl)