diff --git a/src/ui/DetailsPanel.tsx b/src/ui/DetailsPanel.tsx index cd3351c..befabe5 100644 --- a/src/ui/DetailsPanel.tsx +++ b/src/ui/DetailsPanel.tsx @@ -198,6 +198,7 @@ const TASK_GLYPHS = { completed: "✓", running: "◐", pending: "○" } as cons function StatusBlock({ details, inner }: { readonly details: ThreadDetails; readonly inner: number }) { const { status, context, limits } = details; if (!status && !context && !limits) return null; + const shownLimits = limits ? fittingLimits(limits, inner - "Limits ".length - " left".length) : null; const filled = context?.left == null ? 0 : Math.round((context.left / 100) * BAR_CELLS); return ( @@ -216,16 +217,17 @@ function StatusBlock({ details, inner }: { readonly details: ThreadDetails; read )} ) : null} - {limits ? ( + {shownLimits ? ( {"Limits "} - - {limits.map((limit, index) => ( + + {shownLimits.map((limit, index) => ( {`${index > 0 ? " · " : ""}${limit.label} `} {`${limit.left}%`} ))} + left ) : null} @@ -359,3 +361,16 @@ function countsText(insertions: number, deletions: number): string { function startTruncate(text: string, width: number): string { return text.length > width ? `…${text.slice(text.length - width + 1)}` : text; } + +/** The tightest limits first, as many as fit on the line, and always the tightest. */ +function fittingLimits(limits: readonly T[], width: number): T[] { + const shown: T[] = []; + let used = 0; + for (const limit of [...limits].sort((a, b) => a.left - b.left)) { + const cost = (shown.length > 0 ? 3 : 0) + `${limit.label} ${limit.left}%`.length; + if (shown.length > 0 && used + cost > width) break; + shown.push(limit); + used += cost; + } + return shown; +}