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
6 changes: 3 additions & 3 deletions src/app/views/schedule-render.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,8 @@ describe('renderSchedule', () => {
).map(stripAnsi);
const out = lines.join('\n');

expect(out).toMatch(/Mon\S? +08:00 Math/);
expect(out).toMatch(/ +10:00 Physics/);
expect(out).toMatch(/Mon 9\/7\S? +08:00\S* +Math/);
expect(out).toMatch(/ +10:00\S* +Physics/);
expect(out).toContain('Sun');
expect(lines.some((line) => line.trimStart().startsWith('←'))).toBe(false);
});
Expand Down Expand Up @@ -684,7 +684,7 @@ describe('renderSchedule', () => {
lines.find((l) => /^\s*08:00.08:45 /.test(l));

expect(gridRow(narrowLines)).toBeUndefined();
expect(narrowLines.join('\n')).toMatch(new RegExp(`08:00 ${longName}`));
expect(narrowLines.join('\n')).toMatch(new RegExp(`08:00\\S* +${longName}`));
expect(gridRow(wideLines)).toContain(longName);
});
});
Expand Down
10 changes: 7 additions & 3 deletions src/app/views/schedule-render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ function renderHubWeek(
inlineLines: string[],
fallbackLines: string[],
tt: Timetable,
weekOne: string | undefined,
week: number,
todayWd: Weekday,
now: Date,
Expand All @@ -278,7 +279,7 @@ function renderHubWeek(
): HubWeek {
const layouts: [string[] | null, boolean][] = [
[fittingWeekGrid(tt, week, now, rows, cols, cursor), true],
[renderWeekAgenda(tt, week, now, cols, cursor), false],
[renderWeekAgenda(tt, week, now, cols, cursor, false, weekOne), false],
];
for (const [layout, grid] of layouts) {
if (!layout) continue;
Expand All @@ -294,6 +295,7 @@ function renderHubWeek(

function renderWeekBody(
tt: Timetable,
weekOne: string | undefined,
week: number,
todayWd: Weekday,
now: Date,
Expand All @@ -305,8 +307,8 @@ function renderWeekBody(
const title = heading(t().timetable.hubWeek);
const layouts = [
fittingWeekGrid(tt, week, now, rows - 2, cols, cursor),
renderWeekAgenda(tt, week, now, cols, cursor),
renderWeekAgenda(tt, week, now, cols, cursor, true),
renderWeekAgenda(tt, week, now, cols, cursor, false, weekOne),
renderWeekAgenda(tt, week, now, cols, cursor, true, weekOne),
];
for (const layout of layouts) {
if (!layout) continue;
Expand Down Expand Up @@ -368,6 +370,7 @@ function layoutHub(
pre.inlineLines,
pre.fallbackLines,
pre.tt,
state.weekOne,
pre.week,
createTimetableSchedule(pre.tt).weekdayAt(now),
now,
Expand Down Expand Up @@ -556,6 +559,7 @@ export function renderSchedule(
});
return renderWeekBody(
state.timetable,
state.weekOne,
Math.max(1, schedule.weekAt(now)),
schedule.weekdayAt(now),
now,
Expand Down
27 changes: 27 additions & 0 deletions src/features/schedule-render.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1377,6 +1377,33 @@ describe('renderWeekAgenda', () => {
};
const monday = campusDateTime('2026-09-07', '07:00');

it('dates each day, shows time ranges, and notes untimed courses in their week', () => {
const withUntimed: Timetable = {
...agendaTimetable,
untimedCourses: [
{
sourceId: null,
courseName: 'Fitness test',
teacherNames: [],
campus: null,
location: null,
weeks: [1],
kind: 'practice',
},
],
};
const lines = renderWeekAgenda(withUntimed, 1, monday, 80, undefined, false, '2026-09-07').map(
stripAnsi,
);
const out = lines.join('\n');
expect(out).toMatch(/Mon 9\/7\S* +08:00-08:45 Math/);
expect(out).toContain('Thu 9/10');
expect(lines.at(-1)).toMatch(/Fitness test - time to be announced/);
expect(
renderWeekAgenda(withUntimed, 2, monday, 80, undefined, false, '2026-09-07').join('\n'),
).not.toContain('Fitness test');
});

it('lists every weekday with its classes and locations', () => {
const lines = renderWeekAgenda(agendaTimetable, 1, monday, 80).map(stripAnsi);
expect(lines).toHaveLength(8);
Expand Down
65 changes: 49 additions & 16 deletions src/features/schedule-render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ function renderTimeline(
};
});
const nameColW = Math.max(...rows.map((row) => visualWidth(row.m.courseName)));
const statusColW = Math.max(...rows.map((row) => visualWidth(row.statusText)));
const locationColW = Math.max(...rows.map((row) => visualWidth(row.locationText)));

const lines = rows.map(
({ m, startStr, isLive, isDone, minutesLeft, statusText, locationText }, i) => {
Expand All @@ -200,39 +200,40 @@ function renderTimeline(
const renderLine = (
name: string,
status: string,
location: string,
location: string | undefined,
currentTimeCol = timeCol,
indent: string = space.indent,
): string => {
const aligned = name === m.courseName;
const statusW = aligned && location ? statusColW : 0;
const statusCol = status || statusW > 0 ? ` ${type.hint(padEndV(status, statusW))}` : '';
const locationCol = location ? ` ${type.hint(location)}` : '';
const locationW = aligned && status && location !== undefined ? locationColW : 0;
const locationCol =
location || locationW > 0 ? ` ${type.hint(padEndV(location ?? '', locationW))}` : '';
const statusCol = status ? ` ${type.hint(status)}` : '';
const shownName = aligned && (statusCol || locationCol) ? padEndV(name, nameColW) : name;
const content = `${currentTimeCol} ${styleName(shownName)}${statusCol}${locationCol}`;
const content = `${currentTimeCol} ${styleName(shownName)}${locationCol}${statusCol}`;
return `${indent}${isCursor ? type.cursor(content) : content}`;
};

const whole = [
renderLine(m.courseName, statusText, locationText),
renderLine(m.courseName, statusText, ''),
renderLine(m.courseName, compactStatusText, ''),
renderLine(m.courseName, statusText, undefined),
renderLine(m.courseName, compactStatusText, undefined),
].find(fits);
if (whole) return whole;

for (const status of compactStatusText ? [compactStatusText, ''] : ['']) {
const courseWidth = Math.floor(width - visualWidth(renderLine('', status, '')));
const courseWidth = Math.floor(width - visualWidth(renderLine('', status, undefined)));
if (courseWidth <= visualWidth(ellipsis())) continue;
return renderLine(clip(m.courseName, courseWidth), status, '');
return renderLine(clip(m.courseName, courseWidth), status, undefined);
}

const compactTimeCol = `${marker}${type.hint(startStr)}`;
for (const indent of [space.indent, '']) {
const courseWidth = Math.floor(
width - visualWidth(renderLine('', '', '', compactTimeCol, indent)),
width - visualWidth(renderLine('', '', undefined, compactTimeCol, indent)),
);
if (courseWidth <= visualWidth(ellipsis())) continue;
return renderLine(clip(m.courseName, courseWidth), '', '', compactTimeCol, indent);
return renderLine(clip(m.courseName, courseWidth), '', undefined, compactTimeCol, indent);
}

const timeOnly = [
Expand Down Expand Up @@ -270,7 +271,7 @@ export function renderTodayTimeline(
periods,
now,
{ weekday: 0, isToday: true },
false,
true,
undefined,
cols,
);
Expand Down Expand Up @@ -500,16 +501,31 @@ export function renderWeekAgenda(
cols = Number.POSITIVE_INFINITY,
cursor?: { weekday: number; period: number },
oneLinePerDay = false,
weekOneMonday?: string,
): string[] {
const schedule = createTimetableSchedule(timetable);
const todayWd = schedule.weekdayAt(now);
const width = lineBudget(cols);
const todayMark = pickIcon('•', '*');
const dot = glyph.sep();
const pointer = glyph.cursor();
const dates = WEEKDAY_KEYS.map((_, i) =>
weekOneMonday === undefined ? undefined : teachingDate(weekOneMonday, weekNumber, i + 1),
);
const today = campusIsoDate(now);
const shortDate = (iso: string | undefined) =>
iso === undefined ? '' : ` ${Number(iso.slice(5, 7))}/${Number(iso.slice(8, 10))}`;
const labels = WEEKDAY_KEYS.map(
(_, i) => `${weekdayShortLabel(i + 1)}${i + 1 === todayWd ? todayMark : ''}`,
(_, i) =>
`${weekdayShortLabel(i + 1)}${oneLinePerDay ? '' : shortDate(dates[i])}${i + 1 === todayWd ? todayMark : ''}`,
);
const isOver = (wd: number, m: TimetableMeeting): boolean => {
const date = dates[wd - 1];
if (date === undefined) return false;
if (date !== today) return date < today;
const end = timetable.periods.find((p) => p.period === m.endPeriod)?.end;
return end !== undefined && campusDateTime(date, end).getTime() <= now.getTime();
};
const labelW = Math.max(...labels.map(visualWidth));
const nameColW = Math.max(
0,
Expand Down Expand Up @@ -537,7 +553,7 @@ export function renderWeekAgenda(
};
const room = Math.max(1, width - visualWidth(head(0)));
const nameStyle = (m: TimetableMeeting): ((value: string) => string) =>
isSelected(m) ? type.active : type.body;
isSelected(m) ? type.active : isOver(wd, m) ? type.hint : type.body;

if (meetings.length === 0) {
lines.push(`${head(0)}${type.hint(dot)}`);
Expand All @@ -564,7 +580,11 @@ export function renderWeekAgenda(

meetings.forEach((m, row) => {
const start = timetable.periods.find((p) => p.period === m.startPeriod)?.start ?? '';
const time = `${start} `;
const ranged = `${span(m, timetable.periods)} `;
const time =
room - visualWidth(ranged) >= nameColW + 3 + visualWidth(m.location ?? '')
? ranged
: `${start} `;
const nameRoom = room - visualWidth(time);
const location = m.location ?? '';
const nameW = [nameColW, visualWidth(m.courseName)].find(
Expand All @@ -577,9 +597,22 @@ export function renderWeekAgenda(
lines.push(`${head(row)}${type.hint(time)}${body}`);
});
});
for (const course of timetable.untimedCourses ?? []) {
if (!course.weeks.includes(weekNumber)) continue;
const mark = type.hint(pickIcon('◇', '*'));
const text = `${course.courseName} ${dot} ${t().timetable.untimedNote}`;
lines.push(
`${space.indent}${' '.repeat(visualWidth(pointer))} ${mark} ${type.body(clip(text, Math.max(1, width - visualWidth(pointer) - 4)))}`,
);
}
return lines;
}

function teachingDate(weekOneMonday: string, week: number, weekday: number): string {
const monday = campusDateTime(weekOneMonday, '12:00').getTime();
return campusIsoDate(new Date(monday + ((week - 1) * 7 + weekday - 1) * 86_400_000));
}

/** Lists weeks with runs of three or more collapsed, such as "1, 3, 5–17". */
function formatWeekRange(weeks: readonly number[]): string {
const sorted = [...new Set(weeks)].sort((a, b) => a - b);
Expand Down
1 change: 1 addition & 0 deletions src/i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ export interface Translations {
detailTomorrow: string;
detailAlso: string;
detailWeeksValue: string;
untimedNote: string;
teacherSeparator: string;
noClassOnDay: string;
countdownDays: string;
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,8 @@
"helpOpenClass": "Class details",
"footerDay": "day",
"footerClass": "class",
"footerDetail": "details"
"footerDetail": "details",
"untimedNote": "time to be announced"
},
"theme": {
"current": "Current theme settings",
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,8 @@
"helpOpenClass": "查看课程详情",
"footerDay": "星期",
"footerClass": "课程",
"footerDetail": "详情"
"footerDetail": "详情",
"untimedNote": "时间待定"
},
"theme": {
"current": "当前主题设置",
Expand Down
Loading