repeat revision 249751
112315Sasami#!/bin/sh
212315Sasami#-
312315Sasami# Copyright (c) 2012-2013 Devin Teske
412315Sasami# All Rights Reserved.
512315Sasami#
612315Sasami# Redistribution and use in source and binary forms, with or without
712315Sasami# modification, are permitted provided that the following conditions
812315Sasami# are met:
912315Sasami# 1. Redistributions of source code must retain the above copyright
1012315Sasami#    notice, this list of conditions and the following disclaimer.
1112315Sasami# 2. Redistributions in binary form must reproduce the above copyright
1212315Sasami#    notice, this list of conditions and the following disclaimer in the
1312315Sasami#    documentation and/or other materials provided with the distribution.
1412315Sasami#
1512315Sasami# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1612315Sasami# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
1712315Sasami# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1812315Sasami# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1912315Sasami# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2012315Sasami# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2112315Sasami# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2212315Sasami# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2312315Sasami# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2412315Sasami# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2512315Sasami# SUCH DAMAGE.
2612315Sasami#
2712315Sasami# $FreeBSD: head/usr.sbin/bsdconfig/console/repeat 249751 2013-04-22 05:52:06Z dteske $
2812315Sasami#
2912315Sasami############################################################ INCLUDES
3012315Sasami
3112315SasamiBSDCFG_SHARE="/usr/share/bsdconfig"
3212315Sasami. $BSDCFG_SHARE/common.subr || exit 1
3312315Sasamif_dprintf "%s: loading includes..." "$0"
3412315Sasamif_include $BSDCFG_SHARE/dialog.subr
3512315Sasamif_include $BSDCFG_SHARE/mustberoot.subr
3612315Sasamif_include $BSDCFG_SHARE/sysrc.subr
3712315Sasami
3812315SasamiBSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="080.console"
3912315Sasamif_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
4012315Sasami
4112315Sasamiipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
4212315Sasami[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
4312315Sasami
4412315Sasami############################################################ FUNCTIONS
4512315Sasami
4612315Sasami# dialog_menu_main
4712315Sasami#
4812315Sasami# Display the dialog(1)-based application main menu.
4912315Sasami#
5012315Sasamidialog_menu_main()
5112315Sasami{
5212315Sasami	local menu_list size defaultitem=
5312315Sasami	local hline="$hline_choose_a_keyboard_repeat_rate"
5412315Sasami	local prompt="$msg_repeat_menu_text"
5512315Sasami
5612315Sasami	menu_list="
5712315Sasami		'$msg_default' '$msg_default_desc'
5812315Sasami		'$msg_slow'    '$msg_slow_desc'
5912315Sasami		'$msg_normal'  '$msg_normal_desc'
6012315Sasami		'$msg_fast'    '$msg_fast_desc'
6112315Sasami	" # END-QUOTE
6212315Sasami
6312315Sasami	size=$( eval f_dialog_menu_size \
6412315Sasami	        	\"\$DIALOG_TITLE\"     \
6512315Sasami	        	\"\$DIALOG_BACKTITLE\" \
6612315Sasami	                \"\$prompt\"           \
6712315Sasami	        	\"\$hline\"            \
6812315Sasami	        	$menu_list             )
6912315Sasami
7012315Sasami	case "$( f_sysrc_get keyrate )" in
7112315Sasami	slow) defaultitem="$msg_slow";;
7212315Sasami	normal) defaultitem="$msg_normal";;
7312315Sasami	fast) defaultitem="$msg_fast";;
7412315Sasami	[Nn][Oo]|'') defaultitem="$msg_default";;
7512315Sasami	esac
7612315Sasami
7712315Sasami	local dialog_menu
7812315Sasami	dialog_menu=$( eval $DIALOG \
7912315Sasami		--title \"\$DIALOG_TITLE\"         \
8012315Sasami		--backtitle \"\$DIALOG_BACKTITLE\" \
8112315Sasami		--hline \"\$hline\"                \
8212315Sasami		--ok-label \"\$msg_ok\"            \
8312315Sasami		--cancel-label \"\$msg_cancel\"    \
8412315Sasami		--default-item \"\$defaultitem\"   \
8512315Sasami		--menu \"\$prompt\" $size          \
8612315Sasami		$menu_list                         \
8712315Sasami		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
8812315Sasami	)
8912315Sasami	local retval=$?
9012315Sasami	setvar DIALOG_MENU_$$ "$dialog_menu"
9112315Sasami	return $retval
9212315Sasami}
9312315Sasami
9412315Sasami############################################################ MAIN
9512315Sasami
9612315Sasami# Incorporate rc-file if it exists
9712315Sasami[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc"
9812315Sasami
9912315Sasami#
10012315Sasami# Process command-line arguments
10112315Sasami#
10212315Sasamiwhile getopts dD:hSX flag; do
10312315Sasami	case "$flag" in
10412315Sasami	h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
10512315Sasami	esac
10612315Sasamidone
10712315Sasamishift $(( $OPTIND - 1 ))
10812315Sasami
10912315Sasami#
11012315Sasami# Initialize
11112315Sasami#
11212315Sasamif_dialog_title "$msg_system_console_keyboard_repeat_rate"
11312315Sasamif_dialog_backtitle "${ipgm:+bsdconfig }$pgm"
11412315Sasamif_mustberoot_init
11512315Sasami
11612315Sasami#
11712315Sasami# Launch application main menu
11812315Sasami#
119while :; do
120	dialog_menu_main
121	retval=$?
122	mtag=$( f_dialog_menutag )
123
124	[ $retval -eq 0 ] || f_die
125
126	case "$mtag" in
127	"$msg_slow") # Slow keyboard repeat rate
128		f_sysrc_set keyrate "slow" || f_die
129		break ;;
130	"$msg_normal") # "Normal" keyboard repeat rate
131		f_sysrc_set keyrate "normal" || f_die
132		break ;;
133	"$msg_fast") # Fast keyboard repeat rate
134		f_sysrc_set keyrate "fast" || f_die
135		break ;;
136	"$msg_default") # Use default keyboard repeat rate
137		f_sysrc_set keyrate "NO" || f_die
138		break ;;
139	esac
140
141done
142
143exit $SUCCESS
144
145################################################################################
146# END
147################################################################################
148