diff options
Diffstat (limited to 'read-character-from-terminal.bash')
-rwxr-xr-x | read-character-from-terminal.bash | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/read-character-from-terminal.bash b/read-character-from-terminal.bash index 373900c..6abd2b6 100755 --- a/read-character-from-terminal.bash +++ b/read-character-from-terminal.bash | |||
@@ -66,9 +66,9 @@ readchar_SIGCONT() | |||
66 | if check_foreground | 66 | if check_foreground |
67 | then | 67 | then |
68 | x cfmakeraw "${readchar_termopts[@]}" | 68 | x cfmakeraw "${readchar_termopts[@]}" |
69 | x kill -CONT $SOCAT_PID | 69 | x kill -CONT $SOCAT_PID 2>/dev/null |
70 | else | 70 | else |
71 | x kill -STOP $BASHPID $SOCAT_PID | 71 | x kill -STOP $BASHPID $SOCAT_PID 2>/dev/null |
72 | fi | 72 | fi |
73 | } | 73 | } |
74 | 74 | ||
@@ -82,17 +82,20 @@ readchar() | |||
82 | { | 82 | { |
83 | declare -n REPLY="${1:-CHARACTER}" | 83 | declare -n REPLY="${1:-CHARACTER}" |
84 | 84 | ||
85 | if ! check_foreground | ||
86 | then | ||
87 | sleep .25 | ||
88 | return | ||
89 | fi | ||
90 | |||
85 | if ! [ "$SOCAT_PID" ] || ! kill -CONT "$SOCAT_PID" 2>/dev/null | 91 | if ! [ "$SOCAT_PID" ] || ! kill -CONT "$SOCAT_PID" 2>/dev/null |
86 | then | 92 | then |
87 | x cfmakeraw "${readchar_termopts[@]}" | 93 | x cfmakeraw "${readchar_termopts[@]}" |
88 | exec {SOCAT}< <(trap 'sleep .25' SIGTSTP; socat - -) | 94 | exec {SOCAT}< <(trap 'sleep .25' SIGTSTP; socat - -) |
89 | |||
90 | # READ_PID=$BASHPID | ||
91 | # exec {SOCAT}< <(trap 'kill -TSTP $READ_PID; kill -STOP $BASHPID' SIGTSTP; exec cat) | ||
92 | SOCAT_PID=$! | 95 | SOCAT_PID=$! |
93 | fi | 96 | fi |
94 | 97 | ||
95 | if check_foreground && read -t .25 -n1 -d '' -r -s -u "$SOCAT" | 98 | if read -n1 -d '' -r -s -u "$SOCAT" |
96 | then | 99 | then |
97 | if [ "$t" ] | 100 | if [ "$t" ] |
98 | then | 101 | then |
@@ -151,7 +154,12 @@ read_chars() | |||
151 | reader_process() | 154 | reader_process() |
152 | { | 155 | { |
153 | enable -f sleep sleep | 156 | enable -f sleep sleep |
154 | read_chars | 157 | if [ "$SHLVL" = 1 -a -t 1 ] |
158 | then | ||
159 | (read_chars) | ||
160 | else | ||
161 | read_chars | ||
162 | fi | ||
155 | } | 163 | } |
156 | 164 | ||
157 | run_test() | 165 | run_test() |