refactor(homebrew): 统一 Homebrew 输出着色处理

- 移除交互式终端的特殊处理逻辑,禁用 Homebrew 自带动态进度显示
- 统一使用语义着色处理所有场景下的 Homebrew 输出
- 删除 BSD script 伪终端分配功能,简化日志记录流程
- 更新 README 文档说明输出着色的一致性改进
This commit is contained in:
2026-07-23 08:45:15 +08:00
parent 3c677eddcf
commit d090edd5c6
2 changed files with 13 additions and 28 deletions
+12 -27
View File
@@ -573,14 +573,8 @@ colorize_brew_output() {
run_brew_colored() {
local pipeline_status=()
# Homebrew 只有在 stdout 连接 TTY 时才会让 curl 显示动态下载进度。
# 交互式终端中保留原始文件描述符,并使用 Homebrew 原生配色
if [[ -t 1 ]]; then
brew "$@"
return $?
fi
# 非交互式输出无法显示动态进度,继续按行进行语义着色。
# 禁用 Homebrew 自带的不完整配色,统一按语义着色。这里不能在
# 交互式终端直接运行 brew,否则版本变化行会绕过着色器
if env -u HOMEBREW_COLOR brew "$@" 2>&1 | colorize_brew_output; then
return 0
fi
@@ -704,26 +698,17 @@ run_brew_with_retries() {
fi
: > "$ACTIVE_LOG_FILE"
if [[ -t 0 && -t 1 && -t 2 && "$(uname -s 2>/dev/null || true)" == "Darwin" && -x /usr/bin/script ]]; then
# BSD script 为 brew 分配伪终端:既保留实时进度,又记录完整输出供错误分类。
if /usr/bin/script -q -e "$ACTIVE_LOG_FILE" brew "$@"; then
status=0
else
status=$?
fi
if env -u HOMEBREW_COLOR brew "$@" 2>&1 | tee "$ACTIVE_LOG_FILE" | colorize_brew_output; then
status=0
else
if env -u HOMEBREW_COLOR brew "$@" 2>&1 | tee "$ACTIVE_LOG_FILE" | colorize_brew_output; then
status=0
else
pipeline_status=("${PIPESTATUS[@]}")
status="${pipeline_status[0]}"
if ((${pipeline_status[1]:-0} != 0)); then
print_error "failed to write retry log."
status="${pipeline_status[1]}"
elif ((${pipeline_status[2]:-0} != 0)); then
print_error "failed to colorize Homebrew output."
status="${pipeline_status[2]}"
fi
pipeline_status=("${PIPESTATUS[@]}")
status="${pipeline_status[0]}"
if ((${pipeline_status[1]:-0} != 0)); then
print_error "failed to write retry log."
status="${pipeline_status[1]}"
elif ((${pipeline_status[2]:-0} != 0)); then
print_error "failed to colorize Homebrew output."
status="${pipeline_status[2]}"
fi
fi