Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/app/views/schedule-render.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
16 changes: 15 additions & 1 deletion src/app/views/schedule-render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[],
Expand All @@ -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 };
}
}
Expand Down