summaryrefslogtreecommitdiff
path: root/read-character-from-terminal.bash
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2024-08-19 19:26:28 -0400
committerAndrew Cady <d@jerkface.net>2024-08-19 19:27:05 -0400
commitc8b67e958404dd7e358a99b43efe65aba1488c3b (patch)
treeaccf1072ba55ef791496a188654cfd0caf533d17 /read-character-from-terminal.bash
parent26292c3cbc0827620f1d02560c522860c7a621fc (diff)
finally working: code to read characters from terminal
Diffstat (limited to 'read-character-from-terminal.bash')
-rwxr-xr-xread-character-from-terminal.bash22
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()
151reader_process() 154reader_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
157run_test() 165run_test()