From 8a918eef825e76657e862250c9f68999cde951f0 Mon Sep 17 00:00:00 2001 From: Peter Slattery Date: Thu, 10 Jul 2025 06:01:34 -0700 Subject: [PATCH] Checking for color support in build scripts --- build_new/helpers/print-routines.sh | 35 ++++++++++++++++++++++++----- build_new/scripts/build.sh | 31 +------------------------ 2 files changed, 30 insertions(+), 36 deletions(-) diff --git a/build_new/helpers/print-routines.sh b/build_new/helpers/print-routines.sh index cb368334..781898a9 100644 --- a/build_new/helpers/print-routines.sh +++ b/build_new/helpers/print-routines.sh @@ -1,11 +1,34 @@ #!/bin/bash -# Colors & Styles for output -RED='\033[0;31m' -GREEN='\033[0;32m' -BLUE='\033[0;34m' -BOLD='\033[1m' -NC='\033[0m' # No Color +colors_supported() { + # Check if stdout is a terminal + [[ -t 1 ]] || return 1 + + # Check if TERM is set and not "dumb" + [[ -n "$TERM" && "$TERM" != "dumb" ]] || return 1 + + # Check if tput is available and supports colors + if command -v tput >/dev/null 2>&1; then + tput setaf 1 >/dev/null 2>&1 || return 1 + fi + + return 0 +} + +if colors_supported; then + # Colors & Styles for output + RED='\033[0;31m' + GREEN='\033[0;32m' + BLUE='\033[0;34m' + BOLD='\033[1m' + NC='\033[0m' # No Color +else + RED='' + GREEN='' + BLUE='' + BOLD='' + NC='' +fi print_success() { printf "%b✓%b %s\n" "$GREEN" "$NC" "$1" diff --git a/build_new/scripts/build.sh b/build_new/scripts/build.sh index 88cd16f4..23324826 100755 --- a/build_new/scripts/build.sh +++ b/build_new/scripts/build.sh @@ -19,37 +19,8 @@ HELPERS_DIR="$SCRIPT_DIR/../helpers" # Source configuration files source "$CONFIG_DIR/build-config.sh" +source "$HELPERS_DIR/print-routines.sh" -# ============================================================================= -# Utility Functions -# ============================================================================= - -# Colors for output -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[1;33m' -BLUE='\033[0;34m' -NC='\033[0m' # No Color - -print_success() { - echo -e "${GREEN}✓${NC} $1" -} - -print_warning() { - echo -e "${YELLOW}⚠${NC} $1" -} - -print_error() { - echo -e "${RED}✗${NC} $1" -} - -print_info() { - echo -e "${BLUE}ℹ${NC} $1" -} - -print_step() { - echo -e "${BLUE}===${NC} $1 ${BLUE}===${NC}" -} show_usage() { echo "Usage: $0 [platform] [config] [arch]"