Commit df4d9ff9 authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Add an optional resize util function

This is as a replacement for the tool supplied with xterm.
parent f10ea650
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -200,3 +200,22 @@ do_update()
		done
	fi
}

has resize || resize() {
	local IFS=';' flag signal
	case $(get_shell) in
		bash) flag=-a signal=RETURN ;;
		zsh) flag=-A signal=EXIT ;;
		*) echo >&2 "Cannot resize with this shell"; return 1 ;;
	esac
	stty -echo
	trap 'stty echo' $signal
	printf '\033[18t'
	read -d '[' -s _
	read -d 't' -s $flag params
	set -- "${params[@]}"
	[ $# -eq 3 -a $1 -eq 8 ] && shift
	[ $# -ne 2 ] && echo >&2 "Cannot resize" && return 1
	stty rows "$1" cols "$2" echo
	trap '' $signal
}