1#!/bin/sh 2# 3# Copyright (c) Linux Test Project, 2017 4# 5# This program is free software; you can redistribute it and/or modify 6# it under the terms of the GNU General Public License as published by 7# the Free Software Foundation; either version 2 of the License, or 8# (at your option) any later version. 9# 10# This program is distributed in the hope that it will be useful, 11# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13# GNU General Public License for more details. 14# 15# You should have received a copy of the GNU General Public License along 16# with this program; if not, write to the Free Software Foundation, Inc., 17# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18# 19# Written by Petr Vorel <pvorel@suse.cz> 20 21tst_flag2color() 22{ 23 # NOTE: these colors should match colors defined in include/tst_ansi_color.h 24 local ansi_color_blue='\033[1;34m' 25 local ansi_color_green='\033[1;32m' 26 local ansi_color_magenta='\033[1;35m' 27 local ansi_color_red='\033[1;31m' 28 local ansi_color_yellow='\033[1;33m' 29 30 case "$1" in 31 TPASS) printf $ansi_color_green;; 32 TFAIL) printf $ansi_color_red;; 33 TBROK) printf $ansi_color_red;; 34 TWARN) printf $ansi_color_magenta;; 35 TINFO) printf $ansi_color_blue;; 36 TCONF) printf $ansi_color_yellow;; 37 esac 38} 39 40tst_color_enabled() 41{ 42 [ "$LTP_COLORIZE_OUTPUT" = "n" ] || [ "$LTP_COLORIZE_OUTPUT" = "0" ] && return 0 43 [ "$LTP_COLORIZE_OUTPUT" = "y" ] || [ "$LTP_COLORIZE_OUTPUT" = "1" ] && return 1 44 [ -t 1 ] || return 0 45 return 1 46} 47 48tst_print_colored() 49{ 50 tst_color_enabled 51 local color=$? 52 53 [ "$color" = "1" ] && tst_flag2color "$1" 54 printf "$2" 55 [ "$color" = "1" ] && printf '\033[0m' 56} 57