Use read -s if it is supported.

This commit is contained in:
anseki 2015-03-02 02:07:28 +09:00
parent c33a9d77cd
commit a2113444d1
2 changed files with 18 additions and 4 deletions

View file

@ -1,13 +1,27 @@
if [ "$1" = "noechoback" ]; then
silentRead() {
# `typeset` doesn't work in `func()` of ksh.
# `function fnc` for local-var of ksh is not compatible.
# Therefore, `_input` is not local-var on ksh.
local _input="" 2>/dev/null || typeset _input=""
stty --file=/dev/tty -echo echonl 2>/dev/null || \
stty -F /dev/tty -echo echonl 2>/dev/null || \
stty -f /dev/tty -echo echonl 2>/dev/null || \
exit 1
IFS= read -r INPUT </dev/tty
IFS= read -r _input </dev/tty
stty --file=/dev/tty echo -echonl 2>/dev/null || \
stty -F /dev/tty echo -echonl 2>/dev/null || \
stty -f /dev/tty echo -echonl 2>/dev/null
# printf '\n' >/dev/tty
printf '%s' "$_input"
}
if [ "$1" = "noechoback" ]; then
# Try `-s` option. *ksh have it that not `--silent`. Therefore, don't try it.
if [ -n "$BASH_VERSION" ] || [ -n "$ZSH_VERSION" ]; then
IFS= read -rs INPUT </dev/tty 2>/dev/null || INPUT=`silentRead` || exit 1
printf '\n' >/dev/tty
else
INPUT=`silentRead` || exit 1
fi
else
IFS= read -r INPUT </dev/tty
fi

View file

@ -1,6 +1,6 @@
{
"name": "readline-sync",
"version": "0.7.1",
"version": "0.7.2",
"title": "readlineSync",
"description": "Synchronous Readline",
"keywords": [