Checking for color support in build scripts

This commit is contained in:
Peter Slattery 2025-07-10 06:01:34 -07:00
parent d615358064
commit 8a918eef82
2 changed files with 30 additions and 36 deletions

View File

@ -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"

View File

@ -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]"