summaryrefslogtreecommitdiffstats
path: root/lib/libforms/examples/test.c
diff options
context:
space:
mode:
authorpaul <paul@FreeBSD.org>1995-01-10 04:00:37 +0000
committerpaul <paul@FreeBSD.org>1995-01-10 04:00:37 +0000
commit62368d936ed04f0f0dd494db60e18247324d6bf8 (patch)
tree12e65d39d2314ca461f1e4b7bbc73652944dd4b6 /lib/libforms/examples/test.c
parentdaea0811576934884619d970ea003569a0c67f81 (diff)
downloadFreeBSD-src-62368d936ed04f0f0dd494db60e18247324d6bf8.zip
FreeBSD-src-62368d936ed04f0f0dd494db60e18247324d6bf8.tar.gz
New forms library. This provides some basic functions for writing
input forms. It has the following simple fields: Text fields: Just titles, labels etc. Input fields: An editable text field that may or may not have an initial default value. Labelled input field: This is an input field that has an initial informative entry in it but it vanishes when you start editing the field. Toggle fields: These are fields with a pre-defined list of options which you cycle through using the space bar. Action fields: These are button type fields that call functions when they are selected. A simple demo is included in examples.
Diffstat (limited to 'lib/libforms/examples/test.c')
-rw-r--r--lib/libforms/examples/test.c89
1 files changed, 89 insertions, 0 deletions
diff --git a/lib/libforms/examples/test.c b/lib/libforms/examples/test.c
new file mode 100644
index 0000000..1fc3836
--- /dev/null
+++ b/lib/libforms/examples/test.c
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 1995 Paul Richards.
+ *
+ * All rights reserved.
+ *
+ * This software may be used, modified, copied, distributed, and
+ * sold, in both source and binary form provided that the above
+ * copyright and these terms are retained, verbatim, as the first
+ * lines of this file. Under no circumstances is the author
+ * responsible for the proper functioning of this software, nor does
+ * the author assume any responsibility for damages incurred with
+ * its use.
+ */
+
+#include "../forms.h"
+
+main()
+{
+
+ int res;
+
+ char *string0 = "A simple demo of the current forms widgets";
+ char *string1 = "Hey, I can flash boldly";
+ char *string2 = "This is an input field with default:";
+ char *string4 = "This is a labelled input field:";
+ char *string6 = "Some options to choose from: ";
+
+ char *options7[] = {"Choose", "one", "of", "these"};
+
+ struct text_field field0 = {string0};
+ struct text_field field1 = {string1};
+ struct text_field field2 = {string2};
+ struct input_field field3 = {0,"Default entry",0};
+ struct text_field field4 = {string4};
+ struct input_field field5 = {1,"A place filler",0};
+ struct text_field field6 = {string6};
+ struct menu_field field7 = {4, 0, options7};
+ struct action_field field8 = {"EXIT",&exit_form};
+ struct action_field field9 = {"CANCEL",&cancel_form};
+
+ struct field field[] = {
+ {F_TEXT, 0, 15, 80, 80, A_BOLD,
+ 0, 0, 0, 0, 0, (struct text_field *)&field0},
+ {F_TEXT, 3, 23, 25, 15, A_BLINK|A_BOLD,
+ 0, 0, 0, 0, 0, &field1},
+ {F_TEXT, 7, 2, 40, 40, F_DEFATTR,
+ 0, 0, 0, 0, 0, &field2},
+ {F_INPUT, 7, 45, 15, 30, F_DEFATTR,
+ 5, -1, 5, -1, -1, (struct text_field *)&field3},
+ {F_TEXT, 11, 2, 40, 40, F_DEFATTR,
+ 0, 0, 0, 0, 0, &field4},
+ {F_INPUT, 11, 45, 15, 30, F_DEFATTR,
+ 7, 3, 7, -1, -1, (struct text_field *)&field5},
+ {F_TEXT, 15, 2, 40, 40, F_DEFATTR,
+ 0, 0, 0, 0, 0, (struct text_field *)&field6},
+ {F_MENU, 15, 45, 10, 10, F_DEFATTR,
+ 8, 5, 8, -1, -1, (struct text_field *)&field7},
+ {F_ACTION, 20, 20, 6, 6, (A_BOLD|A_REVERSE),
+ 0, 7, -1, -1, 9, (struct text_field *)&field8},
+ {F_ACTION, 20, 43, 6, 6, (A_BOLD|A_REVERSE),
+ 3, 3, 3, 7, 3, (struct text_field *)&field9},
+ {F_END, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
+ };
+
+ struct form form = {0, 3, field, 25, 80, 0, 0, 0};
+ form.field = field;
+
+ initscr();
+
+ initfrm(&form);
+
+ keypad(form.window, TRUE);
+ while (!(res = update_form(&form)));
+
+
+ wclear(form.window);
+ wrefresh(form.window);
+
+ if (res == F_DONE) {
+ printf("You're entries were:\n\n");
+ printf("%s\n",field[3].field.input->input);
+ printf("%s\n",field[5].field.input->input);
+ printf("%s\n",field[7].field.menu->options[field[7].field.menu->selected]);
+ } else if (res == F_CANCEL)
+ printf("You cancelled the form\n");
+
+ endfrm(&form);
+ endwin();
+}
OpenPOWER on IntegriCloud