From 96b5027d9e04d7bca923c5f277316334186fde3f Mon Sep 17 00:00:00 2001 From: "Kang.Jianbin" Date: Sat, 28 Oct 2017 14:01:07 +0800 Subject: [PATCH] Add emulation-attributes test for true color. --- src/tests/Makefile.am | 1 + src/tests/emulation-attributes-truecolor.test | 1 + src/tests/emulation-attributes.test | 55 ++++++++++++++++++- 3 files changed, 54 insertions(+), 3 deletions(-) create mode 120000 src/tests/emulation-attributes-truecolor.test diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index dd08a4c..e53b316 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -19,6 +19,7 @@ displaytests = \ emulation-attributes-16color.test \ emulation-attributes-256color8.test \ emulation-attributes-256color248.test \ + emulation-attributes-truecolor.test \ emulation-back-tab.test \ emulation-cursor-motion.test \ emulation-multiline-scroll.test \ diff --git a/src/tests/emulation-attributes-truecolor.test b/src/tests/emulation-attributes-truecolor.test new file mode 120000 index 0000000..03c0a01 --- /dev/null +++ b/src/tests/emulation-attributes-truecolor.test @@ -0,0 +1 @@ +emulation-attributes.test \ No newline at end of file diff --git a/src/tests/emulation-attributes.test b/src/tests/emulation-attributes.test index bf8c093..e633f5c 100755 --- a/src/tests/emulation-attributes.test +++ b/src/tests/emulation-attributes.test @@ -1,9 +1,10 @@ #!/bin/sh # -# This validates VT100, 16-color, and 256-color attributes against -# tmux. It is not run directly, but as subtests based on the -# executable's name for vt100, 16color, 256color8, and 256color248. +# This validates VT100, 16-color, 256-color and true color attributes +# against tmux. It is not run directly, but as subtests based on the +# executable's name for vt100, 16color, 256color8, 256color248 and +# truecolor. # This is because Mosh internally represents the first 8 values of the # 256color space as though they were the 16-color values they are # equivalent to. tmux does not filter this out on its redisplay, so @@ -24,6 +25,34 @@ if [ $# -ne 1 ]; then fail "bad arguments %s\n" "$@" fi +test_true_color() +{ + s=$(printf "\033[0") + for i in $@; do + s="$s;$i" + done + s="${s}m" + + for attr in $(seq 0 76); do + r=$((255-(attr*255/76))) + g=$((attr*510/76)) + b=$((attr*255/76)) + if [ $g -gt 255 ]; then + g=$((510-g)) + fi + invr=$((255-r)) + invg=$((255-g)) + invb=$((255-b)) + c="E" + + printf "%s" "$s" + printf "\033[48;2;%d;%d;%dm" $r $g $b; + printf "\033[38;2;%d;%d;%dm" $invr $invg $invb + printf "%s\033[m" "$c" + done + printf "\n" +} + baseline() { # Strip our name to the last dash-separated word before the .test suffix. @@ -61,6 +90,26 @@ baseline() printf '\033[48;5;%dmM\033[m ' "$attr" done ;; + # True color. + # See https://gist.github.com/XVilka/8346728 for the test case + truecolor) + echo "Normal:" + test_true_color + echo "Bold:" + test_true_color 1 + echo "Italic:" + test_true_color 3 + echo "Underline:" + test_true_color 4 + echo "Blink:" + test_true_color 5 + echo "Inverse:" + test_true_color 7 + echo "Invisible:" + test_true_color 8 + echo "Bold, italic and underline:" + test_true_color 1 3 4 + ;; *) fail "unknown test name %s\n" "$1" ;;