repeat revision 252178
176195Sbrian#!/bin/sh
276195Sbrian#-
376358Sbrian# Copyright (c) 2012-2013 Devin Teske
476358Sbrian# All Rights Reserved.
576358Sbrian#
676195Sbrian# Redistribution and use in source and binary forms, with or without
776195Sbrian# modification, are permitted provided that the following conditions
876195Sbrian# are met:
976195Sbrian# 1. Redistributions of source code must retain the above copyright
1076195Sbrian#    notice, this list of conditions and the following disclaimer.
1176195Sbrian# 2. Redistributions in binary form must reproduce the above copyright
1276195Sbrian#    notice, this list of conditions and the following disclaimer in the
1376195Sbrian#    documentation and/or other materials provided with the distribution.
1476195Sbrian#
1576195Sbrian# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1676195Sbrian# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
1776195Sbrian# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1876195Sbrian# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1976195Sbrian# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2076195Sbrian# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2176195Sbrian# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2276195Sbrian# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2376195Sbrian# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2476195Sbrian# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2576195Sbrian# SUCH DAMAGE.
2676195Sbrian#
2776195Sbrian# $FreeBSD: head/usr.sbin/bsdconfig/console/repeat 252178 2013-06-24 20:58:54Z dteske $
2876195Sbrian#
2976195Sbrian############################################################ INCLUDES
3076195Sbrian
3176195SbrianBSDCFG_SHARE="/usr/share/bsdconfig"
3276195Sbrian. $BSDCFG_SHARE/common.subr || exit 1
3376195Sbrianf_dprintf "%s: loading includes..." "$0"
3476195Sbrianf_include $BSDCFG_SHARE/dialog.subr
3576195Sbrianf_include $BSDCFG_SHARE/mustberoot.subr
3676195Sbrianf_include $BSDCFG_SHARE/sysrc.subr
3776195Sbrian
3890684SbdeBSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="080.console"
3990684Sbdef_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
4076195Sbrian
4176195Sbrianipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
4276195Sbrian[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
4376195Sbrian
4476195Sbrian############################################################ FUNCTIONS
4576195Sbrian
4676195Sbrian# dialog_menu_main
4776195Sbrian#
48129879Sphk# Display the dialog(1)-based application main menu.
4976195Sbrian#
5076195Sbriandialog_menu_main()
5176195Sbrian{
5276195Sbrian	local prompt="$msg_repeat_menu_text"
5376195Sbrian	local menu_list="
5476195Sbrian		'$msg_default' '$msg_default_desc'
5576195Sbrian		'$msg_slow'    '$msg_slow_desc'
5676848Sbrian		'$msg_normal'  '$msg_normal_desc'
5776853Sbrian		'$msg_fast'    '$msg_fast_desc'
5876853Sbrian	" # END-QUOTE
5976853Sbrian	local defaultitem= # Calculated below
6076853Sbrian	local hline="$hline_choose_a_keyboard_repeat_rate"
6176195Sbrian
6276195Sbrian	local height width rows
6376195Sbrian	eval f_dialog_menu_size height width rows \
6476195Sbrian	                        \"\$DIALOG_TITLE\"     \
6576195Sbrian	                        \"\$DIALOG_BACKTITLE\" \
6676195Sbrian	                        \"\$prompt\"           \
6776195Sbrian	                        \"\$hline\"            \
6876195Sbrian	                        $menu_list
6976195Sbrian
7076195Sbrian	case "$( f_sysrc_get keyrate )" in
7176195Sbrian	[Nn][Oo]|'') defaultitem="$msg_default" ;;
7276195Sbrian	slow)        defaultitem="$msg_slow"    ;;
7376195Sbrian	normal)      defaultitem="$msg_normal"  ;;
7476195Sbrian	fast)        defaultitem="$msg_fast"    ;;
7576195Sbrian	esac
7676195Sbrian
7776195Sbrian	local menu_choice
7876195Sbrian	menu_choice=$( eval $DIALOG \
7976195Sbrian		--title \"\$DIALOG_TITLE\"         \
8076195Sbrian		--backtitle \"\$DIALOG_BACKTITLE\" \
8176195Sbrian		--hline \"\$hline\"                \
8276195Sbrian		--ok-label \"\$msg_ok\"            \
8376195Sbrian		--cancel-label \"\$msg_cancel\"    \
8476195Sbrian		--default-item \"\$defaultitem\"   \
8576195Sbrian		--menu \"\$prompt\"                \
8676195Sbrian		$height $width $rows               \
8776195Sbrian		$menu_list                         \
8876195Sbrian		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
8976195Sbrian	)
9076195Sbrian	local retval=$?
9176195Sbrian	f_dialog_menutag_store -s "$menu_choice"
9276195Sbrian	return $retval
9376195Sbrian}
9476195Sbrian
9576195Sbrian############################################################ MAIN
9676195Sbrian
9776195Sbrian# Incorporate rc-file if it exists
9876195Sbrian[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc"
9976195Sbrian
10076195Sbrian#
10176195Sbrian# Process command-line arguments
10276195Sbrian#
10376195Sbrianwhile getopts h$GETOPTS_STDARGS flag; do
10476195Sbrian	case "$flag" in
10576195Sbrian	h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
10676195Sbrian	esac
10776195Sbriandone
10889062Smsmithshift $(( $OPTIND - 1 ))
10991445Speter
11076195Sbrian#
11176195Sbrian# Initialize
11276195Sbrian#
11376195Sbrianf_dialog_title "$msg_system_console_keyboard_repeat_rate"
11476195Sbrianf_dialog_backtitle "${ipgm:+bsdconfig }$pgm"
11576195Sbrianf_mustberoot_init
11676195Sbrian
11776195Sbrian#
11876195Sbrian# Launch application main menu
11976195Sbrian#
12076195Sbriandialog_menu_main || f_die
12176195Sbrianf_dialog_menutag_fetch mtag
12276195Sbrian
12376195Sbrianrepeat_rate_to_set=
12476195Sbriancase "$mtag" in
12576195Sbrian"$msg_default") repeat_rate_to_set="NO"     ;; # Use default repeat rate
12676195Sbrian"$msg_slow")    repeat_rate_to_set="slow"   ;; # Slow keyboard repeat rate
12776195Sbrian"$msg_normal")  repeat_rate_to_set="normal" ;; # "Normal" keyboard repeat rate
12876195Sbrian"$msg_fast")    repeat_rate_to_set="fast"   ;; # Fast keyboard repeat rate
12976195Sbrianesac
13076195Sbrian
13176195Sbrianif [ "$repeat_rate_to_set" ]; then
13276195Sbrian	f_sysrc_set keyrate "$repeat_rate_to_set" || f_die
13376195Sbrian	break
13476195Sbrianelse
13576195Sbrian	f_die 1 "$msg_unknown_repeat_rate"
13676195Sbrianfi
13776195Sbrian
13876195Sbrianexit $SUCCESS
13976195Sbrian
14076195Sbrian################################################################################
14176195Sbrian# END
14276195Sbrian################################################################################
14376195Sbrian