feat(statusline): reset countdowns, thinking fallback, color-grade percentages
- Replace fixed "5h"/"7d" window labels with hours/days remaining until the rate-limit window resets, derived from rate_limits.*.resets_at. - Wire up the previously-captured-but-unused $thinking variable as a fallback marker when no explicit effort.level is present. - Color-grade all three percentages (context, 5h, 7d): yellow >=80%, red >=90%. Uses \e[39m to restore default fg without losing the surrounding dim attribute. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
431ab60e8d
commit
7679cf9f4b
1 changed files with 37 additions and 3 deletions
|
|
@ -12,7 +12,40 @@ used=$(echo "$input" | jq -r '.context_window.used_percentage // empty')
|
|||
|
||||
# Rate limits
|
||||
rl_5h=$(echo "$input" | jq -r '.rate_limits.five_hour.used_percentage // empty')
|
||||
rl_5h_reset=$(echo "$input" | jq -r '.rate_limits.five_hour.resets_at // empty')
|
||||
rl_7d=$(echo "$input" | jq -r '.rate_limits.seven_day.used_percentage // empty')
|
||||
rl_7d_reset=$(echo "$input" | jq -r '.rate_limits.seven_day.resets_at // empty')
|
||||
|
||||
# Whole hours until a unix-epoch timestamp, ceiling-rounded; falls back to label on past/empty
|
||||
hours_until() {
|
||||
local ts="$1" fallback="$2"
|
||||
[[ -z "$ts" ]] && { printf '%s' "$fallback"; return; }
|
||||
local diff=$(( ts - $(date +%s) ))
|
||||
(( diff <= 0 )) && { printf '%s' "$fallback"; return; }
|
||||
printf '%dh' "$(( (diff + 3599) / 3600 ))"
|
||||
}
|
||||
|
||||
# Same idea, days
|
||||
days_until() {
|
||||
local ts="$1" fallback="$2"
|
||||
[[ -z "$ts" ]] && { printf '%s' "$fallback"; return; }
|
||||
local diff=$(( ts - $(date +%s) ))
|
||||
(( diff <= 0 )) && { printf '%s' "$fallback"; return; }
|
||||
printf '%dd' "$(( (diff + 86399) / 86400 ))"
|
||||
}
|
||||
|
||||
# Render a percentage with optional suffix; yellow >=80, red >=90. \e[39m restores default fg without dropping the surrounding dim.
|
||||
pct_color() {
|
||||
local val="$1" suffix="$2" int color=''
|
||||
int=${val%.*}
|
||||
(( int >= 90 )) && color=$'\e[31m'
|
||||
(( int >= 80 && int < 90 )) && color=$'\e[33m'
|
||||
if [[ -n "$color" ]]; then
|
||||
printf '%s%.0f%%%s\e[39m' "$color" "$val" "$suffix"
|
||||
else
|
||||
printf '%.0f%%%s' "$val" "$suffix"
|
||||
fi
|
||||
}
|
||||
|
||||
# Thinking / effort
|
||||
thinking=$(echo "$input" | jq -r '.thinking.enabled // empty')
|
||||
|
|
@ -23,11 +56,12 @@ dim=""
|
|||
[[ -n "$branch" ]] && dim="$dim ($branch)"
|
||||
[[ -n "$model" ]] && dim="$dim $model"
|
||||
[[ -n "$effort" ]] && dim="$dim $effort"
|
||||
[[ -n "$used" ]] && dim="$dim $(printf '%.0f%%' "$used")"
|
||||
[[ -z "$effort" && -n "$thinking" ]] && dim="$dim thinking"
|
||||
[[ -n "$used" ]] && dim="$dim $(pct_color "$used")"
|
||||
|
||||
usage=""
|
||||
[[ -n "$rl_5h" ]] && usage="$usage $(printf '%.0f%%/5h' "$rl_5h")"
|
||||
[[ -n "$rl_7d" ]] && usage="$usage $(printf '%.0f%%/7d' "$rl_7d")"
|
||||
[[ -n "$rl_5h" ]] && usage="$usage $(pct_color "$rl_5h" "/$(hours_until "$rl_5h_reset" 5h)")"
|
||||
[[ -n "$rl_7d" ]] && usage="$usage $(pct_color "$rl_7d" "/$(days_until "$rl_7d_reset" 7d)")"
|
||||
[[ -n "$usage" ]] && dim="$dim -$usage"
|
||||
|
||||
printf '\033[1m%s\033[0m\033[2m%s\033[0m\n' "$dir" "$dim"
|
||||
|
|
|
|||
Loading…
Reference in a new issue