From: Kevin Lamonte Date: Sun, 3 Nov 2019 00:58:10 +0000 (-0500) Subject: Jexer image protocol performance X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=977b473d9521933e972587015144c3cf1bb551f6;p=nikiroo-utils.git Jexer image protocol performance --- diff --git a/examples/imgls b/examples/imgls new file mode 100755 index 0000000..99bbb9c --- /dev/null +++ b/examples/imgls @@ -0,0 +1,64 @@ +#!/bin/bash + +# This is a modified version of the 'imgls' from iTerm2 located at +# https://iterm2.com/utilities/imgls, modified to emit images with the +# Jexer image protocol. + +# tmux requires unrecognized OSC sequences to be wrapped with DCS tmux; +# ST, and for all ESCs in to be replaced with ESC ESC. It +# only accepts ESC backslash for ST. +function print_osc() { + if [ x"$TERM" = "xscreen" ] ; then + printf "\033Ptmux;\033\033]" + else + printf "\033]" + fi +} + +function check_dependency() { + if ! (builtin command -V "$1" > /dev/null 2>& 1); then + echo "imgcat: missing dependency: can't find $1" 1>& 2 + exit 1 + fi +} + +# More of the tmux workaround described above. +function print_st() { + if [ x"$TERM" = "xscreen" ] ; then + printf "\a\033\\" + else + printf "\a" + fi +} + +function list_file() { + fn=$1 + test -f "$fn" || return 0 + + if [ "${fn: -4}" == ".png" ]; then + print_osc + printf '444;1;1;' + base64 < "$fn" + print_st + elif [ "${fn: -4}" == ".jpg" ]; then + print_osc + printf '444;2;1;' + base64 < "$fn" + print_st + fi +} + +check_dependency base64 + +if [ $# -eq 0 ]; then + for fn in * + do + list_file "$fn" + done < <(ls -ls) +else + for fn in "$@" + do + list_file "$fn" + done +fi + diff --git a/src/jexer/tterminal/ECMA48.java b/src/jexer/tterminal/ECMA48.java index 8127458..12e7a2b 100644 --- a/src/jexer/tterminal/ECMA48.java +++ b/src/jexer/tterminal/ECMA48.java @@ -4778,13 +4778,22 @@ public class ECMA48 implements Runnable { private void oscPut(final char xtermChar) { // System.err.println("oscPut: " + xtermChar); + boolean oscEnd = false; + + if (xtermChar == 0x07) { + oscEnd = true; + } + if ((xtermChar == '\\') + && (collectBuffer.charAt(collectBuffer.length() - 1) == '\033') + ) { + oscEnd = true; + } + // Collect first collectBuffer.append(xtermChar); // Xterm cases... - if ((xtermChar == 0x07) - || (collectBuffer.toString().endsWith("\033\\")) - ) { + if (oscEnd) { String args = null; if (xtermChar == 0x07) { args = collectBuffer.substring(0, collectBuffer.length() - 1); @@ -4867,11 +4876,19 @@ public class ECMA48 implements Runnable { private void pmPut(final char pmChar) { // System.err.println("pmPut: " + pmChar); + boolean pmEnd = false; + + if ((pmChar == '\\') + && (collectBuffer.charAt(collectBuffer.length() - 1) == '\033') + ) { + pmEnd = true; + } + // Collect first collectBuffer.append(pmChar); // Xterm cases... - if (collectBuffer.toString().endsWith("\033\\")) { + if (pmEnd) { String arg = null; arg = collectBuffer.substring(0, collectBuffer.length() - 2);