Checking for color support in build scripts
This commit is contained in:
parent
d615358064
commit
8a918eef82
|
@ -1,11 +1,34 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
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
|
# Colors & Styles for output
|
||||||
RED='\033[0;31m'
|
RED='\033[0;31m'
|
||||||
GREEN='\033[0;32m'
|
GREEN='\033[0;32m'
|
||||||
BLUE='\033[0;34m'
|
BLUE='\033[0;34m'
|
||||||
BOLD='\033[1m'
|
BOLD='\033[1m'
|
||||||
NC='\033[0m' # No Color
|
NC='\033[0m' # No Color
|
||||||
|
else
|
||||||
|
RED=''
|
||||||
|
GREEN=''
|
||||||
|
BLUE=''
|
||||||
|
BOLD=''
|
||||||
|
NC=''
|
||||||
|
fi
|
||||||
|
|
||||||
print_success() {
|
print_success() {
|
||||||
printf "%b✓%b %s\n" "$GREEN" "$NC" "$1"
|
printf "%b✓%b %s\n" "$GREEN" "$NC" "$1"
|
||||||
|
|
|
@ -19,37 +19,8 @@ HELPERS_DIR="$SCRIPT_DIR/../helpers"
|
||||||
|
|
||||||
# Source configuration files
|
# Source configuration files
|
||||||
source "$CONFIG_DIR/build-config.sh"
|
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() {
|
show_usage() {
|
||||||
echo "Usage: $0 [platform] [config] [arch]"
|
echo "Usage: $0 [platform] [config] [arch]"
|
||||||
|
|
Loading…
Reference in New Issue