xref: /freebsd/contrib/dialog/samples/form1 (revision 724b4bfdf1306e4f2c451b6d146fe0fe0353b2c8)
1#! /bin/sh
2# $Id: form1,v 1.15 2011/10/04 23:36:53 tom Exp $
3
4. ./setup-vars
5
6DIALOG_ERROR=254
7export DIALOG_ERROR
8
9backtitle="An Example for the use of --form:"
10
11ids=`id|sed -e 's/([^)]*)//g'`
12uid=`echo "$ids" | sed -e 's/^uid=//' -e 's/ .*//'`
13gid=`echo "$ids" | sed -e 's/^.* gid=//' -e 's/ .*//'`
14
15user="$USER"
16home="$HOME"
17
18returncode=0
19while test $returncode != 1 && test $returncode != 250
20do
21exec 3>&1
22value=`$DIALOG --ok-label "Submit" \
23	  --backtitle "$backtitle" "$@" \
24	  --form "Here is a possible piece of a configuration program." \
2520 50 0 \
26	"Username:" 1 1	"$user" 1 10 10 0 \
27	"UID:"      2 1	"$uid"  2 10  8 0 \
28	"GID:"      3 1	"$gid"  3 10  8 0 \
29	"HOME:"     4 1	"$home" 4 10 40 0 \
302>&1 1>&3`
31returncode=$?
32exec 3>&-
33
34show=`echo "$value" |sed -e 's/^/	/'`
35
36	case $returncode in
37	$DIALOG_CANCEL)
38		"$DIALOG" \
39		--clear \
40		--backtitle "$backtitle" \
41		--yesno "Really quit?" 10 30
42		case $? in
43		$DIALOG_OK)
44			break
45			;;
46		$DIALOG_CANCEL)
47			returncode=99
48			;;
49		esac
50		;;
51	$DIALOG_OK)
52		"$DIALOG" \
53		--clear \
54		--backtitle "$backtitle" --no-collapse --cr-wrap \
55		--msgbox "Resulting data:\n\
56$show" 10 40
57		;;
58	$DIALOG_HELP)
59		echo "Button 2 (Help) pressed."
60		exit
61		;;
62	$DIALOG_EXTRA)
63		echo "Button 3 (Extra) pressed."
64		exit
65		;;
66	$DIALOG_ERROR)
67		echo "ERROR!$value"
68		exit
69		;;
70	$DIALOG_ESC)
71		echo "ESC pressed."
72		exit
73		;;
74	*)
75		echo "Return code was $returncode"
76		exit
77		;;
78	esac
79done
80