repeat revision 251904
1171626Scognet#!/bin/sh
2171626Scognet#-
3171626Scognet# Copyright (c) 2012-2013 Devin Teske
4171626Scognet# All Rights Reserved.
5171626Scognet#
6171626Scognet# Redistribution and use in source and binary forms, with or without
7171626Scognet# modification, are permitted provided that the following conditions
8171626Scognet# are met:
9171626Scognet# 1. Redistributions of source code must retain the above copyright
10171626Scognet#    notice, this list of conditions and the following disclaimer.
11171626Scognet# 2. Redistributions in binary form must reproduce the above copyright
12171626Scognet#    notice, this list of conditions and the following disclaimer in the
13171626Scognet#    documentation and/or other materials provided with the distribution.
14171626Scognet#
15171626Scognet# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16171626Scognet# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
17171626Scognet# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18171626Scognet# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19171626Scognet# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20171626Scognet# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21171626Scognet# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22171626Scognet# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23171626Scognet# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24171626Scognet# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25171626Scognet# SUCH DAMAGE.
26171626Scognet#
27171626Scognet# $FreeBSD: head/usr.sbin/bsdconfig/console/repeat 251904 2013-06-18 07:33:45Z dteske $
28171626Scognet#
29171626Scognet############################################################ INCLUDES
30171626Scognet
31171626ScognetBSDCFG_SHARE="/usr/share/bsdconfig"
32171626Scognet. $BSDCFG_SHARE/common.subr || exit 1
33171626Scognetf_dprintf "%s: loading includes..." "$0"
34171626Scognetf_include $BSDCFG_SHARE/dialog.subr
35171626Scognetf_include $BSDCFG_SHARE/mustberoot.subr
36171626Scognetf_include $BSDCFG_SHARE/sysrc.subr
37171626Scognet
38171626ScognetBSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="080.console"
39171626Scognetf_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
40171626Scognet
41171626Scognetipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
42171626Scognet[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
43171626Scognet
44171626Scognet############################################################ FUNCTIONS
45171626Scognet
46171626Scognet# dialog_menu_main
47171626Scognet#
48171626Scognet# Display the dialog(1)-based application main menu.
49171626Scognet#
50171626Scognetdialog_menu_main()
51171626Scognet{
52171626Scognet	local prompt="$msg_repeat_menu_text"
53171626Scognet	local menu_list="
54171626Scognet		'$msg_default' '$msg_default_desc'
55171626Scognet		'$msg_slow'    '$msg_slow_desc'
56171626Scognet		'$msg_normal'  '$msg_normal_desc'
57171626Scognet		'$msg_fast'    '$msg_fast_desc'
58171626Scognet	" # END-QUOTE
59171626Scognet	local defaultitem= # Calculated below
60171626Scognet	local hline="$hline_choose_a_keyboard_repeat_rate"
61171626Scognet
62171626Scognet	local height width rows
63171626Scognet	eval f_dialog_menu_size height width rows \
64171626Scognet	                        \"\$DIALOG_TITLE\"     \
65171626Scognet	                        \"\$DIALOG_BACKTITLE\" \
66171626Scognet	                        \"\$prompt\"           \
67171626Scognet	                        \"\$hline\"            \
68171626Scognet	                        $menu_list
69171626Scognet
70171626Scognet	case "$( f_sysrc_get keyrate )" in
71171626Scognet	[Nn][Oo]|'') defaultitem="$msg_default" ;;
72171626Scognet	slow)        defaultitem="$msg_slow"    ;;
73171626Scognet	normal)      defaultitem="$msg_normal"  ;;
74171626Scognet	fast)        defaultitem="$msg_fast"    ;;
75171626Scognet	esac
76171626Scognet
77171626Scognet	local menu_choice
78171626Scognet	menu_choice=$( eval $DIALOG \
79171626Scognet		--title \"\$DIALOG_TITLE\"         \
80171626Scognet		--backtitle \"\$DIALOG_BACKTITLE\" \
81171626Scognet		--hline \"\$hline\"                \
82171626Scognet		--ok-label \"\$msg_ok\"            \
83171626Scognet		--cancel-label \"\$msg_cancel\"    \
84171626Scognet		--default-item \"\$defaultitem\"   \
85171626Scognet		--menu \"\$prompt\"                \
86171626Scognet		$height $width $rows               \
87171626Scognet		$menu_list                         \
88171626Scognet		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
89171626Scognet	)
90171626Scognet	local retval=$?
91171626Scognet	f_dialog_menutag_store -s "$menu_choice"
92171626Scognet	return $retval
93171626Scognet}
94171626Scognet
95171626Scognet############################################################ MAIN
96171626Scognet
97171626Scognet# Incorporate rc-file if it exists
98171626Scognet[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc"
99171626Scognet
100171626Scognet#
101171626Scognet# Process command-line arguments
102171626Scognet#
103171626Scognetwhile getopts h$GETOPTS_STDARGS flag; do
104171626Scognet	case "$flag" in
105171626Scognet	h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
106171626Scognet	esac
107171626Scognetdone
108171626Scognetshift $(( $OPTIND - 1 ))
109171626Scognet
110171626Scognet#
111171626Scognet# Initialize
112171626Scognet#
113171626Scognetf_dialog_title "$msg_system_console_keyboard_repeat_rate"
114171626Scognetf_dialog_backtitle "${ipgm:+bsdconfig }$pgm"
115171626Scognetf_mustberoot_init
116171626Scognet
117171626Scognet#
118171626Scognet# Launch application main menu
119171626Scognet#
120171626Scognetwhile :; do
121171626Scognet	dialog_menu_main || f_die
122171626Scognet	f_dialog_menutag_fetch mtag
123171626Scognet
124171626Scognet	case "$mtag" in
125171626Scognet	"$msg_slow") # Slow keyboard repeat rate
126171626Scognet		f_sysrc_set keyrate "slow" || f_die
127171626Scognet		break ;;
128171626Scognet	"$msg_normal") # "Normal" keyboard repeat rate
129171626Scognet		f_sysrc_set keyrate "normal" || f_die
130236987Simp		break ;;
131171626Scognet	"$msg_fast") # Fast keyboard repeat rate
132171626Scognet		f_sysrc_set keyrate "fast" || f_die
133171626Scognet		break ;;
134171626Scognet	"$msg_default") # Use default keyboard repeat rate
135171626Scognet		f_sysrc_set keyrate "NO" || f_die
136171626Scognet		break ;;
137171626Scognet	esac
138171626Scognetdone
139171626Scognet
140171626Scognetexit $SUCCESS
141171626Scognet
142171626Scognet################################################################################
143171626Scognet# END
144171626Scognet################################################################################
145171626Scognet