From 1a126c45fe808efae7e0c9a20b9d014af20e8866 Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Thu, 1 Aug 2024 09:55:49 -0400 Subject: much improved terminal and signal handling --- twopane.bash | 51 ++++++++++++++++++++++++++++++++++++++++----------- 1 file 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' source "$TWOPANE"/screenrc.startpane . -TWOPANE_FUNCTION_EXPORTS='restart sendp sendc send start' restart() { screen -X source "$TWOPANE"/screenrc.restart } sendp() { - socat -u STDIN UNIX-SENDTO:"$TWOPANE"/socket + trap "kill -SIGUSR1 $1" EXIT + socat -u STDIN UNIX-SENDTO:"$TWOPANE"/socket || restart } sendc() { - [ "${COPROC[1]}" ] || coproc sendp + [ "${COPROC[1]}" ] || coproc { sendp $$; } printf '%s' "$*" >&${COPROC[1]} } send() { - [ "${COPROC[1]}" ] || coproc sendp + [ "${COPROC[1]}" ] || coproc { sendp $$; } printf '%s' "$*"$'\n' >&${COPROC[1]} } + +sendcc() { sendc $'\003'; } + +raw() +{ + stty_opts=( + cbreak + raw + -isig + -iexten + -nl + intr undef + quit undef + #erase undef + #kill undef + eof undef + start undef + stop undef + susp undef + lnext undef + ) + stty "${stty_opts[@]}" +} + start() { - [ "${COPROC[1]}" ] || coproc sendp - while read -r -N1 &${COPROC[1]} + if [ "$REPLY" ] + then + sendc "$REPLY" + fi + done } save_file bashrc <<. set -f +set -b set -o pipefail shopt -s lastpipe -trap 'COPROC=()' SIGPIPE trap "screen -X quit" EXIT -$(declare -f $TWOPANE_FUNCTION_EXPORTS | sed 's/ COPROC / /') +$(declare -f) export PS1="$BOT_TITLE\$ " \$BOT_CMD . -- cgit v1.2.3