aboutsummaryrefslogtreecommitdiff
path: root/lib/libforms/examples
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libforms/examples')
-rw-r--r--lib/libforms/examples/Makefile6
-rw-r--r--lib/libforms/examples/example.c62
-rw-r--r--lib/libforms/examples/example.frm186
3 files changed, 162 insertions, 92 deletions
diff --git a/lib/libforms/examples/Makefile b/lib/libforms/examples/Makefile
index 4f0a23fafdd7c..4389b705c0436 100644
--- a/lib/libforms/examples/Makefile
+++ b/lib/libforms/examples/Makefile
@@ -3,7 +3,7 @@ NOMAN = yet
SRCS = example.c
-CFLAGS = -g -static
+CFLAGS = -static #-g
.if exists(${.CURDIR}/../obj)
FORMDIR=${.CURDIR}/../obj
@@ -11,7 +11,7 @@ FORMDIR=${.CURDIR}/../obj
FORMDIR=${.CURDIR}/..
.endif
-LDADD = -L${FORMDIR} -lforms -lncurses -lmytinfo -ll
-DPADD = /usr/lib/libforms.a
+LDADD = -L${FORMDIR} -lforms -ldialog -lncurses -lmytinfo -ll
+DPADD = ${LIBFORMS} ${LIBNCURSES}
.include <bsd.prog.mk>
diff --git a/lib/libforms/examples/example.c b/lib/libforms/examples/example.c
index 39c4432e15856..b08a4ea6e1f35 100644
--- a/lib/libforms/examples/example.c
+++ b/lib/libforms/examples/example.c
@@ -33,66 +33,28 @@
*/
#include <stdio.h>
#include <strhash.h>
+#include <ncurses.h>
#include "../forms.h"
-extern hash_table *global_bindings;
+void UserRoutine(OBJECT *);
main()
{
struct Tuple *tuple;
- struct Form *form;
+ struct Form *form1, *form2;
int res;
- initscr();
-
-
- if (form_load("example.frm") == FS_ERROR)
- exit(0);;
-
- form = form_start("example");
-
- if (!form) {
- err(-1, "No form `example' in example.frm returned");
+ if (load_objects("example.frm") == ST_ERROR)
exit(0);
- }
-
- keypad(form->window, TRUE);
- cbreak();
- noecho();
-
- tuple = form_get_tuple(global_bindings, "example", FT_FORM);
- if (!tuple)
- err(0, "No such form: example");
- else
- form = (struct Form *)tuple->addr;
- print_status("This is the status line");
+ bind_tuple(root_table, "User_Routine", TT_FUNC, &UserRoutine);
- form_bind_tuple(form->bindings, "exit_form", FT_FUNC, &exit_form);
- form_bind_tuple(form->bindings, "cancel_form", FT_FUNC, &cancel_form);
-
- res = form_show("example");
-
- while (form->status == FS_RUNNING) {
- do_field(form);
- wrefresh(form->window);
- }
-
- wclear(form->window);
- wrefresh(form->window);
-
- if (form->status == FS_EXIT) {
- printf("Your entries were:\n\n");
- tuple = form_get_tuple(form->bindings, "input1", FT_FIELD_INST);
- printf("Input 1 = %s\n", ((struct Field *)tuple->addr)->field.input->input);
- tuple = form_get_tuple(form->bindings, "input2", FT_FIELD_INST);
- printf("Input 2 = %s\n", ((struct Field *)tuple->addr)->field.input->input);
- tuple = form_get_tuple(form->bindings, "menu1", FT_FIELD_INST);
- res = ((struct Field *)tuple->addr)->field.menu->selected;
- printf("Menu selected = %d, %s\n", res,
- ((struct Field *)tuple->addr)->field.menu->options[res]);
- } else if (form->status == FS_CANCEL)
- printf("You cancelled the form\n");
+ start_object("adduser");
+}
- endwin();
+void
+UserRoutine(OBJECT *obj)
+{
+ /* Just draw a box and return */
+ exit (1);
}
diff --git a/lib/libforms/examples/example.frm b/lib/libforms/examples/example.frm
index 513ced2394457..eca43ab5675a6 100644
--- a/lib/libforms/examples/example.frm
+++ b/lib/libforms/examples/example.frm
@@ -1,54 +1,162 @@
-Colours example_colors {
- pair = red, yellow
- pair = blue, white
-}
-
-field1 { attributes = 0 text = "\standout This text is \bold bold and \blink flashy" }
+# An example form file for an adduser command
+!Forms Version name
-field2 {
- height = 2
- width = 22
- text = "This is an input fieldwith a default"
+Display screen1 {
+ Height 1000
+ Width 1000
+ Type Ncurses {
+ # libdialog compatible color pairs
+ ColorPairs {
+ 01 Cyan Blue
+ 02 Black Black
+ 03 Black White
+ 04 Yellow White
+ 05 White White
+ 06 White Blue
+ 07 Black White
+ 08 White Blue
+ 09 Red White
+ 10 Yellow Blue
+ 11 Black White
+ 12 Black White
+ 13 Black White
+ 14 Black White
+ 15 Yellow White
+ 16 White White
+ 17 Yellow White
+ 18 Black White
+ 19 White White
+ 20 Black White
+ 21 White Blue
+ 22 Yellow White
+ 23 Yellow Blue
+ 24 Red White
+ 25 Red Blue
+ 26 Black White
+ 27 White White
+ 28 Green White
+ 29 Green White
+ }
+ }
+ #
+ # The AttrTable assosciates attribute strings with numeric id's.
+ # It's up to the device dependant code to decide how to interprate an
+ # attribute id. For ncurses the id is treated as a color pair number.
+ # For other devices they'd likely be an index to some device specific
+ # structure declared above.
+ #
+ AttrTable {
+ screen 01
+ shadow 02
+ dialog 03
+ title 04
+ border 05
+ button_active 06
+ button_inactive 07
+ button_key_active 08
+ button_key_inactive 09
+ button_label_active 10
+ button_label_inactive 11
+ inputbox 12
+ inputbox_border 13
+ searchbox 14
+ searchbox_title 15
+ searchbox_border 16
+ position_indicator 17
+ menubox 18
+ menubox_border 19
+ item 20
+ item_selected 21
+ tag 22
+ tag_selected 23
+ tag_key 24
+ tag_key_selected 25
+ check 26
+ check_selected 27
+ uarrow 28
+ darrow 29
+ }
}
-field3 {
- width = 10
- default = "This is a default entry"
- limit = 30
+template {
+ Width 15
+ Text "This is defined as a template and duplicated here"
}
-field4 { text = "This is a labelled input field" }
+Window adduser on screen1 at 0,0 {
+ Attributes "\screen"
-field5 { label = "A temp. label" }
+ window at 1,1 {
+ Height 22
+ Width 75
+ Attributes "\dialog"
+ Active username
-field6 { text = "Some options to choose from: " }
+ box {
+ Attributes "\dialog"
+ Highlight "\border"
+ CallFunc draw_box
+ shadow {
+ Attributes "\shadow"
+ CallFunc draw_shadow
+ }
+ }
-field7 { selected = 0 options = "Choose", "another", "of", "these" }
+ Title at 0,9 { Text " This is a title " }
-field8 { width = 6 action = "EXIT" function = exit_form }
+ username at 5,20 {
+ Height 1
+ Width 30
+ Attributes "\screen"
+ Highlight "\tag_selected"
-field9 {
-action = "CANCEL"
-function = cancel_form
-}
+ Next shells
+
+ Input "nobody"
+
+ exp at 3,3 {
+ Attributes "\dialog"
+ Text "The is an input object:"
+ }
+ prompt at 5,3 {
+ Text "Username: "
+ }
+ }
+
+ shells at 9,20 {
+ Attributes "\dialog"
+ Highlight "\tag_selected"
+ Next button
+ Options {
+ "sh"
+ "csh"
+ "tcsh"
+ "bash"
+ }
-Form example at 0,0 {
- height = 25
- width = 80
- start = input1
- colortable = example
- attributes = 0
+ exp at 7,3 {
+ Attributes "\dialog"
+ Text "This is a horizontal menu:"
+ }
+ prompt at 9,3 { Text "Select a shell: "}
+ }
- Title {attributes = 0 text = "A Simple Demo"} at 0,30
+ button at 14,9 {
+ Height 3
+ Width 7
+ Attributes "\tag_key_selected"
+ Highlight "\tag_selected"
+ Active button
- field1 at 3,23
- field2 at 7, 2
- field4 at 11, 2
- field6 at 15, 2
+ button_box at 14,9 {
+ CallFunc draw_box
+ }
- input1 {field3} at 7,45, next=input2,down=input2,up=quit,right=input2
- input2 {field5} at 11,45, next=menu1,down=menu1,up=input1,right=menu1
- menu1 {field7} at 15,45, next=quit,down=quit,up=input2,right=quit
- quit {field8} at 20,20, next=cancel,down=input1,up=menu1,right=cancel
- cancel {field9} at 20,43, next=input1,down=input1,up=menu1,right=input1
+ button at 15, 10 {
+ Up username Down username
+ Action User_Routine
+ Label "QUIT"
+ }
+ }
+ }
}