#!/usr/bin/env bash # lib/output.sh — Human and JSON output formatting for android-fs5 # shellcheck shell=bash # ANSI colors (disabled when not a terminal) if [[ -t 1 ]]; then _RED='\033[0;31m' _GREEN='\033[0;32m' _YELLOW='\033[1;33m' _CYAN='\033[0;36m' _RESET='\033[0m' else _RED='' _GREEN='' _YELLOW='' _CYAN='' _RESET='' fi # out_human MSG — print informational message to stdout out_human() { echo -e "${_CYAN}${1}${_RESET}" } # out_success MSG — print success message with checkmark out_success() { echo -e "${_GREEN}✓ ${1}${_RESET}" } # out_warn MSG — print warning to stdout out_warn() { echo -e "${_YELLOW}⚠ ${1}${_RESET}" } # out_error MSG — print error message to stderr out_error() { echo -e "${_RED}✗ ${1}${_RESET}" >&2 } # out_json KEY=VALUE ... — emit a JSON object from key=value pairs # Usage: out_json serial="RD51QE202392" model="FS5" battery_level=85 out_json() { local -a pairs=("$@") python3 - "${pairs[@]}" <<'PYEOF' import sys, json data = {} for arg in sys.argv[1:]: if '=' in arg: key, _, val = arg.partition('=') # Attempt numeric conversion try: if '.' in val: data[key] = float(val) else: data[key] = int(val) except ValueError: # Boolean strings if val.lower() == 'true': data[key] = True elif val.lower() == 'false': data[key] = False else: data[key] = val print(json.dumps(data, indent=2)) PYEOF }