1program form_basic; 2{ 3 Example 25. Forms Basics 4 from ncurses howto 5 6 Possible bug: moving cursors before first char doesn't seem to work. 7} 8{$MODE OBJFPC} 9 10uses 11 ncurses, form; 12 13var 14 field: array[0..2] of PFIELD; 15 my_form: PFORM; 16 ch: Longint; 17begin 18 19try 20 (* Initialize curses *) 21 initscr(); 22 cbreak(); 23 noecho(); 24 keypad(stdscr, TRUE); 25 26 (* Initialize the fields *) 27 field[0] := new_field(1, 10, 4, 18, 0, 0); 28 field[1] := new_field(1, 10, 6, 18, 0, 0); 29 field[2] := nil; 30 31 (* Set field options *) 32 set_field_back(field[0], A_UNDERLINE); { Print a line for the option } 33 field_opts_off(field[0], O_AUTOSKIP); { Don't go to next field when this } 34 { Field is filled up } 35 set_field_back(field[1], A_UNDERLINE); 36 field_opts_off(field[1], O_AUTOSKIP); 37 38 (* Create the form and post it *) 39 my_form := new_form(field); 40 post_form(my_form); 41 refresh(); 42 43 mvprintw(2, 10, 'Cursor up/down to move, F1 to Exit'); 44 mvprintw(4, 10, 'Value 1:'); 45 mvprintw(6, 10, 'Value 2:'); 46 refresh(); 47 48 (* Loop through to get user requests *) 49 ch := getch(); 50 while ch <> KEY_F(1) do 51 begin 52 case ch of 53 KEY_DOWN: 54 (* Go to next field *) 55 begin 56 form_driver(my_form, REQ_NEXT_FIELD); 57 { Go to the end of the present buffer 58 Leaves nicely at the last character } 59 form_driver(my_form, REQ_END_LINE); 60 end; 61 KEY_UP: 62 (* Go to previous field *) 63 begin 64 form_driver(my_form, REQ_PREV_FIELD); 65 form_driver(my_form, REQ_END_LINE); 66 end; 67 else 68 { If this is a normal character, it gets 69 Printed } 70 form_driver(my_form, ch); 71 end; 72 ch := getch(); 73 end 74 finally 75 (* Un post form and free the memory *) 76 unpost_form(my_form); 77 free_form(my_form); 78 free_field(field[0]); 79 free_field(field[1]); 80 81 endwin(); 82 end; 83end.