From 4902f88a13eb76a4e1559ada2eb857ffff1922c9 Mon Sep 17 00:00:00 2001 From: Yu-Jie Lin Date: Thu, 9 Apr 2015 10:44:06 +0800 Subject: [PATCH] adopt resolution of livibetter/pipes.sh#12, some keys halt on exiting The screen is also saved and restored. --- CHANGES.rst | 8 ++++++++ README.rst | 6 ++++++ pipesX.sh | 21 +++++++++++++-------- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 0107d2e..65b62bf 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -6,6 +6,14 @@ CHANGES Development =========== +* drop Bash 3- support + + The last commit for Bash 3- is ``0600773a30038cf552b417442c1a443297773323`` + or before version 1.0.0. + +* fix keys like arrow keys or ``Ctrl+Alt+A`` halt on exiting + (livibetter/pipes.sh#12) + Version 0.1.1 (2014-03-19T03:26:51Z) ==================================== diff --git a/README.rst b/README.rst index d7f6bbd..e8a5866 100644 --- a/README.rst +++ b/README.rst @@ -34,6 +34,12 @@ that is piping at an angle. .. _pipes.sh: https://github.com/livibetter/pipes.sh +Requirements +============ + +* Bash 4+ since version 1.0.0. + + Installation ============ diff --git a/pipesX.sh b/pipesX.sh index c82c430..6635694 100755 --- a/pipesX.sh +++ b/pipesX.sh @@ -94,14 +94,17 @@ done # set to default values if not by options ((${#T[@]})) || T=(0) -[[ $BASH_VERSION = [1-3]* ]] && SLEEP="sleep $I" || SLEEP="read -t $I -n 1" - do_exit() { - # Show cursor and echo stdin - echo -ne "\e[?25h" + # clear up standard input + read -t 0.001 && cat /dev/null + + # terminal has no smcup and rmcup capabilities + ((FORCE_RESET)) && reset && exit 0 + + tput rmcup + tput cnorm stty echo - clear - echo -ne "\e[0m" + ((NOCOLOR)) && echo -ne '\e[0m' exit 0 } trap do_exit HUP TERM @@ -109,7 +112,9 @@ trap 'break 2' INT # No echo stdin and hide the cursor stty -echo -echo -ne "\e[?25l" +tput smcup || FORCE_RESET=1 +tput civis +tput clear # maze geneartion while [[ $MAZE ]] && clear; do @@ -130,7 +135,7 @@ for ((n = 0; n < N; n++)); do done clear -while REPLY=; $SLEEP; [[ -z $REPLY ]] ; do +while REPLY=; read -t $I -n 1; [[ -z $REPLY ]] ; do for ((n = 0; n < N; n++, CC = 0)); do x=${X[n]} y=${Y[n]} d=${D[n]} c=${C[n]}