summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2024-08-01 09:55:49 -0400
committerAndrew Cady <d@jerkface.net>2024-08-01 10:27:11 -0400
commit1a126c45fe808efae7e0c9a20b9d014af20e8866 (patch)
tree57ca929aba7bb4453ee8df2b9f79d286591991d3
parent55d2d1be1321c8b0bd289cd331af2f100106c14b (diff)
much improved terminal and signal handling
-rw-r--r--twopane.bash51
1 files changed, 40 insertions, 11 deletions
diff --git a/twopane.bash b/twopane.bash
index f3aff57..91b9f1a 100644
--- a/twopane.bash
+++ b/twopane.bash
@@ -58,42 +58,71 @@ title 'input'
58source "$TWOPANE"/screenrc.startpane 58source "$TWOPANE"/screenrc.startpane
59. 59.
60 60
61TWOPANE_FUNCTION_EXPORTS='restart sendp sendc send start'
62restart() 61restart()
63{ 62{
64 screen -X source "$TWOPANE"/screenrc.restart 63 screen -X source "$TWOPANE"/screenrc.restart
65} 64}
66sendp() 65sendp()
67{ 66{
68 socat -u STDIN UNIX-SENDTO:"$TWOPANE"/socket 67 trap "kill -SIGUSR1 $1" EXIT
68 socat -u STDIN UNIX-SENDTO:"$TWOPANE"/socket || restart
69} 69}
70sendc() 70sendc()
71{ 71{
72 [ "${COPROC[1]}" ] || coproc sendp 72 [ "${COPROC[1]}" ] || coproc { sendp $$; }
73 printf '%s' "$*" >&${COPROC[1]} 73 printf '%s' "$*" >&${COPROC[1]}
74} 74}
75send() 75send()
76{ 76{
77 [ "${COPROC[1]}" ] || coproc sendp 77 [ "${COPROC[1]}" ] || coproc { sendp $$; }
78 printf '%s' "$*"$'\n' >&${COPROC[1]} 78 printf '%s' "$*"$'\n' >&${COPROC[1]}
79} 79}
80
81sendcc() { sendc $'\003'; }
82
83raw()
84{
85 stty_opts=(
86 cbreak
87 raw
88 -isig
89 -iexten
90 -nl
91 intr undef
92 quit undef
93 #erase undef
94 #kill undef
95 eof undef
96 start undef
97 stop undef
98 susp undef
99 lnext undef
100 )
101 stty "${stty_opts[@]}"
102}
103
80start() 104start()
81{ 105{
82 [ "${COPROC[1]}" ] || coproc sendp 106 trap ': SIGPIPE ${COPROC[@]@A}' SIGPIPE
83 while read -r -N1 </dev/tty 107 trap ': SIGCHLD ${COPROC[@]@A}' SIGCHLD
108 trap ': SIGUSR1 ${COPROC[@]@A}; COPROC=()' SIGUSR1
109 raw
110 while read -r -N1 || [ $? -gt 128 ]
84 do 111 do
85 [ "${COPROC[1]}" ] || break 112 if [ "$REPLY" ]
86 printf '%s' "$REPLY" 113 then
87 done >&${COPROC[1]} 114 sendc "$REPLY"
115 fi
116 done
88} 117}
89 118
90save_file bashrc <<. 119save_file bashrc <<.
91set -f 120set -f
121set -b
92set -o pipefail 122set -o pipefail
93shopt -s lastpipe 123shopt -s lastpipe
94trap 'COPROC=()' SIGPIPE
95trap "screen -X quit" EXIT 124trap "screen -X quit" EXIT
96$(declare -f $TWOPANE_FUNCTION_EXPORTS | sed 's/ COPROC / /') 125$(declare -f)
97export PS1="$BOT_TITLE\$ " 126export PS1="$BOT_TITLE\$ "
98\$BOT_CMD 127\$BOT_CMD
99. 128.