diff --git a/ui-tui/src/__tests__/statusRule.test.ts b/ui-tui/src/__tests__/statusRule.test.ts index bf34e37750c..0249c7e19e5 100644 --- a/ui-tui/src/__tests__/statusRule.test.ts +++ b/ui-tui/src/__tests__/statusRule.test.ts @@ -20,6 +20,6 @@ describe('statusRuleWidths', () => { }) it('omits the cwd segment when there is no room for it', () => { - expect(statusRuleWidths(2, 'abcdef')).toEqual({ leftWidth: 1, rightWidth: 0, separatorWidth: 1 }) + expect(statusRuleWidths(2, 'abcdef')).toEqual({ leftWidth: 2, rightWidth: 0, separatorWidth: 0 }) }) }) diff --git a/ui-tui/src/components/appChrome.tsx b/ui-tui/src/components/appChrome.tsx index 8c386200ad6..01bbd92c204 100644 --- a/ui-tui/src/components/appChrome.tsx +++ b/ui-tui/src/components/appChrome.tsx @@ -152,10 +152,16 @@ function ctxBar(pct: number | undefined, w = 10) { export function statusRuleWidths(cols: number, cwdLabel: string) { const width = Math.max(1, Math.floor(cols || 1)) - const separatorWidth = width >= 24 ? 3 : 1 + const desiredSeparatorWidth = width >= 24 ? 3 : 1 const minLeftWidth = width >= 24 ? 8 : 1 - const maxRightWidth = Math.max(0, width - separatorWidth - minLeftWidth) + const maxRightWidth = Math.max(0, width - desiredSeparatorWidth - minLeftWidth) + + if (!cwdLabel || maxRightWidth <= 0) { + return { leftWidth: width, rightWidth: 0, separatorWidth: 0 } + } + const rightWidth = Math.max(0, Math.min(cwdLabel.length, maxRightWidth)) + const separatorWidth = rightWidth > 0 ? desiredSeparatorWidth : 0 const leftWidth = Math.max(1, width - separatorWidth - rightWidth) return { leftWidth, rightWidth, separatorWidth }