[Midnightbsd-cvs] src [11312] trunk/usr.sbin/bsdinstall/scripts/keymap: update keymap

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Wed Jul 4 10:12:58 EDT 2018


Revision: 11312
          http://svnweb.midnightbsd.org/src/?rev=11312
Author:   laffer1
Date:     2018-07-04 10:12:58 -0400 (Wed, 04 Jul 2018)
Log Message:
-----------
 update keymap

Modified Paths:
--------------
    trunk/usr.sbin/bsdinstall/scripts/keymap

Property Changed:
----------------
    trunk/usr.sbin/bsdinstall/scripts/keymap

Modified: trunk/usr.sbin/bsdinstall/scripts/keymap
===================================================================
--- trunk/usr.sbin/bsdinstall/scripts/keymap	2018-07-04 14:11:34 UTC (rev 11311)
+++ trunk/usr.sbin/bsdinstall/scripts/keymap	2018-07-04 14:12:58 UTC (rev 11312)
@@ -1,6 +1,7 @@
 #!/bin/sh
 #-
 # Copyright (c) 2011 Nathan Whitehorn
+# Copyright (c) 2013-2015 Devin Teske
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -24,13 +25,215 @@
 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 # SUCH DAMAGE.
 #
+# $FreeBSD: stable/10/usr.sbin/bsdinstall/scripts/keymap 290291 2015-11-02 22:07:25Z dteske $
 # $MidnightBSD$
-# $FreeBSD: src/usr.sbin/bsdinstall/scripts/keymap,v 1.3 2011/10/06 14:22:38 nwhitehorn Exp $
+#
+############################################################ INCLUDES
+ 
+BSDCFG_SHARE="/usr/share/bsdconfig"
+. $BSDCFG_SHARE/common.subr || exit 1
+f_dprintf "%s: loading includes..." "$0"
+f_include $BSDCFG_SHARE/dialog.subr
+f_include $BSDCFG_SHARE/keymap.subr
+f_include $BSDCFG_SHARE/sysrc.subr
 
-kbdcontrol -d >/dev/null 2>&1
-if [ $? -eq 0 ]; then
-	dialog --backtitle "MidnightBSD Installer" --title "Keymap Selection" \
-	    --yesno "Would you like to set a non-default key mapping for your keyboard?" 0 0 || exit 0
-	exec 3>&1
-	kbdmap 2>&1 1>&3 | grep 'keymap=' > $BSDINSTALL_TMPETC/rc.conf.keymap
+############################################################ CONFIGURATION
+
+#
+# Default file to store keymap selection in
+#
+: ${KEYMAPFILE:=$BSDINSTALL_TMPETC/rc.conf.keymap}
+
+#
+# Default path to keymap INDEX containing descriptions
+#
+: ${MAPDESCFILE:=/usr/share/syscons/keymaps/INDEX.keymaps}
+
+############################################################ GLOBALS
+
+#
+# Strings that should be moved to an i18n file and loaded with f_include_lang()
+#
+hline_arrows_tab_enter="Press arrows, TAB or ENTER"
+msg_continue_with_keymap="Continue with %s keymap"
+msg_default="default"
+msg_error="Error"
+msg_freebsd_installer="MidnightBSD Installer"
+msg_keymap_menu_text="The system console driver for MidnightBSD defaults to standard \"US\"\nkeyboard map. Other keymaps can be chosen below."
+msg_keymap_selection="Keymap Selection"
+msg_ok="OK"
+msg_select="Select"
+msg_test_keymap="Test %s keymap"
+msg_test_the_currently_selected_keymap="Test the currently selected keymap"
+msg_test_the_keymap_by_typing="Test the keymap by typing letters, numbers, and symbols. Characters\nshould match labels on the keyboard keys. Press Enter to stop testing."
+
+############################################################ FUNCTIONS
+
+# dialog_keymap_test $keymap
+#
+# Activate $keymap and display an input box (without cancel button) for the
+# user to test keyboard input and return. Always returns success.
+#
+dialog_keymap_test()
+{
+	local keym="$1"
+	local title= # Calculated below
+	local btitle= # Calculated below
+	local prompt="$msg_test_the_keymap_by_typing"
+	local hline=
+
+	# Attempt to activate the keymap
+	if [ "$keym" ]; then
+		local err
+		err=$( f_keymap_kbdcontrol "$keym" 2>&1 > /dev/null )
+		if [ "$err" ]; then
+			f_dialog_title "$msg_error"
+			f_dialog_msgbox "$err"
+			f_dialog_title_restore
+			return $FAILURE
+		fi
+	fi
+
+	f_dialog_title "$( printf "$msg_test_keymap" "${keym:-$msg_default}" )"
+	title="$DIALOG_TITLE"
+	btitle="$DIALOG_BACKTITLE"
+	f_dialog_title_restore
+
+	local height width
+	f_dialog_inputbox_size height width \
+		"$title" "$btitle" "$prompt" "" "$hline"
+
+	$DIALOG \
+		--title "$title"      \
+		--backtitle "$btitle" \
+		--hline "$hline"      \
+		--ok-label "$msg_ok"  \
+		--no-cancel           \
+		--inputbox "$prompt"  \
+		$height $width        \
+		2>/dev/null >&$DIALOG_TERMINAL_PASSTHRU_FD
+
+	return $DIALOG_OK
+}
+
+############################################################ MAIN
+
+#
+# Initialize
+#
+f_dialog_title "$msg_keymap_selection"
+f_dialog_backtitle "$msg_freebsd_installer"
+
+#
+# Die immediately if we can't dump the current keyboard map
+#
+#error=$( kbdcontrol -d 2>&1 > /dev/null ) || f_die $FAILURE "%s" "$error"
+
+# Capture Ctrl-C for clean-up
+trap 'rm -f $KEYMAPFILE; exit $FAILURE' SIGINT
+
+# Get a value from rc.conf(5) as initial value (if not being scripted)
+f_getvar $VAR_KEYMAP keymap
+if [ ! "$keymap" ]; then
+	keymap=$( f_sysrc_get keymap )
+	case "$keymap" in [Nn][Oo]) keymap="";; esac
 fi
