Give the usage bars a line of their own, always
Squeezing the 5h/7d group onto line one was what cost the reset times and the pace figure at laptop width, and it made the layout jump between one and two lines as the branch name or the cost changed width. Line two is now the group's own at every terminal size, so both timestamps and the burn rate fit; the ladder only starts giving things up below ~80 columns. The bars also survive down to 35 columns now rather than being dropped below 68, since a line of their own is all they need. Every rung of the ladder is fit-checked, the last one included: with the floor that low, a percentage the API reports in more digits than anyone expects would otherwise have overflowed the line rather than dropped the group. The two timestamps still cost ~10 subprocesses to format on a line that redraws per keystroke, so that is skipped when line two provably cannot show them -- an under-estimate, so the fit check stays the decider. With nothing left to squeeze, WRAP_NARROW, the wrap band and the split tier go: line one is the full tier down to 150, wide to 68, then narrow. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
2a785a55a7
commit
ab96dfc52a
7 changed files with 148 additions and 155 deletions
|
|
@ -124,13 +124,13 @@ out=$(render 245)
|
|||
|| bad "30min old: refetched, not held for the hour" "$out"
|
||||
|
||||
# ------------------------------------------------- bars shown => bars refreshed
|
||||
# The refresh is gated on the same tier check as the bars themselves, so the
|
||||
# two must agree at every width: wrapped onto line two included, and 68 being
|
||||
# WRAP_FLOOR, the narrowest width that still shows them.
|
||||
# The refresh is gated on the same width check as the bars themselves, so the
|
||||
# two must agree at every width, 35 being RL_MIN_WIDTH -- the narrowest usable
|
||||
# width the bars still fit on their own line.
|
||||
echo
|
||||
echo "Every width that shows the bars refreshes them:"
|
||||
|
||||
for u in 245 115 85 68; do
|
||||
for u in 245 115 85 68 50 35; do
|
||||
cached_response_aged 360
|
||||
out=$(render "$u")
|
||||
if case "$out" in *"5h"*) true ;; *) false ;; esac; then
|
||||
|
|
@ -141,14 +141,14 @@ for u in 245 115 85 68; do
|
|||
fi
|
||||
done
|
||||
|
||||
# One column below the wrap floor the group is dropped entirely — nothing is
|
||||
# One column below RL_MIN_WIDTH the group is dropped entirely — nothing is
|
||||
# shown, so nothing should be paid for either.
|
||||
cached_response_aged 360
|
||||
out=$(render 67)
|
||||
case "$out" in *"5h"*) bad "usable 67: no bars at the narrow tier" "$out" ;;
|
||||
*) ok "usable 67: no bars at the narrow tier" ;; esac
|
||||
[ "$(calls)" = "0" ] && ok "usable 67: no API call when no bars are shown" \
|
||||
|| bad "usable 67: no API call when no bars are shown" "$out"
|
||||
out=$(render 34)
|
||||
case "$out" in *"5h"*) bad "usable 34: no bars below the group's floor" "$out" ;;
|
||||
*) ok "usable 34: no bars below the group's floor" ;; esac
|
||||
[ "$(calls)" = "0" ] && ok "usable 34: no API call when no bars are shown" \
|
||||
|| bad "usable 34: no API call when no bars are shown" "$out"
|
||||
|
||||
# --------------------------------------------------------- offline retry backoff
|
||||
# With no network, curl can burn --max-time 10 before giving up. A failed fetch
|
||||
|
|
|
|||
|
|
@ -20,7 +20,12 @@ SCRIPT = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))
|
|||
BRANCHES = ["main", "feature/some-longer-branch-name",
|
||||
"feature/an-extremely-long-branch-name-that-keeps-going-and-going"]
|
||||
MODELS = ["Opus 5", "Opus 5 (1M context)"]
|
||||
WIDTHS = range(64, 245, 10)
|
||||
# Starts at the narrowest terminal line ONE fits on with the longest branch
|
||||
# below (measured: 44 usable columns, i.e. 49 with padding 2) -- the pre-existing
|
||||
# narrow-tier floor, which width_test.sh marks XFAIL. Everything above it is
|
||||
# fair game, and that now includes the band from RL_MIN_WIDTH up, where the
|
||||
# usage group is shown but has few columns to spare.
|
||||
WIDTHS = range(49, 245, 10)
|
||||
# The cwd basename is rendered at the widest layouts and is capped by
|
||||
# CWD_MAX_LEN; vary it, since a long project directory was one of the ways
|
||||
# line one used to overflow.
|
||||
|
|
|
|||
|
|
@ -214,8 +214,8 @@ import sys,re,unicodedata
|
|||
for ln in sys.stdin.read().rstrip('\n').split('\n'):
|
||||
p=re.sub(r'\033\[[0-9;]*m','',ln)
|
||||
print(sum(2 if unicodedata.east_asian_width(c) in 'WF' else 1 for c in p))"; }
|
||||
over=0; toomany=0; orphan=0; dropped=0; shown=0
|
||||
for u in 200 180 160 155 150 145 140 135 130 125 120 116 110 105 100 95 90 85 80 75 70 68; do
|
||||
over=0; toomany=0; orphan=0; dropped=0; shown=0; missing_wide=0
|
||||
for u in 200 180 160 155 150 145 140 135 130 125 120 116 110 105 100 95 90 85 80 75 70 68 60 55 50 45 40; do
|
||||
o=$(render "$MON" 12345 "$u")
|
||||
ws=$(printf '%s' "$o" | widths)
|
||||
while read -r c; do [ "$c" -gt "$u" ] && over=1; done <<< "$ws"
|
||||
|
|
@ -224,13 +224,18 @@ for u in 200 180 160 155 150 145 140 135 130 125 120 116 110 105 100 95 90 85 80
|
|||
# be the last thing standing.
|
||||
case "$o" in
|
||||
*"%/d"*) shown=1; case "$o" in *Fable*) ;; *) orphan=1 ;; esac ;;
|
||||
*) case "$o" in *Fable*) dropped=1 ;; esac ;;
|
||||
*) case "$o" in *Fable*) dropped=1 ;; esac
|
||||
[ "$u" -ge 68 ] && missing_wide=1 ;;
|
||||
esac
|
||||
done
|
||||
[ "$over" = 0 ] && ok "no line exceeds the usable width at any width" || bad "no line exceeds the usable width at any width"
|
||||
[ "$toomany" = 0 ] && ok "never more than two lines" || bad "never more than two lines"
|
||||
[ "$orphan" = 0 ] && ok "pace never outlives the per-model bar" || bad "pace never outlives the per-model bar"
|
||||
[ "$shown" = 1 ] && ok "pace is actually rendered somewhere in the sweep" || bad "pace is actually rendered somewhere in the sweep"
|
||||
# Line two is the group's own, so pace survives every width that fits a normal
|
||||
# status line -- it is only given up on a genuinely tiny terminal.
|
||||
[ "$missing_wide" = 0 ] && ok "pace is kept at every width from 68 columns up" \
|
||||
|| bad "pace is kept at every width from 68 columns up"
|
||||
[ "$dropped" = 1 ] && ok "the pace rung is reachable: some width keeps the bar but drops pace" \
|
||||
|| bad "the pace rung is reachable: some width keeps the bar but drops pace"
|
||||
|
||||
|
|
@ -238,7 +243,7 @@ done
|
|||
# readout, pace is the number this segment exists for, so the credits go first.
|
||||
fixture 7.0 "$R_MON_ISO" "$(scoped 0 null)" "$EXTRA_ON"
|
||||
pace_alone=0; credits_alone=0
|
||||
for u in 200 180 160 155 150 145 140 135 130 125 120 116 110 105 100 95 90 85 80 75 70 68; do
|
||||
for u in 200 180 160 155 150 145 140 135 130 125 120 116 110 105 100 95 90 85 80 75 70 68 60 55 50 45 40; do
|
||||
o=$(render "$MON" 12345 "$u")
|
||||
case "$o" in
|
||||
*"%/d"*) case "$o" in *extra*) ;; *) pace_alone=1 ;; esac ;;
|
||||
|
|
|
|||
|
|
@ -68,13 +68,25 @@ out=$(render 250)
|
|||
case "$out" in *"Fable"*"10%"*) ok "wide: renders 'Fable' with its percentage" ;;
|
||||
*) bad "wide: renders 'Fable' with its percentage" "$out" ;; esac
|
||||
|
||||
# Wrapped: assert Fable is on line TWO specifically, not merely present.
|
||||
out=$(render 90)
|
||||
[ "$(count "$out")" = "2" ] && ok "narrow: wraps to two lines" || bad "narrow: wraps to two lines" "$out"
|
||||
case "$(nth "$out" 2)" in *"Fable"*"10%"*) ok "narrow: Fable is on line two" ;;
|
||||
*) bad "narrow: Fable is on line two" "$out" ;; esac
|
||||
case "$(nth "$out" 1)" in *"Fable"*) bad "narrow: Fable not duplicated on line one" "$out" ;;
|
||||
*) ok "narrow: Fable not duplicated on line one" ;; esac
|
||||
# The usage group always gets a line of its own, however wide the terminal is.
|
||||
for w in 250 116 90; do
|
||||
out=$(render "$w")
|
||||
[ "$(count "$out")" = "2" ] && ok "width $w: usage is on its own line" \
|
||||
|| bad "width $w: usage is on its own line" "$out"
|
||||
case "$(nth "$out" 2)" in *"Fable"*"10%"*) ok "width $w: Fable is on line two" ;;
|
||||
*) bad "width $w: Fable is on line two" "$out" ;; esac
|
||||
case "$(nth "$out" 1)" in *"Fable"*) bad "width $w: Fable not duplicated on line one" "$out" ;;
|
||||
*) ok "width $w: Fable not duplicated on line one" ;; esac
|
||||
done
|
||||
|
||||
# A line of its own is what buys room for the reset times: both the 5-hour
|
||||
# clock time and the 7-day date survive down to a laptop-sized terminal, where
|
||||
# they used to be the first thing given up.
|
||||
for w in 250 116 100; do
|
||||
out=$(render "$w")
|
||||
case "$(nth "$out" 2)" in *"↺"*"↺"*) ok "width $w: both reset times are shown" ;;
|
||||
*) bad "width $w: both reset times are shown" "$out" ;; esac
|
||||
done
|
||||
|
||||
# The per-model bar is the reason the group exists on a Fable-capable account,
|
||||
# so it must survive by wrapping and never be dropped to squeeze the group onto
|
||||
|
|
@ -105,7 +117,7 @@ for desc in "no limits key:{$BASE,\"extra_usage\":{\"is_enabled\":false}}" \
|
|||
name="${desc%%:*}"; json="${desc#*:}"
|
||||
printf '%s' "$json" | fixture
|
||||
out=$(render 250)
|
||||
if [ "$(count "$out")" = "1" ] && case "$out" in *"5h"*"7d"*) true;; *) false;; esac \
|
||||
if [ "$(count "$out")" = "2" ] && case "$(nth "$out" 2)" in *"5h"*"7d"*) true;; *) false;; esac \
|
||||
&& case "$out" in *error*|*null*|*"jq:"*|*"line "*) false;; *) true;; esac; then
|
||||
ok "$name"
|
||||
else bad "$name" "$out"; fi
|
||||
|
|
@ -139,33 +151,17 @@ fixture <<JSON
|
|||
"limits":[{"kind":"weekly_scoped","percent":10,"scope":{"model":{"display_name":"A\nB"}},"is_active":true}]}
|
||||
JSON
|
||||
out=$(render 250)
|
||||
[ "$(count "$out")" = "1" ] && ok "newline in display_name does not split the line" \
|
||||
[ "$(count "$out")" = "2" ] && ok "newline in display_name does not split the line" \
|
||||
|| bad "newline in display_name does not split the line" "$out"
|
||||
fixture <<JSON
|
||||
{$BASE,"extra_usage":{"is_enabled":false},"limits":[]}
|
||||
JSON
|
||||
mkdir -p "$REPO/sub"
|
||||
out=$(render 250 "$REPO/pro\\nj")
|
||||
[ "$(count "$out")" = "1" ] && ok "literal backslash-n in cwd does not split the line" \
|
||||
[ "$(count "$out")" = "2" ] && ok "literal backslash-n in cwd does not split the line" \
|
||||
|| bad "literal backslash-n in cwd does not split the line" "$out"
|
||||
out=$(render 250 "$REPO" 'Opus\n5')
|
||||
[ "$(count "$out")" = "1" ] && ok "literal backslash-n in model name does not split the line" \
|
||||
[ "$(count "$out")" = "2" ] && ok "literal backslash-n in model name does not split the line" \
|
||||
|| bad "literal backslash-n in model name does not split the line" "$out"
|
||||
|
||||
# --------------------------------------------- WRAP_NARROW=false (regression §2)
|
||||
echo "With WRAP_NARROW=false the single line must still be fit-checked:"
|
||||
NOWRAP=$(mktemp); sed 's/^WRAP_NARROW=true/WRAP_NARROW=false/' "$SCRIPT" > "$NOWRAP"
|
||||
fixture <<JSON
|
||||
{$BASE,"extra_usage":{"is_enabled":false},
|
||||
"limits":[{"kind":"weekly_scoped","percent":10,"scope":{"model":{"display_name":"Fable"}},"is_active":true}]}
|
||||
JSON
|
||||
for w in 81 105 130; do
|
||||
out=$(stdin_json "$REPO" "Opus 5" | TERM_WIDTH=$w bash "$NOWRAP" 2>&1 | sed $'s/\033\[[0-9;]*m//g')
|
||||
u=$(( w - 5 )); c=$(vis "$out")
|
||||
[ "$(count "$out")" = "1" ] && [ "$c" -le "$u" ] \
|
||||
&& ok "width $w: one line, $c <= usable $u" \
|
||||
|| bad "width $w: one line within usable $u (got $(count "$out") line/s, $c cols)" "$out"
|
||||
done
|
||||
rm -f "$NOWRAP"
|
||||
|
||||
echo; echo "pass=$pass fail=$fail"; [ "$fail" -eq 0 ]
|
||||
|
|
|
|||
|
|
@ -82,8 +82,10 @@ echo "Fallbacks and tiers:"
|
|||
has true "" "◆ thinking" 200 "absent effort falls back to the old label"
|
||||
has true garbage "◆ thinking" 200 "an unrecognised level falls back rather than widening the line"
|
||||
has true high "◆ high" 120 "the label survives the wide tier"
|
||||
# The split tier (76-99) is unreachable while WRAP_NARROW=true -- that band is
|
||||
# overridden to wide and wrapped -- so only narrow is asserted here.
|
||||
# Below 68 columns the narrow tier drops the segment entirely; between there
|
||||
# and 100 the compact tier keeps the label, since the usage group has moved off
|
||||
# line one and left room for it.
|
||||
has true high "◆ high" 85 "the label survives the compact tier"
|
||||
lacks true high "◆" 60 "narrow tier hides the segment"
|
||||
|
||||
echo
|
||||
|
|
|
|||
|
|
@ -54,10 +54,13 @@ check() { # usable, branch, model, cost, [xfail-reason]
|
|||
[ "$over" = "1" ] && why="line exceeds usable width"
|
||||
# INVARIANT 2: at most two lines
|
||||
[ "$n" -gt 2 ] && why="${why:-more than two lines}"
|
||||
# INVARIANT 3: only wrap when it was actually necessary
|
||||
if [ -z "$why" ] && [ "$n" = "2" ]; then
|
||||
local l1 l2; l1=$(printf '%s\n' "$ws" | sed -n 1p); l2=$(printf '%s\n' "$ws" | sed -n 2p)
|
||||
[ $(( l1 + 3 + l2 )) -le "$u" ] && why="wrapped unnecessarily (would have fit on one line)"
|
||||
# INVARIANT 3: the usage group always gets a line of its own, so that the
|
||||
# reset times and the pace figure have room whatever line one holds. Below
|
||||
# RL_MIN_WIDTH there is no group to wrap, so a single line is expected.
|
||||
if [ -z "$why" ]; then
|
||||
if [ "$u" -ge 35 ] && [ "$n" != "2" ]; then why="usage not on its own line"
|
||||
elif [ "$u" -lt 35 ] && [ "$n" != "1" ]; then why="wrapped with no usage group"
|
||||
fi
|
||||
fi
|
||||
|
||||
local label="usable=$u branch=${#branch}ch model='${model:0:12}' lines=$n max=$mx"
|
||||
|
|
@ -75,7 +78,7 @@ M1="Opus 5"
|
|||
M2="Opus 5 (1M context)"
|
||||
|
||||
echo "Sweep of usable widths, short branch:"
|
||||
for u in 200 155 150 130 116 110 100 95 85 75 68 67 60 40; do check "$u" "$SHORT" "$M1" 0.50; done
|
||||
for u in 200 155 150 130 116 110 100 95 85 75 68 67 60 50 40; do check "$u" "$SHORT" "$M1" 0.50; done
|
||||
# Narrow tier has a ~35-col floor; nothing can fit below that. Verified byte-identical
|
||||
# on the pre-change script, so not a regression.
|
||||
check 25 "$SHORT" "$M1" 0.50 "narrow tier floor ~35 cols"
|
||||
|
|
@ -86,7 +89,7 @@ for u in 200 150 116 100 85 68; do check "$u" "$LONG" "$M2" 4.61; done
|
|||
check 40 "$LONG" "$M2" 4.61 "narrow tier floor ~43 cols with a long branch"
|
||||
echo "Large cost figure:"
|
||||
for u in 116 85 68; do check "$u" "$SHORT" "$M1" 1234.56; done
|
||||
# ... and with a long branch, which is what makes the wrap-mode branch budget
|
||||
# ... and with a long branch, which is what makes the compact-tier branch budget
|
||||
# bite: a four-digit cost is three columns wider than the budget assumed.
|
||||
echo "Large cost figure with a long branch:"
|
||||
for u in 68 69 70 75 85; do check "$u" "$LONG" "$M1" 1234.56; done
|
||||
|
|
|
|||
Loading…
Reference in a new issue