#!/bin/ksh

saveterm=$TERM
savetty="$(stty -g)"

if test "$TERM" = "xterm"
then
	export TERM=xterm-m
	stty load
	stty +edit
else
	tty=`tty`
	device=${tty##*/}
	name=${device%[123456789]}

	if test "$name" = "con"
	then
		export TERM=qansi
		stty protocol=1
	else
		echo "Midnight Commander runs best on a console or in xterm -"
		echo "prepare for an EMACS experience should you choose to continue (y/n): \c"
		read -r continue

		if test "$continue" != "y"
		then
			exit
		fi
	fi
fi

/usr/local/bin/mc $*

export TERM=$saveterm
stty $savetty
