From bd3d815e9c3757414b50225ba2c427ab8ff298e7 Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Tue, 20 Aug 2024 07:14:23 -0400 Subject: "new" backgrounding code --- src/twopane.bash | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/twopane.bash b/src/twopane.bash index d49ca4f..f496701 100755 --- a/src/twopane.bash +++ b/src/twopane.bash @@ -246,7 +246,7 @@ forward() socat FD:$STDIN,$stty!!STDOUT - <&$stdin >&$TEE 2>&$STDERR & } 2>/dev/null FORWARD_PID=$! - printf '%s\n' "#!/bin/bash" "kill $!" "screen -X focus bottom" > "$TWOPANE"/unforward + printf '%s\n' "#!/bin/bash" "kill -TSTP $!" "screen -X focus bottom" > "$TWOPANE"/unforward chmod +x "$TWOPANE"/unforward fg >/dev/null stty "$old_stty" @@ -284,14 +284,47 @@ resume_forward() focus bottom } +tty_forward() +{ + read-tty +} + +background() +{ + old_stty=$(stty -g) + start_screen_pane "$@" + focus bottom + connect stdin stdout + #stty tostop + exec {BOTTOM_PANE}> >(trap 'echo SIG >&2' SIGTTOU SIGTTIN SIGTSTP; output_filter) + BOTTOM_PANE_PID=$! + exec {BOTH_PANES}> >(trap 'echo TTOU >&2' SIGTTOU; ptee 1 $BOTTOM_PANE >&$stdout) + exec {NET_MERGE}> >(exec {STDIN}<&0; exec -a merge_reader socat FD:$STDIN!!STDOUT - <&$stdin >&$BOTH_PANES) + local STDERR + exec {STDERR}>&2 + { + exec 2>&$STDERR {STDERR}>&- + tty_forward & + } >&$NET_MERGE 2>/dev/null + TTY_READER_PID=$! + printf '%s\n' "#!/bin/bash" "kill -TSTP $TTY_READER_PID" "screen -X focus bottom" > "$TWOPANE"/unforward + chmod +x "$TWOPANE"/unforward + #"$TWOPANE"/unforward +} + foreground() { - if forwarding + if ! jobs -p %tty_forward >/dev/null 2>&1 then - resume_forward + background else - foreground_loop "$@" + old_stty=$(stty -g) fi + cfmakeraw opost onlcr + focus top + fg %tty_forward + stty "$old_stty" + focus bottom } twopane() -- cgit v1.2.3