From a4c27af6973974b88894020afc1fcb22072a9cc4 Mon Sep 17 00:00:00 2001 From: Brooklyn Nicholson Date: Sat, 23 May 2026 14:11:44 -0500 Subject: [PATCH] fix(tui): measure status cwd by display width Budget the right-hand status label by terminal display width so wide Unicode paths cannot wrap skinny status bars. --- ui-tui/src/__tests__/statusRule.test.ts | 7 +++++++ ui-tui/src/components/appChrome.tsx | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ui-tui/src/__tests__/statusRule.test.ts b/ui-tui/src/__tests__/statusRule.test.ts index 0249c7e19e5..635b35db996 100644 --- a/ui-tui/src/__tests__/statusRule.test.ts +++ b/ui-tui/src/__tests__/statusRule.test.ts @@ -22,4 +22,11 @@ describe('statusRuleWidths', () => { it('omits the cwd segment when there is no room for it', () => { expect(statusRuleWidths(2, 'abcdef')).toEqual({ leftWidth: 2, rightWidth: 0, separatorWidth: 0 }) }) + + it('budgets the cwd segment by display width, not utf-16 length', () => { + const widths = statusRuleWidths(30, '目录/分支') + + expect(widths.leftWidth + widths.separatorWidth + widths.rightWidth).toBeLessThanOrEqual(30) + expect(widths.rightWidth).toBeGreaterThan('目录/分支'.length) + }) }) diff --git a/ui-tui/src/components/appChrome.tsx b/ui-tui/src/components/appChrome.tsx index 01bbd92c204..771c917691f 100644 --- a/ui-tui/src/components/appChrome.tsx +++ b/ui-tui/src/components/appChrome.tsx @@ -1,4 +1,4 @@ -import { Box, type ScrollBoxHandle, Text } from '@hermes/ink' +import { Box, type ScrollBoxHandle, stringWidth, Text } from '@hermes/ink' import { useStore } from '@nanostores/react' import { type ReactNode, type RefObject, useEffect, useMemo, useRef, useState } from 'react' import unicodeSpinners from 'unicode-animations' @@ -160,7 +160,7 @@ export function statusRuleWidths(cols: number, cwdLabel: string) { return { leftWidth: width, rightWidth: 0, separatorWidth: 0 } } - const rightWidth = Math.max(0, Math.min(cwdLabel.length, maxRightWidth)) + const rightWidth = Math.max(0, Math.min(stringWidth(cwdLabel), maxRightWidth)) const separatorWidth = rightWidth > 0 ? desiredSeparatorWidth : 0 const leftWidth = Math.max(1, width - separatorWidth - rightWidth)