Просмотр исходного кода

mini: reserve headroom before showing usage (#38659)

Simon Klee 3 недель назад
Родитель
Сommit
edaee143d9
2 измененных файлов с 26 добавлено и 3 удалено
  1. 5 3
      packages/tui/src/mini/footer.width.ts
  2. 21 0
      packages/tui/test/mini/footer.view.test.tsx

+ 5 - 3
packages/tui/src/mini/footer.width.ts

@@ -6,6 +6,8 @@ export function footerWidthPolicy(width: number) {
   }
   }
 }
 }
 
 
+const USAGE_HEADROOM = 8
+
 export function footerStatuslinePolicy(input: {
 export function footerStatuslinePolicy(input: {
   width: number
   width: number
   mainWidth: number
   mainWidth: number
@@ -18,10 +20,10 @@ export function footerStatuslinePolicy(input: {
 }) {
 }) {
   let remaining = input.width - input.mainWidth - (input.commandWidth ?? 0)
   let remaining = input.width - input.mainWidth - (input.commandWidth ?? 0)
   let hasSection = input.commandWidth !== undefined
   let hasSection = input.commandWidth !== undefined
-  const include = (width: number | undefined) => {
+  const include = (width: number | undefined, headroom = 0) => {
     if (width === undefined) return false
     if (width === undefined) return false
     const required = width + (hasSection ? 3 : 1)
     const required = width + (hasSection ? 3 : 1)
-    if (remaining < required) return false
+    if (remaining < required + headroom) return false
     remaining -= required
     remaining -= required
     hasSection = true
     hasSection = true
     return true
     return true
@@ -40,7 +42,7 @@ export function footerStatuslinePolicy(input: {
     (showAgent || input.agentWidth === undefined) &&
     (showAgent || input.agentWidth === undefined) &&
     contextComplete &&
     contextComplete &&
     (showVariant || input.variantWidth === undefined) &&
     (showVariant || input.variantWidth === undefined) &&
-    include(input.usageWidth)
+    include(input.usageWidth, USAGE_HEADROOM)
 
 
   return {
   return {
     showAgent,
     showAgent,

+ 21 - 0
packages/tui/test/mini/footer.view.test.tsx

@@ -1522,6 +1522,27 @@ test("direct footer shows full usage metadata when room is available", async ()
   }
   }
 })
 })
 
 
+test("direct footer omits usage when it would fill the statusline", async () => {
+  const app = await renderFooter({
+    state: { phase: "running", model: "GPT-5.6 SoL", usage: "8.4K (1%) · $0.01" },
+    currentVariant: "high",
+    mono: true,
+    width: 66,
+  })
+
+  try {
+    await app.renderOnce()
+    const frame = app.captureCharFrame()
+
+    expect(frame).toContain("esc interrupt")
+    expect(frame).toContain("GPT-5.6 SoL high")
+    expect(frame).toContain("ctrl+p cmd")
+    expect(frame).not.toContain("8.4K")
+  } finally {
+    app.cleanup()
+  }
+})
+
 test("direct footer hides routine activity and shows explicit notices", async () => {
 test("direct footer hides routine activity and shows explicit notices", async () => {
   let status = ""
   let status = ""
   const app = await renderFooter({
   const app = await renderFooter({