Subject: lib/17480: libform, field movement behavior destroys fields, leaves characters
To: None <>
From: None <>
List: netbsd-bugs
Date: 07/05/2002 12:24:07
>Number:         17480
>Category:       lib
>Synopsis:       libform, field movement behavior destroys fields, leaves characters
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Jul 04 09:20:01 PDT 2002
>Originator:     rob/tyler
>Release:        NetBSD 1.6B (-current build July 3)
Wasabi Systems
System: NetBSD elysium 1.6B NetBSD 1.6B (elysium) #0: Wed Jul 3 00:39:26 EST 2002 rtr@elysium:/usr/src/sys/arch/i386/compile/elysium i386
Architecture: i386
Machine: i386
	There are two problems included in this PR the second more annoying.

	1. fields have no fore/back visibility while buffer is NULL.

	2. Rmoving and adding characters to fields "messes" them up.

1.	Create editable form fields, set the fore/back attribute to A_REVERSE
	when program is run form fields don't appear as A_REVERSE until
	buffer contains something (this may include zero length string).

	A work around is to set the buffer to "".  This may be intended
	behavior but it's not particularly useful. 

2.	Removing and adding characters to fields "messes" them up.
	Run the included program with the following key sequence in order
	to view all problems.  It's likely they're all related.

	- hold 'f' (or any other printable key) until both fields are full.
	- hold backspace to attempt to remove all characters in field 2
	- All characters will be removed with exception to first character
	  which appears to the left of the cursor. 
	- It's necessary to move to the end of field in order to backspace
	  this charater (unpleasant)

	- press arrow up once, press arrow right once this should move
	  cursor to end of field one but doesn't.  It moves to second last
	  position of field one (unpleasant)

	- hold backspace to attempt to remove all characters in field 1
	- all characters except character that was right of the cursor will
	  be removed.  Then cursor itself will disappear once it reaches 
	  first position of field (unpleasant)
	- Arrow down once to move back to field 2
	- First position of field 2 disappears completely and will remain
	  unusable. This can be observed by arrow key up again to leave the
	  field. (unpleasant)

/* begin code snippet */

#include <form.h>

FORM *form;
FIELD *fields[5];

main(int argc, char **argv)
        int c;

	keypad(stdscr, TRUE);

	fields[0] = new_field(1, 6, 0, 0, 0, 0);
	fields[1] = new_field(1, 6, 0, 8, 0, 0);
	fields[2] = new_field(1, 6, 1, 0, 0, 0);
	fields[3] = new_field(1, 6, 1, 8, 0, 0);
	fields[4] = NULL;

	/* labels */
	set_field_buffer(fields[0], 0, "One:");
	set_field_buffer(fields[2], 0, "Two:");
	field_opts_off(fields[0], O_ACTIVE);
	field_opts_off(fields[2], O_ACTIVE);

	set_field_fore(fields[1], A_REVERSE);
	set_field_fore(fields[3], A_REVERSE);
	set_field_back(fields[1], A_REVERSE);
	set_field_back(fields[3], A_REVERSE);

	/* necessary if we want to "see" the fields */
	set_field_buffer(fields[1], 0, "");
	set_field_buffer(fields[3], 0, "");

	form = new_form(fields);

	set_form_sub(form, stdscr);

	for (;;) {

		switch (c = getch()) {

		case KEY_UP:
			form_driver(form, REQ_UP_FIELD);

		case KEY_RIGHT:
			form_driver(form, REQ_END_FIELD);

		case KEY_DOWN:
			form_driver(form, REQ_DOWN_FIELD);

			form_driver(form, REQ_DEL_PREV);

			form_driver(form, c);



	/* don't bother cleaning up after ourselves */


/* end code snippet */

	1. Could initialize buffer to "" or apply fore/back attribute while
	   buffer is NULL.

	2. Don't know, looks ugly.