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: 7 additions & 8 deletions src/app/views/home.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ describe('renderHome — week overview panel', () => {
language === 'en' ? /Mon|Tue|Wed|Thu|Fri|Sat|Sun/g : /[一二三四五六日]/g,
);
expect(weekdays).toHaveLength(7);
expect(positions(defined(lines[start + 2]), /▓▓|··|##|\.\./g)).toEqual(weekdays);
expect(positions(defined(lines[start + 2]), /▆▆|··|##|\.\./g)).toEqual(weekdays);
expect(positions(defined(lines[start + 3]), /\?\?/g)).toEqual(weekdays);
} finally {
setLanguage('en');
Expand Down Expand Up @@ -583,7 +583,7 @@ describe('renderHome — week overview panel', () => {
expect(titleIdx).toBeGreaterThanOrEqual(0);
expect(lines[titleIdx + 2]).toContain('Classes');
expect(lines[titleIdx + 3]).toContain('Events');
expect(lines[titleIdx + 4]).toContain('Scheduled');
expect(lines[titleIdx + 4]).toContain('Free');
expect(lines[titleIdx + 4]).toContain('Free');
expect(lines[titleIdx + 4]).not.toContain('Not loaded');
});
Expand All @@ -604,7 +604,7 @@ describe('renderHome — week overview panel', () => {
.trim()
.split(/\s+/)
.slice(1);
expect(classCells[5]).toBe('▓▓');
expect(classCells[5]).toBe('▆▆');
expect(classCells[6]).toBe('··');
} finally {
process.env['NBTCA_ICON_MODE'] = 'unicode';
Expand Down Expand Up @@ -633,7 +633,7 @@ describe('renderHome — week overview panel', () => {
.slice(1);
const saturday = eventCells[5];
const sunday = eventCells[6];
expect(saturday).toBe('▓▓');
expect(saturday).toBe('▆▆');
expect(sunday).toBe('··');
} finally {
process.env['NBTCA_ICON_MODE'] = 'unicode';
Expand Down Expand Up @@ -707,7 +707,6 @@ describe('renderHome — week overview panel', () => {
trans.timetable.weekOverviewTitle,
trans.timetable.weekAheadClasses,
trans.menu.events,
trans.timetable.weekAheadBusy,
trans.timetable.weekAheadFree,
]) {
expect(text).toContain(label.replace(/\s/g, ''));
Expand Down Expand Up @@ -894,8 +893,8 @@ describe('homeView.load()', () => {
await homeView.load(ctx);
const lines = stripAnsi(homeView.render(ctx).join('\n')).split('\n');
const titleIdx = lines.findIndex((l) => l.includes('Week overview'));
const cells = defined(lines[titleIdx + 3]).match(/▓▓|··/g);
expect(cells).toEqual(['▓▓', '··', '··', '··', '··', '··', '▓▓']);
const cells = defined(lines[titleIdx + 3]).match(/▆▆|··/g);
expect(cells).toEqual(['▆▆', '··', '··', '··', '··', '··', '▆▆']);
} finally {
vi.useRealTimers();
if (previousTimeZone === undefined) delete process.env.TZ;
Expand All @@ -915,7 +914,7 @@ describe('homeView.load()', () => {
const titleIdx = lines.findIndex((l) => l.includes('Week overview'));
expect(titleIdx).toBeGreaterThanOrEqual(0);
const eventLine = defined(lines[titleIdx + 3]);
expect(eventLine.match(/▓▓|··/g)).toHaveLength(7);
expect(eventLine.match(/▆▆|··/g)).toHaveLength(7);
expect(eventLine).not.toContain('??');
});
});
Expand Down
30 changes: 19 additions & 11 deletions src/app/views/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,12 @@ function renderWeekAheadGrid(
cols: number,
): string {
const trans = t();
const hasClassChar = pickIcon('▓▓', '##');
// A lower bar leaves a gap above, so a busy class cell and the event cell below it stay apart.
const hasClassChar = pickIcon('▆▆', '##');
const freeChar = pickIcon('··', '..');
const unknownChar = '??';
const busyClass = (text: string) => c.brand(text);
const busyEvent = (text: string) => c.success(text);

const rowLabelW =
Math.max(visualWidth(trans.timetable.weekAheadClasses), visualWidth(trans.menu.events)) + 1;
Expand All @@ -114,33 +117,38 @@ function renderWeekAheadGrid(
visualWidth(space.indent) + rowLabelW + days.length * cellWidth + (days.length - 1) * 2 <= width
? ' '
: ' ';
const classCell = (wd: number): string => (classDays[wd - 1] ? hasClassChar : freeChar);
const classCell = (wd: number): string =>
classDays[wd - 1] ? busyClass(hasClassChar) : type.muted(freeChar);
const eventCell = (wd: number): string =>
eventDays ? (eventDays[wd - 1] ? hasClassChar : freeChar) : unknownChar;
eventDays
? eventDays[wd - 1]
? busyEvent(hasClassChar)
: type.muted(freeChar)
: type.muted(unknownChar);
const legendText =
`${hasClassChar} ${trans.timetable.weekAheadBusy} ${freeChar} ${trans.timetable.weekAheadFree}` +
(eventDays ? '' : ` ${unknownChar} ${trans.timetable.weekAheadUnknown}`);
`${busyClass(hasClassChar)} ${trans.timetable.weekAheadClasses} ${busyEvent(hasClassChar)} ${trans.menu.events} ${type.muted(freeChar)} ${trans.timetable.weekAheadFree}` +
(eventDays ? '' : ` ${type.muted(unknownChar)} ${trans.timetable.weekAheadUnknown}`);
const dayLabels = labels.map((label) => type.hint(padEndV(label, cellWidth))).join(gap);
const headerLine = `${space.indent}${padEndV('', rowLabelW)}${dayLabels}`;

const classCells = days.map((wd) => type.body(padEndV(classCell(wd), cellWidth))).join(gap);
const classCells = days.map((wd) => padEndV(classCell(wd), cellWidth)).join(gap);
const classLine = `${space.indent}${type.hint(padEndV(trans.timetable.weekAheadClasses, rowLabelW))}${classCells}`;

const eventCells = days.map((wd) => type.body(padEndV(eventCell(wd), cellWidth))).join(gap);
const eventCells = days.map((wd) => padEndV(eventCell(wd), cellWidth)).join(gap);
const eventLine = `${space.indent}${type.hint(padEndV(trans.menu.events, rowLabelW))}${eventCells}`;

const legend = `${space.indent}${type.hint(legendText)}`;
const legend = wrappedIndentedLines(legendText, cols, type.hint);

const wideLines = [headerLine, classLine, eventLine, legend];
if (wideLines.every((line) => visualWidth(line) <= width)) return wideLines.join('\n');
const grid = [headerLine, classLine, eventLine];
if (grid.every((line) => visualWidth(line) <= width)) return [...grid, ...legend].join('\n');

const compactHeading = wrappedIndentedLines(
`${trans.timetable.weekAheadClasses} / ${trans.menu.events}`,
cols,
type.hint,
);
const compactDays = days.flatMap((wd) => {
const row = `${type.hint(weekdayShortLabel(wd))} ${type.body(classCell(wd))} ${type.body(eventCell(wd))}`;
const row = `${type.hint(weekdayShortLabel(wd))} ${classCell(wd)} ${eventCell(wd)}`;
return wrappedIndentedLines(row, cols, (value) => value);
});
const compactLegend = wrappedIndentedLines(legendText, cols, type.hint);
Expand Down
14 changes: 14 additions & 0 deletions src/core/theme.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ describe('design tokens', () => {
expect(space.indent).toBe(' ');
});

it('type.muted uses a fixed gray, not SGR dim', () => {
const level = chalk.level;
try {
chalk.level = 3;
expect(type.muted('x')).toBe('\x1b[38;2;124;133;148mx\x1b[39m');
chalk.level = 1;
expect(type.muted('x')).toBe(chalk.gray('x'));
chalk.level = 0;
expect(type.muted('x')).toBe('x');
} finally {
chalk.level = level;
}
});

it('type.hint returns its text (possibly styled)', () => {
expect(stripAnsi(type.hint('go'))).toBe('go');
});
Expand Down
2 changes: 2 additions & 0 deletions src/core/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ export const type = {
label: (s: string) => s,
body: (s: string) => s,
hint: (s: string) => s,
// A fixed mid-gray rather than SGR dim: some palettes render dim text close to invisible.
muted: (s: string) => (chalk.level >= 2 ? chalk.hex('#7c8594')(s) : chalk.gray(s)),
active: (s: string) => chalk.bold(c.brand(s)),
cursor: (s: string) => chalk.bgHex('#0ea5e9').black(s),
};
2 changes: 1 addition & 1 deletion src/features/calendar-heatmap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ describe('renderHeatmap', () => {
const output = renderHeatmap(makeBuckets('2025-06-09', [0, 1, 2, 3, 4]), today, {
color: true,
});
expect(output).toContain(chalk.dim('·'));
expect(output).toContain(chalk.gray('·'));
for (const glyph of ['░', '▒', '▓', '█']) expect(output).toContain(chalk.green(glyph));
expect(output).not.toMatch(/\u001b\[38;[25];/);
} finally {
Expand Down
2 changes: 1 addition & 1 deletion src/features/calendar-heatmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function levelCell(count: number, useColor: boolean): string {
const [unicode, ascii] = LEVEL_GLYPHS[level] ?? LEVEL_GLYPHS[0];
const cell = pickIcon(unicode, ascii);
if (!useColor) return cell;
return level === 0 ? c.muted(cell) : c.success(cell);
return level === 0 ? type.muted(cell) : c.success(cell);
}

interface MonthAnchor {
Expand Down
5 changes: 3 additions & 2 deletions src/features/calendar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,9 @@ describe('renderEventBrief', () => {
expect(at('2026-07-16T20:00:00')).toMatch(/38;2;14;165;233/);
expect(at('2026-07-16T20:00:00')).not.toMatch(/\x1b\[1m/);
const thisWeek = at('2026-07-18T20:00:00');
expect(thisWeek.slice(0, thisWeek.indexOf('X'))).not.toMatch(/\x1b\[2m\d/);
expect(at('2026-08-20T20:00:00')).toMatch(/\x1b\[2m0/);
const muted = /\x1b\[38;2;124;133;148m\d/;
expect(thisWeek.slice(0, thisWeek.indexOf('X'))).not.toMatch(muted);
expect(at('2026-08-20T20:00:00')).toMatch(muted);
} finally {
chalk.level = level;
}
Expand Down
4 changes: 2 additions & 2 deletions src/features/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,10 @@ export function renderEventBriefLines(
? c.brand
: proximity === 'week'
? type.body
: c.muted;
: type.muted;
const marker = proximity === 'today' ? type.active(pickIcon('●', '*')) : dateStyle(glyph.sep());
const titleStyled = styleTitle(e.title, proximity === 'today' ? type.active : type.body);
const content = `${dateStyle(eventWhen(e))} ${type.hint(dot)} ${titleStyled}${type.hint(recurringMark(e))}`;
const content = `${dateStyle(eventWhen(e))} ${type.muted(dot)} ${titleStyled}${type.muted(recurringMark(e))}`;
return hangingLines(marker, content, cols);
}

Expand Down
21 changes: 21 additions & 0 deletions src/features/schedule-render.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,27 @@ describe('renderWeekAgenda', () => {
expect(stripAnsi(later.join('\n'))).not.toContain('*');
});

it('mutes classes that have ended and keeps later ones at full strength', () => {
const level = chalk.level;
chalk.level = 3;
try {
const lines = renderWeekAgenda(
agendaTimetable,
1,
campusDateTime('2026-09-07', '09:00'),
80,
undefined,
false,
'2026-09-07',
);
const muted = '\x1b[38;2;124;133;148m';
expect(lines.find((line) => line.includes('Math'))).toContain(`${muted}Math`);
expect(lines.find((line) => line.includes('History'))).not.toContain(`${muted}History`);
} finally {
chalk.level = level;
}
});

it('lists every weekday with its classes and locations', () => {
const lines = renderWeekAgenda(agendaTimetable, 1, monday, 80).map(stripAnsi);
expect(lines).toHaveLength(8);
Expand Down
38 changes: 20 additions & 18 deletions src/features/schedule-render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,10 @@ function renderTimeline(
cursorPeriod !== undefined && m.startPeriod <= cursorPeriod && cursorPeriod <= m.endPeriod;
const connector = i === 0 ? topConnector : midConnector;
const marker = isLive ? type.active(pickIcon('▶', '>')) : ' ';
const timeCol = `${marker}${type.hint(startStr)} ${rule}${connector}${rule}`;
const timeStyle = isDone ? type.muted : type.hint;
const timeCol = `${marker}${timeStyle(startStr)} ${type.muted(`${rule}${connector}${rule}`)}`;
const styleName = (name: string): string =>
isLive ? type.active(name) : isDone ? type.hint(name) : type.body(name);
isLive ? type.active(name) : isDone ? type.muted(name) : type.body(name);

const compactStatusText = isDone ? trans.timetable.classDone : minutesLeft;
const renderLine = (
Expand All @@ -207,8 +208,8 @@ function renderTimeline(
const aligned = name === m.courseName;
const locationW = aligned && status && location !== undefined ? locationColW : 0;
const locationCol =
location || locationW > 0 ? ` ${type.hint(padEndV(location ?? '', locationW))}` : '';
const statusCol = status ? ` ${type.hint(status)}` : '';
location || locationW > 0 ? ` ${type.muted(padEndV(location ?? '', locationW))}` : '';
const statusCol = status ? ` ${isLive ? type.active(status) : type.muted(status)}` : '';
const shownName = aligned && (statusCol || locationCol) ? padEndV(name, nameColW) : name;
const content = `${currentTimeCol} ${styleName(shownName)}${locationCol}${statusCol}`;
return `${indent}${isCursor ? type.cursor(content) : content}`;
Expand All @@ -227,7 +228,7 @@ function renderTimeline(
return renderLine(clip(m.courseName, courseWidth), status, undefined);
}

const compactTimeCol = `${marker}${type.hint(startStr)}`;
const compactTimeCol = `${marker}${timeStyle(startStr)}`;
for (const indent of [space.indent, '']) {
const courseWidth = Math.floor(
width - visualWidth(renderLine('', '', undefined, compactTimeCol, indent)),
Expand All @@ -250,8 +251,8 @@ function renderTimeline(
if (!last) return lines.join('\n');
const lastEnd = periods.find((p) => p.period === last.endPeriod)?.end ?? '23:59';
const endLine = [
`${space.indent} ${type.hint(lastEnd)} ${rule}${bottomConnector}${rule} ${type.hint(trans.timetable.timelineEnd)}`,
`${space.indent}${type.hint(lastEnd)} ${rule}${bottomConnector}${rule}`,
`${space.indent} ${type.hint(lastEnd)} ${type.muted(`${rule}${bottomConnector}${rule}`)} ${type.muted(trans.timetable.timelineEnd)}`,
`${space.indent}${type.hint(lastEnd)} ${type.muted(`${rule}${bottomConnector}${rule}`)}`,
`${space.indent}${type.hint(lastEnd)}`,
type.hint(lastEnd),
].find(fits);
Expand Down Expand Up @@ -414,7 +415,7 @@ export function renderWeekGrid(
const emptyGlyph = pickIcon('·', '.');
const sepGlyph = pickIcon('│', '|');
const gap = ` ${sepGlyph} `;
const sep = type.hint(gap);
const sep = type.muted(gap);
const { rowHeadW, idealColWidths, totalIdealColW } = weekGridMetrics(timetable, weekNumber, now);
const availableForCols = Math.max(
0,
Expand Down Expand Up @@ -469,10 +470,10 @@ export function renderWeekGrid(
locCells.push(starting ? type.body(paddedLoc) : type.hint(paddedLoc));
} else if (starting) {
nameCells.push(isToday ? type.active(paddedName) : type.body(paddedName));
locCells.push(type.hint(paddedLoc));
locCells.push(type.muted(paddedLoc));
} else {
nameCells.push(type.hint(paddedName));
locCells.push(type.hint(paddedLoc));
nameCells.push(type.muted(paddedName));
locCells.push(type.muted(paddedLoc));
}
}
const rowHead = type.hint(
Expand All @@ -482,15 +483,15 @@ export function renderWeekGrid(
.map((cell, index) =>
index === 0
? cell
: type.hint(gap.slice(index - 1 === widened ? 1 : 0, index === widened ? 2 : 3)) + cell,
: type.muted(gap.slice(index - 1 === widened ? 1 : 0, index === widened ? 2 : 3)) + cell,
)
.join('');
lines.push(space.indent + rowHead + nameRow);
lines.push(space.indent + blankHead + locCells.join(sep));

const next = sorted[i + 1];
if (next && minutesOf(next.start) - minutesOf(p.end) > GAP_THRESHOLD_MINUTES) {
lines.push(space.indent + type.hint(pickIcon('╌', '-').repeat(totalW)));
lines.push(space.indent + type.muted(pickIcon('╌', '-').repeat(totalW)));
}
});
return lines.join('\n');
Expand Down Expand Up @@ -551,10 +552,10 @@ export function renderWeekAgenda(
};
const room = Math.max(1, width - visualWidth(head(0)));
const nameStyle = (m: TimetableMeeting): ((value: string) => string) =>
isSelected(m) ? type.active : isOver(wd, m) ? type.hint : type.body;
isSelected(m) ? type.active : isOver(wd, m) ? type.muted : type.body;

if (meetings.length === 0) {
lines.push(`${head(0)}${type.hint(dot)}`);
lines.push(`${head(0)}${type.muted(dot)}`);
return;
}

Expand Down Expand Up @@ -590,9 +591,10 @@ export function renderWeekAgenda(
);
const body =
location && nameW !== undefined
? `${nameStyle(m)(padEndV(m.courseName, nameW))} ${type.hint(location)}`
? `${nameStyle(m)(padEndV(m.courseName, nameW))} ${type.muted(location)}`
: nameStyle(m)(clip(m.courseName, Math.max(1, nameRoom)));
lines.push(`${head(row)}${type.hint(time)}${body}`);
const timeStyle = isOver(wd, m) && !isSelected(m) ? type.muted : type.hint;
lines.push(`${head(row)}${timeStyle(time)}${body}`);
});
});
for (const course of timetable.untimedCourses ?? []) {
Expand Down Expand Up @@ -675,7 +677,7 @@ function weekStrip(meeting: TimetableMeeting, progress: CourseProgress): string
const week = index + 1;
const mark = weeks.has(week) ? full : empty;
if (week === progress.currentWeek) return type.active(mark);
return weeks.has(week) && week > progress.currentWeek ? type.body(mark) : type.hint(mark);
return weeks.has(week) && week > progress.currentWeek ? type.body(mark) : type.muted(mark);
}).join(' ');
}

Expand Down
1 change: 0 additions & 1 deletion src/i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ export interface Translations {
exportSaved: string;
weekOverviewTitle: string;
weekAheadClasses: string;
weekAheadBusy: string;
weekAheadFree: string;
weekAheadUnknown: string;
termPreviewWeek: string;
Expand Down
1 change: 0 additions & 1 deletion src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,6 @@
"exportSaved": "Saved: {path}",
"weekOverviewTitle": "Week overview",
"weekAheadClasses": "Classes",
"weekAheadBusy": "Scheduled",
"weekAheadFree": "Free",
"weekAheadUnknown": "Not loaded",
"termPreviewWeek": "Week 1 preview",
Expand Down
1 change: 0 additions & 1 deletion src/i18n/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,6 @@
"exportSaved": "已保存:{path}",
"weekOverviewTitle": "本周概览",
"weekAheadClasses": "课程",
"weekAheadBusy": "有安排",
"weekAheadFree": "无安排",
"weekAheadUnknown": "尚未加载",
"termPreviewWeek": "第一周预览",
Expand Down