@nbtca/prompt 1.5.14 → 1.5.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app/chrome.js +7 -6
- package/dist/app/fields/list-field.js +7 -7
- package/dist/app/views/docs-render.js +1 -1
- package/dist/app/views/docs.js +10 -5
- package/dist/app/views/events-render.js +21 -8
- package/dist/app/views/events.js +52 -43
- package/dist/app/views/home.js +34 -37
- package/dist/app/views/schedule-render.js +63 -21
- package/dist/app/views/schedule.js +49 -6
- package/dist/app/views/settings.js +7 -4
- package/dist/auth/cookie-jar.js +206 -0
- package/dist/auth/cookie-transport.js +53 -29
- package/dist/auth/nbt-auth.js +10 -9
- package/dist/core/components/menu.js +44 -9
- package/dist/core/logo.js +37 -18
- package/dist/core/motion.js +23 -5
- package/dist/core/text.js +2 -2
- package/dist/core/theme.js +25 -9
- package/dist/features/calendar-query.js +39 -9
- package/dist/features/calendar.js +26 -22
- package/dist/features/docs.js +1 -1
- package/dist/features/links.js +16 -2
- package/dist/features/schedule-render.js +152 -69
- package/dist/features/schedule-view.js +19 -33
- package/dist/i18n/locales/en.json +33 -12
- package/dist/i18n/locales/zh.json +31 -10
- package/package.json +2 -6
|
@@ -1,10 +1,30 @@
|
|
|
1
1
|
import { campusDateTime, campusIsoDate, createTimetableSchedule } from '@nbtca/nbtcal/timetable';
|
|
2
2
|
import { countdownParts, isCountdownUrgent } from './calendar-query.js';
|
|
3
|
-
import { c, type, space, glyph } from '../core/theme.js';
|
|
3
|
+
import { c, type, space, glyph, MAX_FRAME_COLS } from '../core/theme.js';
|
|
4
4
|
import { pickIcon } from '../core/icons.js';
|
|
5
5
|
import { padEndV, truncate, visualWidth, wrapAnsiToVisualWidth } from '../core/text.js';
|
|
6
6
|
import { addLocalDays, parseLocalMonday } from '../core/calendar-day.js';
|
|
7
7
|
import { t, fmt, getCurrentLanguage } from '../i18n/index.js';
|
|
8
|
+
const ellipsis = () => pickIcon('…', '...');
|
|
9
|
+
function clip(text, width) {
|
|
10
|
+
return truncate(text, width, ellipsis());
|
|
11
|
+
}
|
|
12
|
+
export function formatClassCountdown(p) {
|
|
13
|
+
const trans = t().timetable;
|
|
14
|
+
if (p.past)
|
|
15
|
+
return trans.nowLabel;
|
|
16
|
+
const values = { days: String(p.days), hours: String(p.hours), minutes: String(p.minutes) };
|
|
17
|
+
if (p.days > 0)
|
|
18
|
+
return fmt(trans.countdownDays, values);
|
|
19
|
+
if (p.hours > 0)
|
|
20
|
+
return fmt(trans.countdownHours, values);
|
|
21
|
+
return fmt(trans.countdownMinutes, values);
|
|
22
|
+
}
|
|
23
|
+
function formatMinutesLeft(end, now) {
|
|
24
|
+
const p = countdownParts(end, now);
|
|
25
|
+
const minutes = p.days * 1440 + p.hours * 60 + p.minutes;
|
|
26
|
+
return fmt(t().timetable.minutesRemaining, { minutes: String(minutes) });
|
|
27
|
+
}
|
|
8
28
|
function span(m, periods) {
|
|
9
29
|
const s = periods.find((p) => p.period === m.startPeriod)?.start ?? '';
|
|
10
30
|
const e = periods.find((p) => p.period === m.endPeriod)?.end ?? '';
|
|
@@ -15,13 +35,7 @@ export function renderNextClassBanner(next, now, cols = Number.POSITIVE_INFINITY
|
|
|
15
35
|
if (!next)
|
|
16
36
|
return '';
|
|
17
37
|
const p = countdownParts(next.start, now);
|
|
18
|
-
const when = p
|
|
19
|
-
? trans.timetable.nowLabel
|
|
20
|
-
: p.days > 0
|
|
21
|
-
? `${p.days}d ${p.hours}h`
|
|
22
|
-
: p.hours > 0
|
|
23
|
-
? `${p.hours}h ${p.minutes}m`
|
|
24
|
-
: `${p.minutes}m`;
|
|
38
|
+
const when = formatClassCountdown(p);
|
|
25
39
|
const styleWhen = isCountdownUrgent(p) ? c.warn : type.hint;
|
|
26
40
|
const whenStyled = styleWhen(when);
|
|
27
41
|
const dot = pickIcon('·', '-');
|
|
@@ -44,7 +58,7 @@ export function renderNextClassBanner(next, now, cols = Number.POSITIVE_INFINITY
|
|
|
44
58
|
const courseWidth = Math.floor(cols - visualWidth(prefix) - visualWidth(suffix));
|
|
45
59
|
if (courseWidth < 3)
|
|
46
60
|
continue;
|
|
47
|
-
return `${prefix}${type.body(
|
|
61
|
+
return `${prefix}${type.body(clip(courseName, courseWidth))}${suffix}`;
|
|
48
62
|
}
|
|
49
63
|
const countdownOnly = [
|
|
50
64
|
`${space.indent}${marker} ${whenStyled}`,
|
|
@@ -57,7 +71,7 @@ export function renderNextClassBanner(next, now, cols = Number.POSITIVE_INFINITY
|
|
|
57
71
|
if (whenWidth === 0)
|
|
58
72
|
return '';
|
|
59
73
|
if (whenWidth >= 3)
|
|
60
|
-
return styleWhen(
|
|
74
|
+
return styleWhen(clip(when, whenWidth));
|
|
61
75
|
let compactWhen = '';
|
|
62
76
|
for (const char of when) {
|
|
63
77
|
if (visualWidth(compactWhen + char) > whenWidth)
|
|
@@ -79,11 +93,28 @@ export function weekdayShortLabel(wd) {
|
|
|
79
93
|
];
|
|
80
94
|
return labels[wd - 1] ?? '';
|
|
81
95
|
}
|
|
82
|
-
function
|
|
96
|
+
function weekdayLongLabel(wd) {
|
|
97
|
+
return new Intl.DateTimeFormat(getCurrentLanguage() === 'zh' ? 'zh-CN' : 'en-US', {
|
|
98
|
+
weekday: 'long',
|
|
99
|
+
timeZone: 'UTC',
|
|
100
|
+
}).format(Date.UTC(2024, 0, wd));
|
|
101
|
+
}
|
|
102
|
+
export function lineBudget(cols) {
|
|
103
|
+
return Number.isFinite(cols)
|
|
104
|
+
? Math.max(1, Math.min(Math.floor(cols), MAX_FRAME_COLS) - visualWidth(space.indent))
|
|
105
|
+
: Number.POSITIVE_INFINITY;
|
|
106
|
+
}
|
|
107
|
+
function renderTimeline(meetings, periods, now, day, alwaysShowLocation, cursorPeriod, cols = Number.POSITIVE_INFINITY) {
|
|
83
108
|
const trans = t();
|
|
109
|
+
const width = lineBudget(cols);
|
|
110
|
+
const fits = (line) => visualWidth(line) <= width;
|
|
84
111
|
const sorted = [...meetings].sort((a, b) => a.startPeriod - b.startPeriod);
|
|
85
|
-
if (sorted.length === 0)
|
|
86
|
-
|
|
112
|
+
if (sorted.length === 0) {
|
|
113
|
+
const empty = day.isToday
|
|
114
|
+
? trans.timetable.noClassToday
|
|
115
|
+
: fmt(trans.timetable.noClassOnDay, { weekday: weekdayLongLabel(day.weekday) });
|
|
116
|
+
return `${space.indent}${type.hint(empty)}`;
|
|
117
|
+
}
|
|
87
118
|
const today = campusIsoDate(now);
|
|
88
119
|
const minute = Math.floor(now.getTime() / 60_000) * 60_000;
|
|
89
120
|
const dot = pickIcon('·', '-');
|
|
@@ -95,25 +126,20 @@ function renderTimeline(meetings, periods, now, isToday, alwaysShowLocation, cur
|
|
|
95
126
|
const startStr = periods.find((p) => p.period === m.startPeriod)?.start ?? '00:00';
|
|
96
127
|
const endStr = periods.find((p) => p.period === m.endPeriod)?.end ?? '23:59';
|
|
97
128
|
const end = campusDateTime(today, endStr);
|
|
98
|
-
const isLive = isToday && campusDateTime(today, startStr).getTime() <= minute && minute <= end.getTime();
|
|
99
|
-
const isDone = isToday && minute > end.getTime();
|
|
129
|
+
const isLive = day.isToday && campusDateTime(today, startStr).getTime() <= minute && minute <= end.getTime();
|
|
130
|
+
const isDone = day.isToday && minute > end.getTime();
|
|
100
131
|
const isCursor = cursorPeriod !== undefined && m.startPeriod <= cursorPeriod && cursorPeriod <= m.endPeriod;
|
|
101
132
|
const connector = i === 0 ? topConnector : midConnector;
|
|
102
133
|
const marker = isLive ? type.active(pickIcon('▶', '>')) : ' ';
|
|
103
134
|
const timeCol = `${marker}${type.hint(startStr)} ${rule}${connector}${rule}`;
|
|
104
135
|
const styleName = (name) => isLive ? type.active(name) : isDone ? type.hint(name) : type.body(name);
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const remaining = countdownParts(end, now);
|
|
113
|
-
const mins = remaining.days * 1440 + remaining.hours * 60 + remaining.minutes;
|
|
114
|
-
statusText = `${trans.timetable.classLive} ${dot} ${fmt(trans.timetable.minutesRemaining, { minutes: String(mins) })}`;
|
|
115
|
-
compactStatusText = `${mins}m`;
|
|
116
|
-
}
|
|
136
|
+
const minutesLeft = isLive ? formatMinutesLeft(end, now) : '';
|
|
137
|
+
const statusText = isDone
|
|
138
|
+
? trans.timetable.classDone
|
|
139
|
+
: isLive
|
|
140
|
+
? `${trans.timetable.classLive} ${dot} ${minutesLeft}`
|
|
141
|
+
: '';
|
|
142
|
+
const compactStatusText = isDone ? trans.timetable.classDone : minutesLeft;
|
|
117
143
|
const showLoc = alwaysShowLocation ? Boolean(m.location) : isLive && Boolean(m.location);
|
|
118
144
|
const locationText = showLoc ? (m.location ?? '') : '';
|
|
119
145
|
const renderLine = (name, status, location, currentTimeCol = timeCol, indent = space.indent) => {
|
|
@@ -122,57 +148,49 @@ function renderTimeline(meetings, periods, now, isToday, alwaysShowLocation, cur
|
|
|
122
148
|
const content = `${currentTimeCol} ${styleName(name)}${statusCol}${locationCol}`;
|
|
123
149
|
return `${indent}${isCursor ? type.cursor(content) : content}`;
|
|
124
150
|
};
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
for (const status of adaptiveStatuses) {
|
|
136
|
-
const courseWidth = Math.floor(cols - visualWidth(renderLine('', status, '')));
|
|
137
|
-
if (courseWidth < 3)
|
|
151
|
+
const whole = [
|
|
152
|
+
renderLine(m.courseName, statusText, locationText),
|
|
153
|
+
renderLine(m.courseName, statusText, ''),
|
|
154
|
+
renderLine(m.courseName, compactStatusText, ''),
|
|
155
|
+
].find(fits);
|
|
156
|
+
if (whole)
|
|
157
|
+
return whole;
|
|
158
|
+
for (const status of compactStatusText ? [compactStatusText, ''] : ['']) {
|
|
159
|
+
const courseWidth = Math.floor(width - visualWidth(renderLine('', status, '')));
|
|
160
|
+
if (courseWidth <= visualWidth(ellipsis()))
|
|
138
161
|
continue;
|
|
139
|
-
return renderLine(
|
|
162
|
+
return renderLine(clip(m.courseName, courseWidth), status, '');
|
|
140
163
|
}
|
|
141
164
|
const compactTimeCol = `${marker}${type.hint(startStr)}`;
|
|
142
165
|
for (const indent of [space.indent, '']) {
|
|
143
|
-
const courseWidth = Math.floor(
|
|
144
|
-
if (courseWidth
|
|
166
|
+
const courseWidth = Math.floor(width - visualWidth(renderLine('', '', '', compactTimeCol, indent)));
|
|
167
|
+
if (courseWidth <= visualWidth(ellipsis()))
|
|
145
168
|
continue;
|
|
146
|
-
return renderLine(
|
|
169
|
+
return renderLine(clip(m.courseName, courseWidth), '', '', compactTimeCol, indent);
|
|
147
170
|
}
|
|
148
|
-
const timeOnly = [`${space.indent}${compactTimeCol}`, compactTimeCol, type.hint(startStr)].find(
|
|
171
|
+
const timeOnly = [`${space.indent}${compactTimeCol}`, compactTimeCol, type.hint(startStr)].find(fits);
|
|
149
172
|
if (timeOnly)
|
|
150
173
|
return timeOnly;
|
|
151
|
-
return type.hint(startStr.slice(0, Math.max(0, Math.floor(
|
|
174
|
+
return type.hint(startStr.slice(0, Math.max(0, Math.floor(width))));
|
|
152
175
|
});
|
|
153
176
|
const last = sorted.at(-1);
|
|
154
177
|
if (!last)
|
|
155
178
|
return lines.join('\n');
|
|
156
179
|
const lastEnd = periods.find((p) => p.period === last.endPeriod)?.end ?? '23:59';
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
`${space.indent}${type.hint(lastEnd)}`,
|
|
165
|
-
type.hint(lastEnd),
|
|
166
|
-
].find((candidate) => visualWidth(candidate) <= cols);
|
|
167
|
-
lines.push(compactEnd ?? type.hint(lastEnd.slice(0, Math.max(0, Math.floor(cols)))));
|
|
168
|
-
}
|
|
180
|
+
const endLine = [
|
|
181
|
+
`${space.indent} ${type.hint(lastEnd)} ${rule}${bottomConnector}${rule} ${type.hint(trans.timetable.timelineEnd)}`,
|
|
182
|
+
`${space.indent}${type.hint(lastEnd)} ${rule}${bottomConnector}${rule}`,
|
|
183
|
+
`${space.indent}${type.hint(lastEnd)}`,
|
|
184
|
+
type.hint(lastEnd),
|
|
185
|
+
].find(fits);
|
|
186
|
+
lines.push(endLine ?? type.hint(lastEnd.slice(0, Math.max(0, Math.floor(width)))));
|
|
169
187
|
return lines.join('\n');
|
|
170
188
|
}
|
|
171
189
|
export function renderTodayTimeline(meetings, periods, now, cols = Number.POSITIVE_INFINITY) {
|
|
172
|
-
return renderTimeline(meetings, periods, now, true, false, undefined, cols);
|
|
190
|
+
return renderTimeline(meetings, periods, now, { weekday: 0, isToday: true }, false, undefined, cols);
|
|
173
191
|
}
|
|
174
|
-
export function renderDayTimeline(meetings, periods, now,
|
|
175
|
-
return renderTimeline(meetings, periods, now,
|
|
192
|
+
export function renderDayTimeline(meetings, periods, now, day, cursorPeriod, cols = Number.POSITIVE_INFINITY) {
|
|
193
|
+
return renderTimeline(meetings, periods, now, day, true, cursorPeriod, cols);
|
|
176
194
|
}
|
|
177
195
|
export function renderDaySwitcher(selectedWeekday, todayWeekday, cols = Number.POSITIVE_INFINITY) {
|
|
178
196
|
const leftArrow = pickIcon('←', '<');
|
|
@@ -245,10 +263,13 @@ export function renderWeekGrid(timetable, weekNumber, now, cols = 80, cursor) {
|
|
|
245
263
|
});
|
|
246
264
|
const fixedOverhead = space.indent.length + rowHeadW + 6 * sepW;
|
|
247
265
|
const availableForCols = Math.max(0, cols - fixedOverhead);
|
|
266
|
+
const evenColW = Math.max(...idealColWidths);
|
|
248
267
|
const totalIdealColW = idealColWidths.reduce((a, b) => a + b, 0);
|
|
249
|
-
const colWidths =
|
|
250
|
-
? idealColWidths
|
|
251
|
-
:
|
|
268
|
+
const colWidths = evenColW * 7 <= availableForCols
|
|
269
|
+
? idealColWidths.map(() => evenColW)
|
|
270
|
+
: totalIdealColW <= availableForCols
|
|
271
|
+
? idealColWidths
|
|
272
|
+
: idealColWidths.map((w) => Math.max(3, Math.floor(w * (availableForCols / totalIdealColW))));
|
|
252
273
|
const totalW = rowHeadW + colWidths.reduce((a, b) => a + b, 0) + 6 * sepW;
|
|
253
274
|
const startingAt = (wd, period) => week.find((m) => m.weekday === wd && m.startPeriod === period);
|
|
254
275
|
const continuingAt = (wd, period) => week.find((m) => m.weekday === wd && m.startPeriod < period && period <= m.endPeriod);
|
|
@@ -259,7 +280,7 @@ export function renderWeekGrid(timetable, weekNumber, now, cols = 80, cursor) {
|
|
|
259
280
|
const d = weekdayShortLabel(wd);
|
|
260
281
|
const label = wd === todayWd ? `${d}${todayMark}` : d;
|
|
261
282
|
const colWidth = colWidths[i] ?? 3;
|
|
262
|
-
const padded = centerInWidth(
|
|
283
|
+
const padded = centerInWidth(clip(label, colWidth), colWidth);
|
|
263
284
|
return wd === todayWd ? type.active(padded) : type.hint(padded);
|
|
264
285
|
}).join(sep);
|
|
265
286
|
lines.push(space.indent + blankHead + headerCells);
|
|
@@ -277,11 +298,11 @@ export function renderWeekGrid(timetable, weekNumber, now, cols = 80, cursor) {
|
|
|
277
298
|
const isContinuation = !starting && continuingAt(wd, p.period);
|
|
278
299
|
const rawName = starting ? starting.courseName : isContinuation ? connector : emptyGlyph;
|
|
279
300
|
const rawLoc = starting ? (starting.location ?? '') : isContinuation ? connector : '';
|
|
280
|
-
const paddedName = centerInWidth(
|
|
281
|
-
const paddedLoc = centerInWidth(
|
|
301
|
+
const paddedName = centerInWidth(clip(rawName, colW), colW);
|
|
302
|
+
const paddedLoc = centerInWidth(clip(rawLoc, colW), colW);
|
|
282
303
|
if (isCursor) {
|
|
283
|
-
nameCells.push(type.
|
|
284
|
-
locCells.push(type.
|
|
304
|
+
nameCells.push(type.active(centerInWidth(`[${clip(rawName, colW - 2)}]`, colW)));
|
|
305
|
+
locCells.push(starting ? type.body(paddedLoc) : type.hint(paddedLoc));
|
|
285
306
|
}
|
|
286
307
|
else if (starting) {
|
|
287
308
|
nameCells.push(isToday ? type.active(paddedName) : type.body(paddedName));
|
|
@@ -301,6 +322,68 @@ export function renderWeekGrid(timetable, weekNumber, now, cols = 80, cursor) {
|
|
|
301
322
|
});
|
|
302
323
|
return lines.join('\n');
|
|
303
324
|
}
|
|
325
|
+
export function renderWeekAgenda(timetable, weekNumber, now, cols = Number.POSITIVE_INFINITY, cursor, oneLinePerDay = false) {
|
|
326
|
+
const schedule = createTimetableSchedule(timetable);
|
|
327
|
+
const todayWd = schedule.weekdayAt(now);
|
|
328
|
+
const width = lineBudget(cols);
|
|
329
|
+
const todayMark = pickIcon('•', '*');
|
|
330
|
+
const dot = pickIcon('·', '-');
|
|
331
|
+
const pointer = glyph.cursor();
|
|
332
|
+
const labels = WEEKDAY_KEYS.map((_, i) => `${weekdayShortLabel(i + 1)}${i + 1 === todayWd ? todayMark : ''}`);
|
|
333
|
+
const labelW = Math.max(...labels.map(visualWidth));
|
|
334
|
+
const nameColW = Math.max(0, ...schedule.meetingsInWeek(weekNumber).map((m) => visualWidth(m.courseName)));
|
|
335
|
+
const lines = [];
|
|
336
|
+
WEEKDAY_KEYS.forEach((_, i) => {
|
|
337
|
+
const wd = i + 1;
|
|
338
|
+
const meetings = [...schedule.meetingsOnDay(weekNumber, wd)].sort((a, b) => a.startPeriod - b.startPeriod);
|
|
339
|
+
const isSelected = (m) => cursor?.weekday === wd && m.startPeriod <= cursor.period && cursor.period <= m.endPeriod;
|
|
340
|
+
const selectedIndex = Math.max(0, meetings.findIndex(isSelected));
|
|
341
|
+
const label = padEndV(labels[i] ?? '', labelW);
|
|
342
|
+
const head = (row) => {
|
|
343
|
+
const mark = cursor?.weekday === wd && row === selectedIndex
|
|
344
|
+
? type.active(pointer)
|
|
345
|
+
: ' '.repeat(visualWidth(pointer));
|
|
346
|
+
const day = row > 0 ? ' '.repeat(labelW) : wd === todayWd ? type.active(label) : type.hint(label);
|
|
347
|
+
return `${space.indent}${mark} ${day} `;
|
|
348
|
+
};
|
|
349
|
+
const room = Math.max(1, width - visualWidth(head(0)));
|
|
350
|
+
const nameStyle = (m) => isSelected(m) ? type.active : type.body;
|
|
351
|
+
if (meetings.length === 0) {
|
|
352
|
+
lines.push(`${head(0)}${type.hint(dot)}`);
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
if (oneLinePerDay) {
|
|
356
|
+
let used = 0;
|
|
357
|
+
let text = '';
|
|
358
|
+
for (const [index, m] of meetings.entries()) {
|
|
359
|
+
const sep = index === 0 ? '' : ` ${dot} `;
|
|
360
|
+
const left = room - used - visualWidth(sep);
|
|
361
|
+
if (left < 2) {
|
|
362
|
+
if (used + visualWidth(ellipsis()) + 1 <= room)
|
|
363
|
+
text += ` ${type.hint(ellipsis())}`;
|
|
364
|
+
break;
|
|
365
|
+
}
|
|
366
|
+
const name = clip(m.courseName, left);
|
|
367
|
+
text += `${type.hint(sep)}${nameStyle(m)(name)}`;
|
|
368
|
+
used += visualWidth(sep) + visualWidth(name);
|
|
369
|
+
}
|
|
370
|
+
lines.push(`${head(0)}${text}`);
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
meetings.forEach((m, row) => {
|
|
374
|
+
const start = timetable.periods.find((p) => p.period === m.startPeriod)?.start ?? '';
|
|
375
|
+
const time = `${start} `;
|
|
376
|
+
const nameRoom = room - visualWidth(time);
|
|
377
|
+
const location = m.location ?? '';
|
|
378
|
+
const nameW = [nameColW, visualWidth(m.courseName)].find((w) => w + 3 + visualWidth(location) <= nameRoom);
|
|
379
|
+
const body = location && nameW !== undefined
|
|
380
|
+
? `${nameStyle(m)(padEndV(m.courseName, nameW))} ${type.hint(location)}`
|
|
381
|
+
: nameStyle(m)(clip(m.courseName, Math.max(1, nameRoom)));
|
|
382
|
+
lines.push(`${head(row)}${type.hint(time)}${body}`);
|
|
383
|
+
});
|
|
384
|
+
});
|
|
385
|
+
return lines;
|
|
386
|
+
}
|
|
304
387
|
function formatWeekRange(weeks) {
|
|
305
388
|
if (weeks.length === 0)
|
|
306
389
|
return '';
|
|
@@ -27,44 +27,38 @@ function loadCachedTimetable() {
|
|
|
27
27
|
weekOneMonday: pointer.weekOneMonday,
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
|
-
export function
|
|
30
|
+
export function peekSchedule() {
|
|
31
31
|
try {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
return loadCachedTimetable();
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function scheduleOf(cached) {
|
|
39
|
+
return createTimetableSchedule(cached.timetable, { weekOneMonday: cached.weekOneMonday });
|
|
40
|
+
}
|
|
41
|
+
export function nextClassLine(cached, now = new Date(), cols = Number.POSITIVE_INFINITY) {
|
|
42
|
+
try {
|
|
43
|
+
return renderNextClassBanner(scheduleOf(cached).next(now), now, cols, false);
|
|
39
44
|
}
|
|
40
45
|
catch {
|
|
41
46
|
return '';
|
|
42
47
|
}
|
|
43
48
|
}
|
|
44
|
-
export function
|
|
49
|
+
export function todayLines(cached, now = new Date(), cols = Number.POSITIVE_INFINITY) {
|
|
45
50
|
try {
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const schedule = createTimetableSchedule(cached.timetable, {
|
|
50
|
-
weekOneMonday: cached.weekOneMonday,
|
|
51
|
-
});
|
|
52
|
-
const week = schedule.weekAt(now);
|
|
53
|
-
const today = schedule.meetingsOnDay(week, schedule.weekdayAt(now));
|
|
54
|
-
return renderTodayTimeline(today, cached.timetable.periods, now).split('\n');
|
|
51
|
+
const schedule = scheduleOf(cached);
|
|
52
|
+
const today = schedule.meetingsOnDay(schedule.weekAt(now), schedule.weekdayAt(now));
|
|
53
|
+
return renderTodayTimeline(today, cached.timetable.periods, now, cols).split('\n');
|
|
55
54
|
}
|
|
56
55
|
catch {
|
|
57
56
|
return [];
|
|
58
57
|
}
|
|
59
58
|
}
|
|
60
|
-
export function
|
|
59
|
+
export function weekAheadInfo(cached, now = new Date()) {
|
|
61
60
|
try {
|
|
62
|
-
const
|
|
63
|
-
if (!cached)
|
|
64
|
-
return null;
|
|
65
|
-
const schedule = createTimetableSchedule(cached.timetable, {
|
|
66
|
-
weekOneMonday: cached.weekOneMonday,
|
|
67
|
-
});
|
|
61
|
+
const schedule = scheduleOf(cached);
|
|
68
62
|
const week = schedule.weekAt(now);
|
|
69
63
|
if (week < 1)
|
|
70
64
|
return null;
|
|
@@ -76,11 +70,3 @@ export function peekWeekAheadInfo(now = new Date()) {
|
|
|
76
70
|
return null;
|
|
77
71
|
}
|
|
78
72
|
}
|
|
79
|
-
export function peekUnresolvedCount() {
|
|
80
|
-
try {
|
|
81
|
-
return loadCachedTimetable()?.timetable.unresolvedItems.length ?? 0;
|
|
82
|
-
}
|
|
83
|
-
catch {
|
|
84
|
-
return 0;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
@@ -43,6 +43,8 @@
|
|
|
43
43
|
"settingsDesc": "language · theme · about",
|
|
44
44
|
"chooseAction": "nbtca",
|
|
45
45
|
"hintMove": "move",
|
|
46
|
+
"hintTabs": "switch",
|
|
47
|
+
"hintBack": "back",
|
|
46
48
|
"hintOpen": "open",
|
|
47
49
|
"hintQuit": "quit"
|
|
48
50
|
},
|
|
@@ -81,7 +83,7 @@
|
|
|
81
83
|
"pastLoading": "Loading past events...",
|
|
82
84
|
"pastEvents": "Past Events",
|
|
83
85
|
"pastEventsDesc": "Recent activity history",
|
|
84
|
-
"noPastEvents": "No past events in the last
|
|
86
|
+
"noPastEvents": "No past events in the last year",
|
|
85
87
|
"viewPastDetail": "Select an event for details:",
|
|
86
88
|
"next": "Next",
|
|
87
89
|
"recentActivity": "Coming up",
|
|
@@ -98,7 +100,15 @@
|
|
|
98
100
|
"exportIcs": "Export .ics",
|
|
99
101
|
"exportSuccess": "Saved",
|
|
100
102
|
"exportError": "Could not write the .ics file",
|
|
101
|
-
"recurringLabel": "recurring"
|
|
103
|
+
"recurringLabel": "recurring",
|
|
104
|
+
"searchNoResultsFor": "No events match “{query}”",
|
|
105
|
+
"noEventsInRange": "No events in this period",
|
|
106
|
+
"endedLabel": "ended",
|
|
107
|
+
"duration": {
|
|
108
|
+
"days": "{days}d {hours}h",
|
|
109
|
+
"hours": "{hours}h {minutes}m",
|
|
110
|
+
"minutes": "{minutes}m"
|
|
111
|
+
}
|
|
102
112
|
},
|
|
103
113
|
"docs": {
|
|
104
114
|
"loading": "Loading documentation list...",
|
|
@@ -117,7 +127,7 @@
|
|
|
117
127
|
"cacheCleared": "Documentation cache cleared",
|
|
118
128
|
"stale": "offline, showing last known docs",
|
|
119
129
|
"currentDir": "Current directory",
|
|
120
|
-
"chooseDoc": "Choose a document or directory
|
|
130
|
+
"chooseDoc": "Choose a document or directory",
|
|
121
131
|
"emptyDir": "This directory is empty",
|
|
122
132
|
"upToParent": "Up to parent directory",
|
|
123
133
|
"returnToMenu": "Return to main menu",
|
|
@@ -128,7 +138,7 @@
|
|
|
128
138
|
"errorHint": "Error",
|
|
129
139
|
"openBrowserPrompt": "Open in browser?",
|
|
130
140
|
"docCompleted": "Document loaded successfully",
|
|
131
|
-
"chooseAction": "Choose an action
|
|
141
|
+
"chooseAction": "Choose an action",
|
|
132
142
|
"opening": "Opening browser...",
|
|
133
143
|
"browserOpened": "Knowledge base opened in browser",
|
|
134
144
|
"browserError": "Failed to open browser",
|
|
@@ -142,7 +152,7 @@
|
|
|
142
152
|
"githubTokenHint": "Tip: set GITHUB_TOKEN for a higher rate limit.",
|
|
143
153
|
"fetchDirFailed": "Failed to fetch directory: {error}",
|
|
144
154
|
"fetchFileFailed": "Failed to fetch file: {error}",
|
|
145
|
-
"searchPrompt": "Search documents
|
|
155
|
+
"searchPrompt": "Search documents",
|
|
146
156
|
"searchPlaceholder": "Enter keyword...",
|
|
147
157
|
"searching": "Searching documents...",
|
|
148
158
|
"searchResults": "results found",
|
|
@@ -288,7 +298,7 @@
|
|
|
288
298
|
"todayHeading": "Today · {weekday} · Week {week}",
|
|
289
299
|
"classDone": "Done",
|
|
290
300
|
"classLive": "In progress",
|
|
291
|
-
"minutesRemaining": "{minutes}
|
|
301
|
+
"minutesRemaining": "{minutes} min left",
|
|
292
302
|
"timelineEnd": "End of day",
|
|
293
303
|
"termNotStarted": "Term hasn't started yet",
|
|
294
304
|
"termStartsIn": "Classes begin {date} · {days} days to go",
|
|
@@ -298,21 +308,32 @@
|
|
|
298
308
|
"weekOverviewTitle": "Week overview",
|
|
299
309
|
"weekAheadClasses": "Classes",
|
|
300
310
|
"weekAheadBusy": "Busy",
|
|
301
|
-
"weekAheadFree": "
|
|
302
|
-
"weekAheadNone": "
|
|
311
|
+
"weekAheadFree": "Light",
|
|
312
|
+
"weekAheadNone": "None",
|
|
303
313
|
"termPreviewWeek": "Week 1 preview",
|
|
304
314
|
"hubFullGrid": "Full grid",
|
|
305
315
|
"detailTime": "Time",
|
|
306
316
|
"detailLocation": "Location",
|
|
307
317
|
"detailTeacher": "Teacher",
|
|
308
318
|
"detailWeeks": "Weeks",
|
|
309
|
-
"teacherSeparator": ", "
|
|
319
|
+
"teacherSeparator": ", ",
|
|
320
|
+
"noClassOnDay": "No classes on {weekday}",
|
|
321
|
+
"countdownDays": "in {days}d {hours}h",
|
|
322
|
+
"countdownHours": "in {hours}h {minutes}m",
|
|
323
|
+
"countdownMinutes": "in {minutes}m",
|
|
324
|
+
"weekTooSmall": "Too small for the whole week; showing one day",
|
|
325
|
+
"termPickerNeedsLogin": "Log in to the school system to switch terms.",
|
|
326
|
+
"termPickerLoginAction": "Log in",
|
|
327
|
+
"homeLoginCta": "Open {tab} and choose “{action}” to see your classes here.",
|
|
328
|
+
"helpSwitchDay": "Switch day",
|
|
329
|
+
"helpPickClass": "Pick a class",
|
|
330
|
+
"helpOpenClass": "Class details",
|
|
331
|
+
"footerDay": "day",
|
|
332
|
+
"footerClass": "class",
|
|
333
|
+
"footerDetail": "details"
|
|
310
334
|
},
|
|
311
335
|
"theme": {
|
|
312
336
|
"current": "Current theme settings",
|
|
313
|
-
"chooseAction": "Settings",
|
|
314
|
-
"chooseIconMode": "Choose icon mode:",
|
|
315
|
-
"chooseColorMode": "Choose color mode:",
|
|
316
337
|
"modeAuto": "Auto",
|
|
317
338
|
"modeAscii": "ASCII",
|
|
318
339
|
"modeUnicode": "Unicode",
|
|
@@ -43,6 +43,8 @@
|
|
|
43
43
|
"settingsDesc": "语言 · 主题 · 关于",
|
|
44
44
|
"chooseAction": "nbtca",
|
|
45
45
|
"hintMove": "移动",
|
|
46
|
+
"hintTabs": "切换",
|
|
47
|
+
"hintBack": "返回",
|
|
46
48
|
"hintOpen": "打开",
|
|
47
49
|
"hintQuit": "退出"
|
|
48
50
|
},
|
|
@@ -81,7 +83,7 @@
|
|
|
81
83
|
"pastLoading": "正在加载历史活动...",
|
|
82
84
|
"pastEvents": "历史活动",
|
|
83
85
|
"pastEventsDesc": "近期活动记录",
|
|
84
|
-
"noPastEvents": "
|
|
86
|
+
"noPastEvents": "近一年没有已结束的活动",
|
|
85
87
|
"viewPastDetail": "选择活动查看详情:",
|
|
86
88
|
"next": "下一场",
|
|
87
89
|
"recentActivity": "近期安排",
|
|
@@ -98,7 +100,15 @@
|
|
|
98
100
|
"exportIcs": "导出 .ics",
|
|
99
101
|
"exportSuccess": "已保存",
|
|
100
102
|
"exportError": "无法写入 .ics 文件",
|
|
101
|
-
"recurringLabel": "循环"
|
|
103
|
+
"recurringLabel": "循环",
|
|
104
|
+
"searchNoResultsFor": "没有找到与“{query}”相关的活动",
|
|
105
|
+
"noEventsInRange": "这段时间没有活动安排",
|
|
106
|
+
"endedLabel": "已结束",
|
|
107
|
+
"duration": {
|
|
108
|
+
"days": "{days} 天 {hours} 小时",
|
|
109
|
+
"hours": "{hours} 小时 {minutes} 分钟",
|
|
110
|
+
"minutes": "{minutes} 分钟"
|
|
111
|
+
}
|
|
102
112
|
},
|
|
103
113
|
"docs": {
|
|
104
114
|
"loading": "正在加载文档列表...",
|
|
@@ -117,7 +127,7 @@
|
|
|
117
127
|
"cacheCleared": "文档缓存已清除",
|
|
118
128
|
"stale": "离线,显示上次获取的文档",
|
|
119
129
|
"currentDir": "当前目录",
|
|
120
|
-
"chooseDoc": "
|
|
130
|
+
"chooseDoc": "选择文档或目录",
|
|
121
131
|
"emptyDir": "该目录为空",
|
|
122
132
|
"upToParent": "返回上级目录",
|
|
123
133
|
"returnToMenu": "返回主菜单",
|
|
@@ -128,7 +138,7 @@
|
|
|
128
138
|
"errorHint": "错误",
|
|
129
139
|
"openBrowserPrompt": "是否在浏览器中打开?",
|
|
130
140
|
"docCompleted": "文档加载完成",
|
|
131
|
-
"chooseAction": "
|
|
141
|
+
"chooseAction": "选择操作",
|
|
132
142
|
"opening": "正在打开浏览器...",
|
|
133
143
|
"browserOpened": "已在浏览器中打开知识库",
|
|
134
144
|
"browserError": "无法打开浏览器",
|
|
@@ -142,7 +152,7 @@
|
|
|
142
152
|
"githubTokenHint": "提示: 设置 GITHUB_TOKEN 环境变量可获得更高的速率限制。",
|
|
143
153
|
"fetchDirFailed": "无法获取目录内容: {error}",
|
|
144
154
|
"fetchFileFailed": "无法获取文件内容: {error}",
|
|
145
|
-
"searchPrompt": "
|
|
155
|
+
"searchPrompt": "搜索文档",
|
|
146
156
|
"searchPlaceholder": "输入关键词...",
|
|
147
157
|
"searching": "正在搜索文档...",
|
|
148
158
|
"searchResults": "个结果",
|
|
@@ -299,20 +309,31 @@
|
|
|
299
309
|
"weekAheadClasses": "课程",
|
|
300
310
|
"weekAheadBusy": "较满",
|
|
301
311
|
"weekAheadFree": "较空",
|
|
302
|
-
"weekAheadNone": "
|
|
312
|
+
"weekAheadNone": "无安排",
|
|
303
313
|
"termPreviewWeek": "第一周预览",
|
|
304
314
|
"hubFullGrid": "完整课表",
|
|
305
315
|
"detailTime": "时间",
|
|
306
316
|
"detailLocation": "地点",
|
|
307
317
|
"detailTeacher": "教师",
|
|
308
318
|
"detailWeeks": "周次",
|
|
309
|
-
"teacherSeparator": "、"
|
|
319
|
+
"teacherSeparator": "、",
|
|
320
|
+
"noClassOnDay": "{weekday}没有课",
|
|
321
|
+
"countdownDays": "{days} 天 {hours} 小时后",
|
|
322
|
+
"countdownHours": "{hours} 小时 {minutes} 分钟后",
|
|
323
|
+
"countdownMinutes": "{minutes} 分钟后",
|
|
324
|
+
"weekTooSmall": "窗口太小,放不下整周课表,先按天显示",
|
|
325
|
+
"termPickerNeedsLogin": "切换学期需要先登录教务系统。",
|
|
326
|
+
"termPickerLoginAction": "登录教务系统",
|
|
327
|
+
"homeLoginCta": "到{tab}页选择“{action}”,这里就会显示你的课程。",
|
|
328
|
+
"helpSwitchDay": "切换星期",
|
|
329
|
+
"helpPickClass": "选择课程",
|
|
330
|
+
"helpOpenClass": "查看课程详情",
|
|
331
|
+
"footerDay": "星期",
|
|
332
|
+
"footerClass": "课程",
|
|
333
|
+
"footerDetail": "详情"
|
|
310
334
|
},
|
|
311
335
|
"theme": {
|
|
312
336
|
"current": "当前主题设置",
|
|
313
|
-
"chooseAction": "设置",
|
|
314
|
-
"chooseIconMode": "选择图标模式:",
|
|
315
|
-
"chooseColorMode": "选择颜色模式:",
|
|
316
337
|
"modeAuto": "自动",
|
|
317
338
|
"modeAscii": "ASCII",
|
|
318
339
|
"modeUnicode": "Unicode",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nbtca/prompt",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.15",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -49,11 +49,7 @@
|
|
|
49
49
|
"@nbtca/docs": "^0.3.2",
|
|
50
50
|
"@nbtca/nbtcal": "^0.4.2",
|
|
51
51
|
"chalk": "^5.6.2",
|
|
52
|
-
"
|
|
53
|
-
"gradient-string": "^3.0.0",
|
|
54
|
-
"marked": "^15.0.12",
|
|
55
|
-
"open": "^11.0.0",
|
|
56
|
-
"tough-cookie": "^6.0.2"
|
|
52
|
+
"marked": "^15.0.12"
|
|
57
53
|
},
|
|
58
54
|
"devDependencies": {
|
|
59
55
|
"@eslint/js": "^9.39.5",
|