[prog] ncurses forms library

Elizabeth Barham lizzy at soggytrousers.net
Wed Nov 5 22:59:53 EST 2003


ed writes:

> Thank you very much for the code!  Now I can get input from the form
> and get something done.

> Just a couple of questions about how this input works.

>    Where does the keyboard input go during the ch = getch loop?

  while( (ch = getch()) != '\n') {
    count++;
    form_driver(my_form, ch);
  }

> I assume form_driver( my_form, ch); places it into field[0], yes?

Perhaps but it may also place it into some kind of internal, private
buffer.

> But when I try to track this input using DDD debug ( p field[0]@10),
> I can't see anything going in. When I enter 123, shouldn't I see the
> something like 31, 32, 33 inside field[0] ?

> Why is it necessary to use REQ_END_LINE ?

My guess is that something is needed to sort of flush the buffer - to
tell ncurses that we've completed a line and it should update
my_form's buffer. While looking for a solution I checked the man page
for some kind of flush function because it seemed as though one was
necessary.

>From that web page: http://en.tldp.org/HOWTO/NCURSES-Programming-HOWTO/forms.html

I noticed REQ_END_LINE was being called so gave it a shot and it
worked so that may or may not be the best method of doing it. As such
you may want to wade through ncurses' source code for a more fitting
solution.

> ch = '\n';
> form_driver( my_form, ch );
> form_driver( my_form, REQ_END_LINE );
> buff = field_buffer(field[0], 0);
> assert( buff != 0 );
> mvprintw(17,4, "buff = %s\n", buff);
> refresh();

>     I thought the form_driver automatically incremented to the right
> before entering the next character Y/N ?

It does on the screen and (perhaps) into ncurses' own internal
buffer. But, if it stays in that internal buffer then we won't be able
to use it. So by using REQ_END_LINE, ncurses flushes the buffer out
into my_form (I guess!! I have not read the source code and this
method is somewhat of a hack.).

> Thanks a lot for all your help! I would never have figured it out on
> my own.

Perhaps if you follow form_driver in your debugger you can see what
ncurses does with each character.

When playing with the original code I noticed that if I typed more
characters than the line length so that the cursor wrapped back
around, the mvprintw() call did respond with some data, specifically
the data that was placed into the field prior to ncurses wrapping the
cursor. Thus, some kind of buffering and flushing was
occurring. Perhaps going to the end of the line causes ncurses to
flush its on-screen buffer into my_form's buffer.

Regards, Elizabeth


More information about the Programming mailing list