Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73038C10F0E for ; Tue, 9 Apr 2019 18:11:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3736C20883 for ; Tue, 9 Apr 2019 18:11:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="pUvn3fNO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726541AbfDISLb (ORCPT ); Tue, 9 Apr 2019 14:11:31 -0400 Received: from mail-oi1-f195.google.com ([209.85.167.195]:38034 "EHLO mail-oi1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726396AbfDISLa (ORCPT ); Tue, 9 Apr 2019 14:11:30 -0400 Received: by mail-oi1-f195.google.com with SMTP id a6so14389736oie.5 for ; Tue, 09 Apr 2019 11:11:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=WPeMMqZxe7pSnZA4Kj8LtB3P/P+aqCT804UeW6SI7/I=; b=pUvn3fNOOJWmkgV+DEvk1auPhofVKlQqa+LkVbfNd7DrHTvK4oz0grRIeUH1lMpSIf iFnZATrWWwPieu3fhi99Yo8g0U9gT6RdaUie6TY9jRnEbcmbiIREmfcDZwLMDAzVAP/6 ddkiTR0jlvh+Ra9vz/CqG+X/sUwhTAg+XZ6hXpD1cZnzaKnJ5HdC2Nwff7YPvsHpxGyG VJWbKGqWSg6+aLIVWYNMfG0f+rKG02iOiu0xepXY2SCxuvb2VT6ig1d8nkv69+9WIYnN uSCt3NmViFIQevQRfjzz37EdBpu4DgUOTgCofkPkh6d5DG9NixrWvlKpDX4oFEP7333z hMDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=WPeMMqZxe7pSnZA4Kj8LtB3P/P+aqCT804UeW6SI7/I=; b=ZplZYI8Dpa3exJRUuDSGCe9HuxnY4SJYiBKPmpEhGN8qnDFhPaKBbI9Bispw9dmY00 Oi6CzBeZacHAXo+mTonqOWBQ4uJ9U3jtFdi4+Y75kcPyg3T8U8S1hWi8K3mWNHvroRM+ IKtfIobkwk5LOGS+DSyNbCo+6HgR5n1d+mb902LtPDmiWX998x6DdIAfXZ7jDdIMVVF1 tiKiN/8NF+jXOQ3irLHKgKkP/KsGIeS38qJAlLGqtMEJctzGTVHgPvjdL23iODvOqJ0t 2algWyVFmHIK7/kniexPgxSiDD0sm9Zt6xygSZ/nFLlBjKEEJDxCCi7ICg366410d6I7 e0iQ== X-Gm-Message-State: APjAAAXDhKggXURKU78zcaFtdUNHMXLailnO0DbVwrfR34ni8J8ELS5w TwV0pC86KnHFbgdPQwV2P6Qr0pN6K8GmUw== X-Google-Smtp-Source: APXvYqySMLVpNEgM9iUbvCPK8sU9IjchUeEeUpXpHLNYIOeHHcCS9Mqiza46Ky699XExWJaqPsDmwg== X-Received: by 2002:aca:5ec4:: with SMTP id s187mr22119520oib.22.1554833488981; Tue, 09 Apr 2019 11:11:28 -0700 (PDT) Received: from alago.cortijodelrio.net (CableLink-189-218-30-19.Hosts.InterCable.net. [189.218.30.19]) by smtp.googlemail.com with ESMTPSA id 70sm14158919otd.52.2019.04.09.11.11.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Apr 2019 11:11:27 -0700 (PDT) From: =?UTF-8?q?Daniel=20D=C3=ADaz?= To: kvm@vger.kernel.org Cc: =?UTF-8?q?Daniel=20D=C3=ADaz?= Subject: [kvm-unit-tests PATCH] scripts: Colorize only when possible Date: Tue, 9 Apr 2019 13:11:11 -0500 Message-Id: <20190409181111.1034-1-daniel.diaz@linaro.org> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Instead of colorizing the output of PASS/SKIP/FAIL all the time, do it only when the terminal supports colors and stdout is opened on a terminal. Signed-off-by: Daniel Díaz --- scripts/runtime.bash | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/scripts/runtime.bash b/scripts/runtime.bash index 200d5b6..0c38787 100644 --- a/scripts/runtime.bash +++ b/scripts/runtime.bash @@ -2,9 +2,23 @@ : ${MAX_SMP:=$(getconf _NPROCESSORS_CONF)} : ${TIMEOUT:=90s} -PASS() { echo -ne "\e[32mPASS\e[0m"; } -SKIP() { echo -ne "\e[33mSKIP\e[0m"; } -FAIL() { echo -ne "\e[31mFAIL\e[0m"; } +# Define text colors +# Check available colors on the terminal, if any +ncolors=`tput colors 2>/dev/null` +color_reset= +color_red= +color_green= +color_yellow= +# If stdout exists and number of colors is eight or more, use them +if [ -t 1 -a "$ncolors" -a "$ncolors" -ge 8 ]; then + color_reset="\e[0m" + color_red="\e[31m" + color_green="\e[32m" + color_yellow="\e[33m" +fi +PASS() { echo -ne "${color_green}PASS${color_reset}"; } +SKIP() { echo -ne "${color_yellow}SKIP${color_reset}"; } +FAIL() { echo -ne "${color_red}FAIL${color_reset}"; } extract_summary() { -- 2.17.1