+
+#
+# Loop until the user has finalized their selection (by clicking the
+# [relabeled] Cancel button).
+#
+width=67 first_pass=1 back_from_testing=
+[ "$USE_XDIALOG" ] && width=70
+prompt="$msg_keymap_menu_text"
+hline="$hline_arrows_tab_enter"
+while :; do
+	#
+	# Re/Build list of keymaps
+	#
+	cont_msg=$( printf "$msg_continue_with_keymap" \
+	                   "${keymap:-$msg_default}" )
+	test_msg=$( printf "$msg_test_keymap" "${keymap:-$msg_default}" )
+	menu_list="
+		'>>> $cont_msg' '' '$msg_continue_with_current_keymap'
+		'->- $test_msg' '' '$msg_test_the_currently_selected_keymap'
+	" # END-QUOTE
+	if [ "$first_pass" ]; then
+		defaultitem=
+		first_pass=
+	else
+		defaultitem="->- $test_msg"
+	fi
+	for k in $KEYMAPS; do
+		keymap_$k get keym keym
+		keymap_$k get desc desc
+		radio=" "
+		if [ "$keym" = "$keymap" ]; then
+			radio="*"
+			if [ "$back_from_testing" ]; then
+				defaultitem="(*) $desc"
+				back_from_testing=
+			fi
+		fi
+		f_shell_escape "$desc" desc
+		menu_list="$menu_list
+			'($radio) $desc' '' '$keym: $desc'
+		" # END-QUOTE
+	done
+	back_from_testing=
+
+	#
+	# Display keymap configuration menu
+	#
+	eval f_dialog_menu_with_help_size height \"\" rows \
+		\"\$DIALOG_TITLE\"     \
+		\"\$DIALOG_BACKTITLE\" \
+		\"\$prompt\"           \
+		\"\$hline\"            \
+		$menu_list
+	menu_choice=$( eval $DIALOG \
+		--title \"\$DIALOG_TITLE\"         \
+		--backtitle \"\$DIALOG_BACKTITLE\" \
+		--hline \"\$hline\"                \
+		--keep-tite                        \
+		--item-help                        \
+		--ok-label \"\$msg_select\"        \
+		--cancel-label \"\$msg_cancel\"    \
+		--default-item \"\$defaultitem\"   \
+		--menu \"\$prompt\"                \
+		$height $width $rows               \
+		$menu_list                         \
+		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
+	) || {
+		f_quietly rm -f "$KEYMAPFILE"
+		exit $FAILURE # Exit with an error so bsdinstall restarts
+	}
+	f_dialog_data_sanitize menu_choice
+
+	case "$menu_choice" in
+	">>> "*) # Continue with keymap
+		break ;;
+	"->-"*) # Test keymap
+		dialog_keymap_test "$keymap"
+		back_from_testing=1
+		continue ;;
+	esac
+
+	# Turn the user's choice into a number
+	n=$( eval f_dialog_menutag2index_with_help \
+		\"\$menu_choice\" $menu_list )
+
+	# Turn that number ithe name of the keymap struct
+	k=$( set -- $KEYMAPS; eval echo \"\${$(( $n - 2))}\" )
+
+	# Get actual keymap setting while we update $keymap and $KEYMAPFILE
+	keymap_$k get keym keymap
+	echo "keymap=\"$keymap\"" > "$KEYMAPFILE"
+done
+
+f_quietly f_keymap_kbdcontrol "$keymap"
+exit $SUCCESS
+
+################################################################################
+# END
+################################################################################


Property changes on: trunk/usr.sbin/bsdinstall/scripts/keymap
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property


More information about the Midnightbsd-cvs mailing list