```
fix(homebrew): 优化终端输出处理逻辑 - 交互式终端中保留 Homebrew 原生配色和实时进度显示 - 非交互式输出时继续使用语义着色处理 - 在 macOS 上使用 script 命令为 brew 分配伪终端以保留完整输出 - 添加对管道状态的更精确错误处理 - 更新文档说明终端输出行为的变化 ```
This commit is contained in:
@@ -573,7 +573,14 @@ colorize_brew_output() {
|
||||
run_brew_colored() {
|
||||
local pipeline_status=()
|
||||
|
||||
# 管道输出时禁用 Homebrew 自带的不完整配色,再统一按语义着色。
|
||||
# Homebrew 只有在 stdout 连接 TTY 时才会让 curl 显示动态下载进度。
|
||||
# 交互式终端中保留原始文件描述符,并使用 Homebrew 原生配色。
|
||||
if [[ -t 1 ]]; then
|
||||
brew "$@"
|
||||
return $?
|
||||
fi
|
||||
|
||||
# 非交互式输出无法显示动态进度,继续按行进行语义着色。
|
||||
if env -u HOMEBREW_COLOR brew "$@" 2>&1 | colorize_brew_output; then
|
||||
return 0
|
||||
fi
|
||||
@@ -697,17 +704,26 @@ run_brew_with_retries() {
|
||||
fi
|
||||
|
||||
: > "$ACTIVE_LOG_FILE"
|
||||
if env -u HOMEBREW_COLOR brew "$@" 2>&1 | tee "$ACTIVE_LOG_FILE" | colorize_brew_output; then
|
||||
status=0
|
||||
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
|
||||
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]}"
|
||||
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
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user