xref: /freebsd/contrib/dialog/samples/form1 (revision a96ef4501919d7ac08e94e98dc34b0bdd744802b)
14c8945a0SNathan Whitehorn#! /bin/sh
2*a96ef450SBaptiste Daroussin# $Id: form1,v 1.18 2020/11/26 00:34:39 tom Exp $
34c8945a0SNathan Whitehorn
44c8945a0SNathan Whitehorn. ./setup-vars
54c8945a0SNathan Whitehorn
64c8945a0SNathan WhitehornDIALOG_ERROR=254
74c8945a0SNathan Whitehornexport DIALOG_ERROR
84c8945a0SNathan Whitehorn
94c8945a0SNathan Whitehornbacktitle="An Example for the use of --form:"
104c8945a0SNathan Whitehorn
114c8945a0SNathan Whitehornids=`id|sed -e 's/([^)]*)//g'`
124c8945a0SNathan Whitehornuid=`echo "$ids" | sed -e 's/^uid=//' -e 's/ .*//'`
134c8945a0SNathan Whitehorngid=`echo "$ids" | sed -e 's/^.* gid=//' -e 's/ .*//'`
144c8945a0SNathan Whitehorn
154c8945a0SNathan Whitehornuser="$USER"
164c8945a0SNathan Whitehornhome="$HOME"
174c8945a0SNathan Whitehorn
184c8945a0SNathan Whitehornreturncode=0
194c8945a0SNathan Whitehornwhile test $returncode != 1 && test $returncode != 250
204c8945a0SNathan Whitehorndo
214c8945a0SNathan Whitehornexec 3>&1
22*a96ef450SBaptiste Daroussinreturntext=`$DIALOG --ok-label "Submit" \
234c8945a0SNathan Whitehorn	  --backtitle "$backtitle" "$@" \
244c8945a0SNathan Whitehorn	  --form "Here is a possible piece of a configuration program." \
254c8945a0SNathan Whitehorn20 50 0 \
264c8945a0SNathan Whitehorn	"Username:" 1 1	"$user" 1 10 10 0 \
274c8945a0SNathan Whitehorn	"UID:"      2 1	"$uid"  2 10  8 0 \
284c8945a0SNathan Whitehorn	"GID:"      3 1	"$gid"  3 10  8 0 \
294c8945a0SNathan Whitehorn	"HOME:"     4 1	"$home" 4 10 40 0 \
304c8945a0SNathan Whitehorn2>&1 1>&3`
314c8945a0SNathan Whitehornreturncode=$?
324c8945a0SNathan Whitehornexec 3>&-
334c8945a0SNathan Whitehorn
34*a96ef450SBaptiste Daroussinshow=`echo "$returntext" |sed -e 's/^/	/'`
354c8945a0SNathan Whitehorn
364c8945a0SNathan Whitehorn	case $returncode in
374c8945a0SNathan Whitehorn	$DIALOG_CANCEL)
384c8945a0SNathan Whitehorn		"$DIALOG" \
394c8945a0SNathan Whitehorn		--clear \
404c8945a0SNathan Whitehorn		--backtitle "$backtitle" \
414c8945a0SNathan Whitehorn		--yesno "Really quit?" 10 30
424c8945a0SNathan Whitehorn		case $? in
434c8945a0SNathan Whitehorn		$DIALOG_OK)
444c8945a0SNathan Whitehorn			break
454c8945a0SNathan Whitehorn			;;
464c8945a0SNathan Whitehorn		$DIALOG_CANCEL)
474c8945a0SNathan Whitehorn			returncode=99
484c8945a0SNathan Whitehorn			;;
494c8945a0SNathan Whitehorn		esac
504c8945a0SNathan Whitehorn		;;
514c8945a0SNathan Whitehorn	$DIALOG_OK)
524c8945a0SNathan Whitehorn		"$DIALOG" \
534c8945a0SNathan Whitehorn		--clear \
544c8945a0SNathan Whitehorn		--backtitle "$backtitle" --no-collapse --cr-wrap \
554c8945a0SNathan Whitehorn		--msgbox "Resulting data:\n\
564c8945a0SNathan Whitehorn$show" 10 40
574c8945a0SNathan Whitehorn		;;
584c8945a0SNathan Whitehorn	$DIALOG_HELP)
594c8945a0SNathan Whitehorn		echo "Button 2 (Help) pressed."
604c8945a0SNathan Whitehorn		exit
614c8945a0SNathan Whitehorn		;;
624c8945a0SNathan Whitehorn	$DIALOG_EXTRA)
634c8945a0SNathan Whitehorn		echo "Button 3 (Extra) pressed."
644c8945a0SNathan Whitehorn		exit
654c8945a0SNathan Whitehorn		;;
664c8945a0SNathan Whitehorn	*)
67*a96ef450SBaptiste Daroussin		. ./report-button
684c8945a0SNathan Whitehorn		exit
694c8945a0SNathan Whitehorn		;;
704c8945a0SNathan Whitehorn	esac
714c8945a0SNathan Whitehorndone
72