在设置 stty -icanon time 0 min 0 以防止读取阻塞后,我有一个循环。
它工作正常,只是它无法读取输入/返回键。
有没有办法在这种模式下读取回车键,或者我的代码可以用任何其他方式编写?
相关代码
tput smcup
Draw
if [ -t 0 ]; then stty -icanon time 0 min 0; fi
count=0
keypress=''
while [ "$keypress" != "q" ]; do
sleep 0.1
(( count = count + 1 ))
rows=$(tput lines)
columns=$(tput cols)
Draw
read keypress
name=$name$keypress
echo $name
if [[ $oldcolumns != $columns || $oldrows != $rows ]];then
Draw
oldcolumns=$columns
oldrows=$rows
elif [[ $count -eq 1 ]]; then
# Draw
count=0
fi
done
if [ -t 0 ]; then stty sane; fi
tput rmcup
#rm tail.tmp
echo "Thanks for using this script."
exit 0