[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Added intra-field navigation sample
From: |
Damien Ruscoe |
Subject: |
Added intra-field navigation sample |
Date: |
Sun, 1 Jan 2017 21:54:38 +0000 |
I have created a sample application to demonstrate navigation within a
field. This maybe suitable for ncurses_programs as well as being added
to the documentation (
http://invisible-island.net/ncurses/NCURSES-Programming-HOWTO.html#INTRAFIELDNAVREQ
) as a sample.
Critique wanted please :)
Damien
--- new 2017-01-01 21:44:33.417336100 +0000
+++ form_field_navigation.c 2017-01-01 21:50:13.564662100 +0000
@@ -0,0 +1,107 @@
+#include <form.h>
+
+int main()
+{ FIELD *fields[2];
+ FORM *my_form;
+ int ch;
+
+ /* Initialize curses */
+ initscr();
+ cbreak();
+ noecho();
+ keypad(stdscr, TRUE);
+
+ int rows = 10, columns = 25, max = 200;
+ FIELD *field = new_field(rows, columns, 4, 28, 0, 0);
+
+ /* Set field options */
+ set_field_back(field, A_UNDERLINE); /* Print a line for the
option */
+ field_opts_off(field, O_AUTOSKIP); /* Don't go to next field
when this */
+ /* Field is filled up */
+ field_opts_off(field, O_STATIC); /* Allow the field to be
resizable */
+ set_max_field(field, max);
+
+ char *sample_buffer = "There's a line I have that our family was
designed more " \
+ "for public than for private. But there are
definitely " \
+ "some things that are only mine. I am
someone who dreams " \
+ "at night, and you don't know what I'm dreaming.";
+ set_field_buffer(field, 0, sample_buffer);
+
+ /* Initialize the fields */
+ fields[0] = field;
+ fields[1] = NULL;
+
+ /* Create the form and post it */
+ my_form = new_form(fields);
+ post_form(my_form);
+ refresh();
+
+ mvprintw(4, 10, "Multi-line Text:");
+ refresh();
+
+ /* Loop through to get user requests */
+ while((ch = getch()) != KEY_F(1))
+ { switch(ch)
+ {
+ case KEY_RIGHT:
+ case 'l':
+ form_driver(my_form, REQ_NEXT_CHAR);
+ break;
+ case KEY_LEFT:
+ case 'h':
+ form_driver(my_form, REQ_PREV_CHAR);
+ break;
+ case KEY_DOWN:
+ case 'j':
+ form_driver(my_form, REQ_DOWN_CHAR);
+ break;
+ case KEY_UP:
+ case 'k':
+ form_driver(my_form, REQ_UP_CHAR);
+ break;
+ case KEY_HOME:
+ case '0':
+ form_driver(my_form, REQ_BEG_LINE);
+ break;
+ case KEY_END:
+ case '$':
+ form_driver(my_form, REQ_END_LINE);
+ break;
+ case 'L':
+ form_driver(my_form, REQ_RIGHT_CHAR);
+ break;
+ case 'H':
+ form_driver(my_form, REQ_LEFT_CHAR);
+ break;
+ case 'J':
+ form_driver(my_form, REQ_NEXT_LINE);
+ break;
+ case 'K':
+ form_driver(my_form, REQ_PREV_LINE);
+ break;
+ case 'w':
+ form_driver(my_form, REQ_NEXT_WORD);
+ break;
+ case 'b':
+ form_driver(my_form, REQ_PREV_WORD);
+ break;
+ case 'g':
+ form_driver(my_form, REQ_BEG_FIELD);
+ break;
+ case 'G':
+ form_driver(my_form, REQ_END_FIELD);
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ /* Un post form and free the memory */
+ unpost_form(my_form);
+ free_form(my_form);
+ free_field(fields[0]);
+
+ endwin();
+ return 0;
+}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Added intra-field navigation sample,
Damien Ruscoe <=