From c6f583db274e8ccf375abfbce22a343ee0822632 Mon Sep 17 00:00:00 2001 From: Tomi Ollila Date: Sat, 24 Aug 2013 16:31:13 +0300 Subject: [PATCH] [PATCH 1/1] test: pre-set terminal capabilities (colors, boldness) --- e5/54ee15c0a4d3ca58a4ee658fa6431a4fac8c6b | 169 ++++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 e5/54ee15c0a4d3ca58a4ee658fa6431a4fac8c6b diff --git a/e5/54ee15c0a4d3ca58a4ee658fa6431a4fac8c6b b/e5/54ee15c0a4d3ca58a4ee658fa6431a4fac8c6b new file mode 100644 index 000000000..388a846c3 --- /dev/null +++ b/e5/54ee15c0a4d3ca58a4ee658fa6431a4fac8c6b @@ -0,0 +1,169 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 1CA67431FBD + for ; Sat, 24 Aug 2013 06:31:33 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0 +X-Spam-Level: +X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] + autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id b-QCM0JgvVzo for ; + Sat, 24 Aug 2013 06:31:23 -0700 (PDT) +Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) + by olra.theworths.org (Postfix) with ESMTP id C4F20431FDC + for ; Sat, 24 Aug 2013 06:31:22 -0700 (PDT) +Received: by guru.guru-group.fi (Postfix, from userid 501) + id C2B4710009D; Sat, 24 Aug 2013 16:31:14 +0300 (EEST) +From: Tomi Ollila +To: notmuch@notmuchmail.org +Subject: [PATCH 1/1] test: pre-set terminal capabilities (colors, boldness) +Date: Sat, 24 Aug 2013 16:31:13 +0300 +Message-Id: <1377351073-4076-1-git-send-email-tomi.ollila@iki.fi> +X-Mailer: git-send-email 1.8.0 +Cc: tomi.ollila@iki.fi +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Sat, 24 Aug 2013 13:31:33 -0000 + +By pre-setting terminal capabilities (colors, boldness) to shell +variables we avoid the overhead of running external commands (in +separate subshell) each time colored text is printed to screen. +--- + test/test-lib.sh | 84 ++++++++++++++++++++++++++++---------------------------- + 1 file changed, 42 insertions(+), 42 deletions(-) + +diff --git a/test/test-lib.sh b/test/test-lib.sh +index ffab1bb..8be2065 100644 +--- a/test/test-lib.sh ++++ b/test/test-lib.sh +@@ -38,9 +38,6 @@ done,*) + ;; + esac + +-# Keep the original TERM for say_color and test_emacs +-ORIGINAL_TERM=$TERM +- + # dtach(1) provides more capable terminal environment to anything + # that requires more than dumb terminal... + [ x"${TERM:-dumb}" = xdumb ] && DTACH_TERM=vt100 || DTACH_TERM=$TERM +@@ -50,8 +47,49 @@ LANG=C + LC_ALL=C + PAGER=cat + TZ=UTC ++export LANG LC_ALL PAGER TZ ++ ++if [ x"${TERM:-dumb}" != xdumb ]; then ++ [ -t 1 ] && ++ # http://en.wikipedia.org/wiki/Tput ++ TC_BOLD=`tput bold 2>/dev/null` && ++ TC_RED=`tput setaf 1 2>/dev/null` && ++ TC_GREEN=`tput setaf 2 2>/dev/null` && ++ TC_YELLOW=`tput setaf 3 2>/dev/null` && ++ TC_RESET=`tput sgr0 2>/dev/null` || ++ TC_BOLD= ++else ++ TC_BOLD= ++fi ++ ++if test -n "$TC_BOLD"; then ++ say_color () { ++ case "$1" in ++ error) printf '%s%s' "$TC_BOLD" "$TC_RED" ;; ++ skip) printf '%s%s' "$TC_BOLD" "$TC_GREEN" ;; ++ pass) printf '%s' "$TC_GREEN" ;; ++ info) printf '%s' "$TC_YELLOW" ;; ++ *) test -n "$quiet" && return;; ++ esac ++ shift ++ printf " " ++ printf "$@" ++ printf '%s' "$TC_RESET" ++ print_subtest ++ } ++else ++ say_color() { ++ test -z "$1" && test -n "$quiet" && return ++ shift ++ printf " " ++ printf "$@" ++ print_subtest ++ } ++fi ++ + TERM=dumb +-export LANG LC_ALL PAGER TERM TZ ++export TERM ++ + GIT_TEST_CMP=${GIT_TEST_CMP:-diff -u} + if [[ ( -n "$TEST_EMACS" && -z "$TEST_EMACSCLIENT" ) || \ + ( -z "$TEST_EMACS" && -n "$TEST_EMACSCLIENT" ) ]]; then +@@ -82,15 +120,6 @@ _x32="$_x04$_x04$_x04$_x04$_x04$_x04$_x04$_x04" + # This test checks if command xyzzy does the right thing... + # ' + # . ./test-lib.sh +-[ "x$ORIGINAL_TERM" != "xdumb" ] && ( +- TERM=$ORIGINAL_TERM && +- export TERM && +- [ -t 1 ] && +- tput bold >/dev/null 2>&1 && +- tput setaf 1 >/dev/null 2>&1 && +- tput sgr0 >/dev/null 2>&1 +- ) && +- color=t + + while test "$#" -ne 0 + do +@@ -136,35 +165,6 @@ else + } + fi + +-if test -n "$color"; then +- say_color () { +- ( +- TERM=$ORIGINAL_TERM +- export TERM +- case "$1" in +- error) tput bold; tput setaf 1;; # bold red +- skip) tput bold; tput setaf 2;; # bold green +- pass) tput setaf 2;; # green +- info) tput setaf 3;; # brown +- *) test -n "$quiet" && return;; +- esac +- shift +- printf " " +- printf "$@" +- tput sgr0 +- print_subtest +- ) +- } +-else +- say_color() { +- test -z "$1" && test -n "$quiet" && return +- shift +- printf " " +- printf "$@" +- print_subtest +- } +-fi +- + error () { + say_color error "error: $*\n" + GIT_EXIT_OK=t +-- +1.8.0 + -- 2.26.2