Files
omarchy/install/helpers/logging.sh
2025-11-16 19:25:52 -05:00

58 lines
1.5 KiB
Bash

# Log output UI for .automated_script.sh
# Tails /var/log/omarchy-install.log and displays it with pretty formatting
start_log_output() {
local ANSI_SAVE_CURSOR="\033[s"
local ANSI_RESTORE_CURSOR="\033[u"
local ANSI_CLEAR_LINE="\033[2K"
local ANSI_HIDE_CURSOR="\033[?25l"
local ANSI_RESET="\033[0m"
local ANSI_GRAY="\033[90m"
local log_file="${1:-/var/log/omarchy-install.log}"
# Save cursor position and hide cursor
printf $ANSI_SAVE_CURSOR
printf $ANSI_HIDE_CURSOR
(
local log_lines=20
local max_line_width=$((LOGO_WIDTH - 4))
while true; do
# Read the last N lines into an array
mapfile -t current_lines < <(tail -n $log_lines "$log_file" 2>/dev/null)
# Build complete output buffer with escape sequences
output=""
for ((i = 0; i < log_lines; i++)); do
line="${current_lines[i]:-}"
# Truncate if needed
if [ ${#line} -gt $max_line_width ]; then
line="${line:0:$max_line_width}..."
fi
# Add clear line escape and formatted output for each line
if [ -n "$line" ]; then
output+="${ANSI_CLEAR_LINE}${ANSI_GRAY}${PADDING_LEFT_SPACES}${line}${ANSI_RESET}\n"
else
output+="${ANSI_CLEAR_LINE}${PADDING_LEFT_SPACES}\n"
fi
done
printf "${ANSI_RESTORE_CURSOR}%b" "$output"
sleep 0.1
done
) &
monitor_pid=$!
}
stop_log_output() {
if [ -n "${monitor_pid:-}" ]; then
kill $monitor_pid 2>/dev/null || true
wait $monitor_pid 2>/dev/null || true
unset monitor_pid
fi
}