summaryrefslogtreecommitdiff
path: root/twopane.bash
diff options
context:
space:
mode:
Diffstat (limited to 'twopane.bash')
-rwxr-xr-xtwopane.bash72
1 files changed, 55 insertions, 17 deletions
diff --git a/twopane.bash b/twopane.bash
index ff1a143..672448e 100755
--- a/twopane.bash
+++ b/twopane.bash
@@ -7,7 +7,7 @@ PROGNAME=${0##*/}
7 7
8BOT_SIZE=8 8BOT_SIZE=8
9BOT_TITLE=input 9BOT_TITLE=input
10BOT_CMD=sendstream 10BOT_CMD=start
11if [ $# = 0 ] 11if [ $# = 0 ]
12then 12then
13 TOP_CMD="$SHELL -i" 13 TOP_CMD="$SHELL -i"
@@ -56,7 +56,7 @@ title 'output'
56focus top 56focus top
57. 57.
58 58
59restart() 59restart_top()
60{ 60{
61 while screen -p1 -Q info >/dev/null 61 while screen -p1 -Q info >/dev/null
62 do 62 do
@@ -65,7 +65,29 @@ restart()
65 screen -X source "$TWOPANE"/screenrc.startpane 65 screen -X source "$TWOPANE"/screenrc.startpane
66} 66}
67 67
68sendstream() 68connect()
69{
70 coproc SOCAT \
71 {
72 socat STDIN!!STDOUT UNIX-CONNECT:"$TWOPANE"/socket,forever
73 kill -USR1 $$
74 [ "$TOP_EXIT" != restart ] || restart_top
75 }
76 eval "exec $1<&${SOCAT[0]} $2>&${SOCAT[1]}"
77}
78
79disconnect()
80{
81 eval "exec $1<&- $2>&-"
82}
83
84restart()
85{
86 [ "${SOCAT[0]}" ] || restart_top
87 start
88}
89
90start()
69{ 91{
70 socat_stty_opts=( 92 socat_stty_opts=(
71 rawer 93 rawer
@@ -84,25 +106,43 @@ sendstream()
84 ) 106 )
85 stty=$(printf %s, "${socat_stty_opts[@]}") 107 stty=$(printf %s, "${socat_stty_opts[@]}")
86 108
87 trap ': SIGUSR1; restart' USR1 109 trap ': SIGUSR1 ; ' USR1
88 exec 100<&0 101>&1 110 exec 100<&0 101>&1
89 while true 111 while true
90 do 112 do
91 coproc SOCAT \ 113 connect 200 201
92 {
93 socat STDIN!!STDOUT UNIX-CONNECT:"$TWOPANE"/socket,forever
94 kill -USR1 $$
95 }
96 exec 200<&${SOCAT[0]} 201>&${SOCAT[1]}
97 socat FD:100,${stty%,}!!STDOUT STDIN!!STDOUT <&200 | 114 socat FD:100,${stty%,}!!STDOUT STDIN!!STDOUT <&200 |
98 input_filter | 115 input_filter |
99 tee >(output_filter | soft_cursor >&101) >&201 116 tee >(output_filter | soft_cursor >&101) >&201
117
100 reset -I -Q -w 118 reset -I -Q -w
101 exec 200<&- 201>&- 119 disconnect 200 201
102 wait -f "$SOCAT_PID" 2>/dev/null 120 wait -f "$SOCAT_PID" 2>/dev/null
121
122 case "$TOP_EXIT" in
123 restart )
124 continue ;;
125 quit )
126 exit ;;
127 * )
128 screen -X focus bottom
129 echo
130 break
131 ;;
132 esac
103 done 133 done
104} 134}
105 135
136quit()
137{
138 screen -X quit
139}
140
141focus()
142{
143 screen -X focus "$@"
144}
145
106input_filter() 146input_filter()
107{ 147{
108 while read -N1 148 while read -N1
@@ -122,19 +162,17 @@ output_filter()
122 162
123soft_cursor() 163soft_cursor()
124{ 164{
125 printf $'\033[43m \b' 165 cursor_color=104
166 cursor=$'\033['"$cursor_color"$'m \b\033[00m'
167 printf '%s' "$cursor"
126 while read -N1 168 while read -N1
127 do 169 do
128 printf '%s' \ 170 printf '%s' "$REPLY" "$cursor"
129 $'\033[00m \b' \
130 "$REPLY" \
131 $'\033[43m \b'
132 done 171 done
133} 172}
134 173
135save_file bashrc <<. 174save_file bashrc <<.
136set -f 175set -f
137set -b
138set -o pipefail 176set -o pipefail
139shopt -s lastpipe 177shopt -s lastpipe
140trap "screen -X quit" EXIT 178trap "screen -X quit" EXIT