From patchwork Tue Apr 9 18:11:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Daniel_D=C3=ADaz?= X-Patchwork-Id: 10891913 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BE7E81708 for ; Tue, 9 Apr 2019 18:11:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ACECC28972 for ; Tue, 9 Apr 2019 18:11:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9E74528978; Tue, 9 Apr 2019 18:11:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A6D628972 for ; Tue, 9 Apr 2019 18:11:32 +0000 (UTC) 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_D=C3=ADaz?= To: kvm@vger.kernel.org Cc: =?utf-8?q?Daniel_D=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 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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() {