diff --git a/src/app/views/schedule-render.test.ts b/src/app/views/schedule-render.test.ts index f931c34..5113f00 100644 --- a/src/app/views/schedule-render.test.ts +++ b/src/app/views/schedule-render.test.ts @@ -455,6 +455,21 @@ describe('renderSchedule', () => { expect(lines.filter((line) => line.includes('08:00'))).toHaveLength(1); }); + it('keeps the gap before the week heading after the banner gap is dropped', () => { + const render = (rows: number) => + renderSchedule( + { mode: 'hub', key: '2026-3', weekOne: '2026-09-07', timetable: busyTimetable }, + campusDateTime('2026-09-07', '07:00'), + rows, + 100, + ).map(stripAnsi); + const roomy = render(40); + const tight = render(roomy.length - 1); + const weekIndex = tight.findIndex((line) => line.trim() === 'This week'); + expect(tight[1]?.trim()).not.toBe(''); + expect(tight[weekIndex - 1]?.trim()).toBe(''); + }); + it('shows the week agenda instead of one day when it fits below a hundred columns', () => { const lines = renderSchedule( { mode: 'hub', key: '2026-3', weekOne: '2026-09-07', timetable: busyTimetable }, diff --git a/src/app/views/schedule-render.ts b/src/app/views/schedule-render.ts index 5856e96..5d43140 100644 --- a/src/app/views/schedule-render.ts +++ b/src/app/views/schedule-render.ts @@ -269,6 +269,20 @@ interface HubWeek { grid: boolean; } +/** + * The lines with every gap, then with gaps removed one at a time from the first, which only + * separates the next-class banner, so the section headings keep their space longest. + */ +function withFewerGaps(lines: readonly string[]): string[][] { + const gaps = lines.flatMap((line, index) => (line === '' ? [index] : [])); + return gaps + .map((_, dropped) => { + const skip = new Set(gaps.slice(0, dropped)); + return lines.filter((_, index) => !skip.has(index)); + }) + .concat([lines.filter((line) => line !== '')]); +} + function renderHubWeek( inlineLines: string[], fallbackLines: string[], @@ -287,7 +301,7 @@ function renderHubWeek( ]; for (const [layout, grid] of layouts) { if (!layout) continue; - for (const head of [inlineLines, inlineLines.filter((line) => line !== ''), fallbackLines]) { + for (const head of [...withFewerGaps(inlineLines), fallbackLines]) { if (head.length + layout.length <= rows) return { lines: [...head, ...layout], grid }; } }