diff --git a/bin/purge.sh b/bin/purge.sh index 9d73424..4f7b104 100755 --- a/bin/purge.sh +++ b/bin/purge.sh @@ -98,7 +98,14 @@ perform_purge() { # Function to truncate path in the middle truncate_path() { local path="$1" - local max_len=80 + local term_cols + term_cols=$(tput cols 2>/dev/null || echo 80) + # Reserve some space for the spinner and text (approx 20 chars) + local max_len=$((term_cols - 20)) + # Ensure a reasonable minimum width + if (( max_len < 40 )); then + max_len=40 + fi if [[ ${#path} -le $max_len ]]; then echo "$path" diff --git a/cmd/status/metrics_battery.go b/cmd/status/metrics_battery.go index 3f14b23..4663b52 100644 --- a/cmd/status/metrics_battery.go +++ b/cmd/status/metrics_battery.go @@ -241,12 +241,24 @@ func collectThermal() ThermalStatus { valStr, _, _ = strings.Cut(valStr, ",") valStr, _, _ = strings.Cut(valStr, "}") valStr = strings.TrimSpace(valStr) - if powerMW, err := strconv.ParseFloat(valStr, 64); err == nil { - // macOS ioreg may return negative values as uint64 (two's complement overflow) - // If value > 2^63, convert from uint64 representation to proper signed value - if powerMW > float64(1<<63) { - powerMW = powerMW - 18446744073709551616.0 // 2^64 - } + + var powerMW float64 + var parsed bool + + // Strategy 1: Try parsing as a signed integer first. + // This handles standard positive values and explicit negative strings like "-12345". + if valInt, err := strconv.ParseInt(valStr, 10, 64); err == nil { + powerMW = float64(valInt) + parsed = true + } else if valUint, err := strconv.ParseUint(valStr, 10, 64); err == nil { + // Strategy 2: Try parsing as an unsigned integer (Two's Complement). + // ioreg often returns negative values as huge uint64 numbers (e.g. 2^64 - 100). + // Casting such a uint64 to int64 correctly restores the negative value. + powerMW = float64(int64(valUint)) + parsed = true + } + + if parsed { // Validate reasonable battery power range: -200W to 200W if powerMW > -200000 && powerMW < 200000 { thermal.BatteryPower = powerMW / 1000.0