From 224a79b4440e6e076a5cbe899364df8d7a56df71 Mon Sep 17 00:00:00 2001 From: Simon Lehn <48837958+srlehn@users.noreply.github.com> Date: Mon, 8 Apr 2019 22:13:05 +0200 Subject: [PATCH 1/2] add preliminary support for terminal multiplexers this adds preliminary support for terminal multiplexers (tmux, screen). Escape codes meant for the terminal have to be piped through muxwrap. Positional escape codes probably should be directed to the multiplexer. you can test the function in a sixel capable terminal with and without tmux/screen like this: ``` printf '\033Pq#0;2;0;0;0#1;2;100;100;0#2;2;0;100;0#1~~@@vv@@~~@@~~$#2??}}GG}}??}}??-#1!14@\033\\' | muxwrap ``` --- lsix | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lsix b/lsix index efc042c..366c25f 100755 --- a/lsix +++ b/lsix @@ -239,6 +239,16 @@ processlabel() { sed 's|%|%%|g; s|\\|\\\\|g; s|@|\\@|g;' } +muxwrap(){ + if [ "${TERM%%.*}" == screen ] && [ -v STY ]; then + sed 's,.\{767\},&\o33\\\o33P,g;1s,^,\o33P,;$s,$,\o33\\,' + elif [ "${TERM%%.*}" == screen ] && [ -v TMUX ]; then + sed 's,\o33,&&,g;1s,^,\o33Ptmux;,;$s,$,\o33\\,' + else + sed b + fi +} + #### main "$@" From efd576f70864f9c38b2cdc95b99860c4e9e39020 Mon Sep 17 00:00:00 2001 From: Simon Lehn <48837958+srlehn@users.noreply.github.com> Date: Wed, 10 Apr 2019 15:28:31 +0200 Subject: [PATCH 2/2] enabled wrapping for multiplexer --- lsix | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lsix b/lsix index 366c25f..78d3978 100755 --- a/lsix +++ b/lsix @@ -77,7 +77,7 @@ autodetect() { stty -echo # Hush-a Mandara Ni Pari # IS TERMINAL SIXEL CAPABLE? - read -s -t 1 -d "c" -p $'\e[c' >&2 # Send Device Attributes + read -s -t 1 -d "c" -p "$(muxwrap <<<$'\e[c')" >&2 # Send Device Attributes if ! [[ $REPLY =~ ";4;" ]]; then cat <<-EOF >&2 Error: Your terminal does not report having sixel graphics support. @@ -96,40 +96,40 @@ autodetect() { fi # ENABLE SIXEL SCROLLING so image will appear right after cursor. - if [[ $TERM != "mlterm" ]]; then - echo -ne $'\e[?80h' + if [[ ! -v MLTERM ]]; then + echo -ne $'\e[?80h' | muxwrap else # Except... mlterm (as of 3.5.0) has a bug that reverses the sense - echo -ne $'\e[?80l' + echo -ne $'\e[?80l' | muxwrap fi # TERMINAL COLOR AUTODETECTION. # Find out how many color registers the terminal has - IFS=";" read -a REPLY -s -t ${timeout} -d "S" -p $'\e[?1;1;0S' >&2 + IFS=";" read -a REPLY -s -t ${timeout} -d "S" -p "$(muxwrap <<<$'\e[?1;1;0S')" >&2 [[ ${REPLY[1]} == "0" ]] && numcolors=${REPLY[2]} # Bug workaround: mlterm does not report number of colors. - if [[ $TERM =~ mlterm ]]; then numcolors=1024; fi + if [[ -v MLTERM ]]; then numcolors=1024; fi # Increase colors, if needed if [[ $numcolors -lt 256 ]]; then # Attempt to set the number of colors to 256. # This will work for xterm, but fail on a real vt340. - IFS=";" read -a REPLY -s -t ${timeout} -d "S" -p $'\e[?1;3;256S' >&2 + IFS=";" read -a REPLY -s -t ${timeout} -d "S" -p "$(muxwrap <<<$'\e[?1;3;256S')" >&2 [[ ${REPLY[1]} == "0" ]] && numcolors=${REPLY[2]} fi # Query the terminal background and foreground colors. - IFS=";:/" read -a REPLY -r -s -t ${timeout} -d "\\" -p $'\e]11;?\e\\' >&2 + IFS=";:/" read -a REPLY -r -s -t ${timeout} -d "\\" -p "$(muxwrap <<<$'\e]11;?\e\\')" >&2 if [[ ${REPLY[1]} =~ ^rgb ]]; then # Return value format: $'\e]11;rgb:ffff/0000/ffff\e\\'. # ImageMagick wants colors formatted as #ffff0000ffff. background='#'${REPLY[2]}${REPLY[3]}${REPLY[4]%%$'\e'*} - IFS=";:/" read -a REPLY -r -s -t ${timeout} -d "\\" -p $'\e]10;?\e\\' >&2 + IFS=";:/" read -a REPLY -r -s -t ${timeout} -d "\\" -p "$(muxwrap <<<$'\e]10;?\e\\')" >&2 if [[ ${REPLY[1]} =~ ^rgb ]]; then foreground='#'${REPLY[2]}${REPLY[3]}${REPLY[4]%%$'\e'*} # Check for "Reverse Video" (DECSCNM screen mode). - IFS=";?$" read -a REPLY -s -t ${timeout} -d "y" -p $'\e[?5$p' + IFS=";?$" read -a REPLY -s -t ${timeout} -d "y" -p "$(muxwrap <<<$'\e[?5$p')" if [[ ${REPLY[2]} == 1 || ${REPLY[2]} == 3 ]]; then temp=$foreground foreground=$background @@ -211,7 +211,8 @@ main() { shift done montage "${onerow[@]}" $imoptions gif:- \ - | convert - -colors $numcolors sixel:- + | convert - -colors $numcolors sixel:- \ + | muxwrap done }