@nbtca/prompt 1.5.23 → 1.6.0

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.
@@ -9,6 +9,11 @@ import { ListField, computeMaxVisible, renderListFieldWithContext } from '../fie
9
9
  import { TextField } from '../fields/text-field.js';
10
10
  import { fitFooterHint, passiveFooterHint } from '../chrome.js';
11
11
  import { renderStudentRecordsPanel, renderStudentRecordDetail, visibleStudentRecords, } from './student-records-render.js';
12
+ import { markGradeSeen, sealedGrades } from '../../features/grade-seen.js';
13
+ import { termKey } from '../../features/schedule-store.js';
14
+ import { getCapabilities } from '../../core/capabilities.js';
15
+ const REVEAL_MS = 900;
16
+ const REVEAL_FRAME_MS = 60;
12
17
  export class StudentRecordsPanel {
13
18
  kind;
14
19
  term;
@@ -29,6 +34,8 @@ export class StudentRecordsPanel {
29
34
  controller;
30
35
  pending = false;
31
36
  results = new Map();
37
+ sealed = new Set();
38
+ reveal;
32
39
  constructor(kind, term, catalog, transport, isActive, onSessionExpired) {
33
40
  this.kind = kind;
34
41
  this.term = term;
@@ -58,6 +65,8 @@ export class StudentRecordsPanel {
58
65
  return;
59
66
  this.data = data;
60
67
  this.results.set(data.kind, data);
68
+ if (data.kind === 'grades')
69
+ this.sealed = sealedGrades(this.termKey(), data.items);
61
70
  const next = data.kind === 'exams'
62
71
  ? data.items.findIndex((exam) => exam.start && exam.end && exam.end > new Date())
63
72
  : -1;
@@ -88,7 +97,15 @@ export class StudentRecordsPanel {
88
97
  setVimKeysActive(true);
89
98
  }
90
99
  isBusy() {
91
- return this.pending;
100
+ return this.pending || this.revealProgress() < 1;
101
+ }
102
+ termKey() {
103
+ return termKey(this.term);
104
+ }
105
+ revealProgress() {
106
+ if (!this.reveal || getCapabilities().reducedMotion)
107
+ return 1;
108
+ return Math.min(1, (Date.now() - this.reveal.at) / REVEAL_MS);
92
109
  }
93
110
  capturesInput() {
94
111
  return this.searchField !== undefined;
@@ -129,6 +146,7 @@ export class StudentRecordsPanel {
129
146
  }
130
147
  if (this.detailIndex !== undefined) {
131
148
  this.detailIndex = undefined;
149
+ this.reveal = undefined;
132
150
  return true;
133
151
  }
134
152
  if (this.query || this.attention) {
@@ -182,7 +200,15 @@ export class StudentRecordsPanel {
182
200
  return [
183
201
  ...wrapAnsiWithIndent(type.hint(t().records.detailHint), ctx.size.cols, space.indent),
184
202
  '',
185
- ...renderStudentRecordDetail(this.data, index, Math.max(1, ctx.size.cols - 6), new Date()).map((line) => space.indent + line),
203
+ ...renderStudentRecordDetail(this.data, index, Math.max(1, ctx.size.cols - 6), new Date(), this.reveal?.index === index
204
+ ? {
205
+ sealed: false,
206
+ reveal: {
207
+ progress: this.revealProgress(),
208
+ frame: Math.floor((Date.now() - this.reveal.at) / REVEAL_FRAME_MS),
209
+ },
210
+ }
211
+ : { sealed: false }).map((line) => space.indent + line),
186
212
  ];
187
213
  }
188
214
  const rendered = renderStudentRecordsPanel({
@@ -195,6 +221,7 @@ export class StudentRecordsPanel {
195
221
  query: this.query,
196
222
  attention: this.attention,
197
223
  searching: this.searchField !== undefined,
224
+ sealed: this.kind === 'grades' ? this.sealed : new Set(),
198
225
  }, ctx.bodyRows, ctx.size.cols, new Date());
199
226
  this.pageSize = rendered.pageSize;
200
227
  return rendered.lines;
@@ -302,7 +329,13 @@ export class StudentRecordsPanel {
302
329
  if (key === '\x1b[F')
303
330
  this.selected = last;
304
331
  if ((key === '\r' || key === '\n') && count > 0) {
305
- this.detailIndex = this.indices()[this.selected];
332
+ const index = this.indices()[this.selected];
333
+ this.detailIndex = index;
334
+ const grade = index === undefined || this.data?.kind !== 'grades' ? undefined : this.data.items[index];
335
+ if (index !== undefined && grade && this.sealed.delete(index)) {
336
+ this.reveal = { index, at: Date.now() };
337
+ markGradeSeen(this.termKey(), grade);
338
+ }
306
339
  ctx.resetScroll();
307
340
  }
308
341
  }
@@ -0,0 +1,92 @@
1
+ import { numeralLines } from '../../art/numerals.js';
2
+ import { useUnicodeIcons } from '../../core/icons.js';
3
+ import { visualWidth, wrapAnsiWithIndent } from '../../core/text.js';
4
+ import { bodyEdge, glyph, space, type } from '../../core/theme.js';
5
+ import { fmt, getCurrentLanguage, t } from '../../i18n/index.js';
6
+ export const COUNT_UP_MS = 700;
7
+ const FILM_HOURS = 2;
8
+ function dayLabel(iso) {
9
+ return new Date(`${iso}T00:00:00Z`).toLocaleDateString(getCurrentLanguage() === 'zh' ? 'zh-CN' : 'en-US', { month: 'long', day: 'numeric', timeZone: 'UTC' });
10
+ }
11
+ export function recapCards(recap) {
12
+ const trans = t().recap;
13
+ const cards = [
14
+ {
15
+ lead: recap.finished ? trans.classesLead : trans.classesLeadSoFar,
16
+ value: recap.classes,
17
+ unit: trans.classesUnit,
18
+ detail: fmt(trans.classesDetail, {
19
+ hours: recap.hours,
20
+ courses: recap.courses,
21
+ weeks: recap.weeks,
22
+ }),
23
+ },
24
+ {
25
+ lead: trans.earlyLead,
26
+ value: recap.earlyClasses,
27
+ unit: trans.earlyUnit,
28
+ detail: recap.earlyClasses > 0 ? trans.earlyDetail : trans.earlyNone,
29
+ },
30
+ ];
31
+ if (recap.busiestDay) {
32
+ cards.push({
33
+ lead: fmt(trans.busiestLead, { date: dayLabel(recap.busiestDay.date) }),
34
+ value: recap.busiestDay.classes,
35
+ unit: trans.classesUnit,
36
+ detail: fmt(trans.busiestDetail, recap.busiestDay),
37
+ });
38
+ }
39
+ if (recap.topCourse) {
40
+ const films = Math.floor(recap.topCourse.hours / FILM_HOURS);
41
+ cards.push({
42
+ lead: fmt(trans.topLead, { course: recap.topCourse.name }),
43
+ value: Math.round(recap.topCourse.hours),
44
+ unit: trans.hoursUnit,
45
+ ...(films > 0 ? { detail: fmt(trans.topDetail, { films }) } : {}),
46
+ });
47
+ }
48
+ if (recap.favoriteRoom) {
49
+ cards.push({
50
+ lead: fmt(trans.roomLead, { room: recap.favoriteRoom.name }),
51
+ value: recap.favoriteRoom.visits,
52
+ unit: trans.roomUnit,
53
+ detail: trans.roomDetail,
54
+ });
55
+ }
56
+ if (recap.events) {
57
+ cards.push({
58
+ lead: trans.eventsLead,
59
+ value: recap.events,
60
+ unit: trans.eventsUnit,
61
+ detail: trans.eventsDetail,
62
+ });
63
+ }
64
+ cards.push({ lead: recap.finished ? trans.outro : trans.outroSoFar });
65
+ return cards;
66
+ }
67
+ const easeOut = (x) => 1 - (1 - x) ** 3;
68
+ function numberLines(value, unit, cols) {
69
+ const big = numeralLines(String(value), useUnicodeIcons());
70
+ const tail = ` ${type.body(unit)}`;
71
+ const fits = visualWidth(space.indent) + (big[0] ? visualWidth(big[0]) : 0) + visualWidth(tail);
72
+ if (fits > bodyEdge(cols))
73
+ return [`${space.indent}${type.active(String(value))}${tail}`];
74
+ return big.map((line, row) => `${space.indent}${type.active(line)}${row === 1 ? tail : ''}`);
75
+ }
76
+ export function renderRecapCard(cards, index, heading, elapsedMs, cols) {
77
+ const card = cards[index];
78
+ if (!card)
79
+ return [];
80
+ const wrap = (text, style) => wrapAnsiWithIndent(style(text), cols, space.indent);
81
+ const lines = [...wrap(heading, type.heading), '', ...wrap(card.lead, type.body), ''];
82
+ if (card.value !== undefined) {
83
+ const shown = Math.round(card.value * easeOut(Math.min(1, elapsedMs / COUNT_UP_MS)));
84
+ lines.push(...numberLines(shown, card.unit ?? '', cols), '');
85
+ }
86
+ if (card.detail)
87
+ lines.push(...wrap(card.detail, type.hint), '');
88
+ const empty = useUnicodeIcons() ? '○' : '.';
89
+ const dots = cards.map((_, i) => (i === index ? glyph.dot() : empty)).join(' ');
90
+ lines.push(`${space.indent}${type.hint(dots)}`);
91
+ return lines;
92
+ }
@@ -0,0 +1,111 @@
1
+ // Indexed by the sun's ecliptic longitude in 15° steps, starting at the spring equinox.
2
+ const SOLAR_TERMS = [
3
+ 'chunfen',
4
+ 'qingming',
5
+ 'guyu',
6
+ 'lixia',
7
+ 'xiaoman',
8
+ 'mangzhong',
9
+ 'xiazhi',
10
+ 'xiaoshu',
11
+ 'dashu',
12
+ 'liqiu',
13
+ 'chushu',
14
+ 'bailu',
15
+ 'qiufen',
16
+ 'hanlu',
17
+ 'shuangjiang',
18
+ 'lidong',
19
+ 'xiaoxue',
20
+ 'daxue',
21
+ 'dongzhi',
22
+ 'xiaohan',
23
+ 'dahan',
24
+ 'lichun',
25
+ 'yushui',
26
+ 'jingzhe',
27
+ ];
28
+ const TERM_WEATHER = {
29
+ yushui: 'rain',
30
+ qingming: 'rain',
31
+ guyu: 'rain',
32
+ xiaoxue: 'snow',
33
+ daxue: 'snow',
34
+ dongzhi: 'snow',
35
+ xiaohan: 'snow',
36
+ dahan: 'snow',
37
+ };
38
+ const RAD = Math.PI / 180;
39
+ const J2000 = Date.UTC(2000, 0, 1, 12);
40
+ /** The sun's apparent ecliptic longitude in degrees, from the low-precision formula in the Astronomical Almanac. */
41
+ function solarLongitude(at) {
42
+ const n = (at - J2000) / 86_400_000;
43
+ const mean = 280.46 + 0.9856474 * n;
44
+ const anomaly = (357.528 + 0.9856003 * n) * RAD;
45
+ const longitude = mean + 1.915 * Math.sin(anomaly) + 0.02 * Math.sin(2 * anomaly);
46
+ return ((longitude % 360) + 360) % 360;
47
+ }
48
+ const CAMPUS_OFFSET_MS = 8 * 3_600_000;
49
+ // Terms are published for the campus calendar day, so the day starts at campus midnight in every time zone.
50
+ function solarTerm(date) {
51
+ const start = Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()) - CAMPUS_OFFSET_MS;
52
+ const before = Math.floor(solarLongitude(start) / 15);
53
+ const after = Math.floor(solarLongitude(start + 86_400_000) / 15);
54
+ return before === after ? undefined : SOLAR_TERMS[after % 24];
55
+ }
56
+ const LUNAR = new Intl.DateTimeFormat('en-u-ca-chinese', { month: 'numeric', day: 'numeric' });
57
+ // ICU's lunar calendar puts some new years a day late (2027, 2030) when the new moon falls near midnight.
58
+ const SPRING_FESTIVAL = {
59
+ 2021: '02-12',
60
+ 2022: '02-01',
61
+ 2023: '01-22',
62
+ 2024: '02-10',
63
+ 2025: '01-29',
64
+ 2026: '02-17',
65
+ 2027: '02-06',
66
+ 2028: '01-26',
67
+ 2029: '02-13',
68
+ 2030: '02-03',
69
+ 2031: '01-23',
70
+ };
71
+ function lunarDay(date) {
72
+ const parts = LUNAR.formatToParts(date);
73
+ const value = (type) => parts.find((part) => part.type === type)?.value;
74
+ return `${value('month')}/${value('day')}`;
75
+ }
76
+ function daysFromSpringFestival(date) {
77
+ const known = SPRING_FESTIVAL[date.getFullYear()];
78
+ const day = Date.UTC(date.getFullYear(), date.getMonth(), date.getDate());
79
+ if (known)
80
+ return (day - Date.parse(`${date.getFullYear()}-${known}T00:00:00Z`)) / 86_400_000;
81
+ for (const offset of [-1, 0, 14]) {
82
+ if (lunarDay(new Date(date.getFullYear(), date.getMonth(), date.getDate() - offset)) === '1/1')
83
+ return offset;
84
+ }
85
+ return undefined;
86
+ }
87
+ function festival(date) {
88
+ if (date.getMonth() === 0 && date.getDate() === 1)
89
+ return { name: 'newYear', weather: 'fireworks' };
90
+ const offset = daysFromSpringFestival(date);
91
+ if (offset === -1)
92
+ return { name: 'newYearsEve', weather: 'fireworks' };
93
+ if (offset === 0)
94
+ return { name: 'springFestival', weather: 'fireworks' };
95
+ if (offset === 14)
96
+ return { name: 'lanternFestival', weather: 'lanterns' };
97
+ if (lunarDay(date) === '8/15')
98
+ return { name: 'midAutumn', weather: 'lanterns' };
99
+ return undefined;
100
+ }
101
+ /** A festival, or else a solar term, that falls on the local calendar day of `date`. */
102
+ export function occasion(date) {
103
+ const holiday = festival(date);
104
+ if (holiday)
105
+ return holiday;
106
+ const term = solarTerm(date);
107
+ if (!term)
108
+ return undefined;
109
+ const weather = TERM_WEATHER[term];
110
+ return weather ? { name: term, weather } : { name: term };
111
+ }
@@ -0,0 +1,34 @@
1
+ const FONT = {
2
+ '0': ['###', '# #', '# #', '# #', '###'],
3
+ '1': [' # ', '## ', ' # ', ' # ', '###'],
4
+ '2': ['###', ' #', '###', '# ', '###'],
5
+ '3': ['###', ' #', ' ##', ' #', '###'],
6
+ '4': ['# #', '# #', '###', ' #', ' #'],
7
+ '5': ['###', '# ', '###', ' #', '###'],
8
+ '6': ['###', '# ', '###', '# #', '###'],
9
+ '7': ['###', ' #', ' # ', ' # ', ' # '],
10
+ '8': ['###', '# #', '###', '# #', '###'],
11
+ '9': ['###', '# #', '###', ' #', '###'],
12
+ '.': [' ', ' ', ' ', ' ', ' # '],
13
+ ':': [' ', ' # ', ' ', ' # ', ' '],
14
+ };
15
+ const HALVES = { unicode: [' ', '▀', '▄', '█'], ascii: [' ', '"', '_', '#'] };
16
+ /** Draws digits three rows tall by pairing the five pixel rows into half-block cells. */
17
+ export function numeralLines(text, unicode) {
18
+ const glyphs = Array.from(text, (ch) => FONT[ch]).filter((rows) => rows !== undefined);
19
+ const halves = unicode ? HALVES.unicode : HALVES.ascii;
20
+ const lines = [];
21
+ for (let row = 0; row < 5; row += 2) {
22
+ const cells = glyphs.map((rows) => {
23
+ let cell = '';
24
+ for (let x = 0; x < 3; x++) {
25
+ const top = rows[row]?.charAt(x) === '#' ? 1 : 0;
26
+ const bottom = rows[row + 1]?.charAt(x) === '#' ? 2 : 0;
27
+ cell += halves[top + bottom] ?? ' ';
28
+ }
29
+ return cell;
30
+ });
31
+ lines.push(cells.join(' '));
32
+ }
33
+ return lines;
34
+ }
package/dist/art/scene.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { solarHour } from './sun.js';
2
+ import { occasion } from './almanac.js';
1
3
  const ASCII_SYMBOLS = Array.from({ length: 94 }, (_, index) => String.fromCharCode(0x21 + index));
2
4
  const FINE = { x: 2, y: 4 };
3
5
  function hexToRgb(hex) {
@@ -6,13 +8,13 @@ function hexToRgb(hex) {
6
8
  function rgbToHex(rgb) {
7
9
  return `#${rgb.map((value) => Math.round(value).toString(16).padStart(2, '0')).join('')}`;
8
10
  }
9
- function mix(from, to, amount) {
11
+ export function mix(from, to, amount) {
10
12
  const a = hexToRgb(from);
11
13
  const b = hexToRgb(to);
12
14
  const t = Math.min(1, Math.max(0, amount));
13
15
  return rgbToHex([0, 1, 2].map((index) => (a[index] ?? 0) + ((b[index] ?? 0) - (a[index] ?? 0)) * t));
14
16
  }
15
- class Canvas {
17
+ export class Canvas {
16
18
  width;
17
19
  height;
18
20
  cells;
@@ -105,7 +107,7 @@ class Canvas {
105
107
  return { palette, rows, density: FINE, smooth: true };
106
108
  }
107
109
  }
108
- function random(seed) {
110
+ export function random(seed) {
109
111
  let state = seed;
110
112
  return () => (state = (state * 16807) % 2147483647) / 2147483647;
111
113
  }
@@ -282,9 +284,101 @@ function drawShore(c, horizon, hour, rand) {
282
284
  c.rect(boatX - 1, boatY, boatX + size, boatY + 1, shade);
283
285
  c.rect(0, c.height - 3, c.width - 1, c.height - 1, shade);
284
286
  }
285
- /** A seascape whose sky, sun or moon (with its real phase), stars, city, and lighthouse follow the time. */
287
+ const BURST_COLORS = ['#ff6b6b', '#ffd166', '#7bdff2', '#f7a1ff', '#b8f2a6'];
288
+ function drawWeather(c, horizon, hour, weather, rand) {
289
+ if (weather === 'rain' || weather === 'snow') {
290
+ const [cloud, amount] = weather === 'rain' ? ['#5b6577', 0.4] : ['#9aa6b8', 0.45];
291
+ for (let y = 0; y < c.height; y++) {
292
+ for (let x = 0; x < c.width; x++) {
293
+ const cell = c.get(x, y);
294
+ if (cell !== null)
295
+ c.set(x, y, mix(cell, cloud, amount * (y < horizon ? 1 : 0.6)));
296
+ }
297
+ }
298
+ }
299
+ if (weather === 'rain') {
300
+ const drops = Math.round(c.width * c.height * 0.006);
301
+ for (let index = 0; index < drops; index++) {
302
+ const x = rand() * c.width;
303
+ const y = rand() * c.height;
304
+ c.line(x, y, x - 1, y + 3, mix(c.get(x, y) ?? '#5b6577', '#c9d4e6', 0.45));
305
+ }
306
+ return;
307
+ }
308
+ if (weather === 'snow') {
309
+ const flakes = Math.round(c.width * c.height * 0.004);
310
+ for (let index = 0; index < flakes; index++) {
311
+ const x = rand() * c.width;
312
+ const y = rand() * (c.height - 3);
313
+ c.set(x, y, rand() > 0.3 ? '#f4f7ff' : '#c7d4ef');
314
+ if (rand() > 0.85)
315
+ c.set(x + 1, y, '#dfe8ff');
316
+ }
317
+ return;
318
+ }
319
+ if (!isDark(hour))
320
+ return;
321
+ if (weather === 'fireworks') {
322
+ const bursts = Math.max(2, Math.round(c.width / 70));
323
+ for (let index = 0; index < bursts; index++) {
324
+ const cx = c.width * (0.12 + 0.76 * rand());
325
+ const cy = horizon * (0.18 + 0.35 * rand());
326
+ const radius = Math.max(4, horizon * (0.12 + 0.08 * rand()));
327
+ const color = BURST_COLORS[index % BURST_COLORS.length] ?? '#ffd166';
328
+ const spokes = 14;
329
+ for (let spoke = 0; spoke < spokes; spoke++) {
330
+ const angle = (2 * Math.PI * spoke) / spokes + rand() * 0.2;
331
+ for (let step = radius * 0.3; step <= radius; step += 1) {
332
+ const x = cx + Math.cos(angle) * step;
333
+ const y = cy + Math.sin(angle) * step * 0.9;
334
+ const cell = c.get(x, y);
335
+ if (cell !== null)
336
+ c.set(x, y, mix(cell, color, 0.25 + 0.75 * (step / radius) ** 2));
337
+ }
338
+ }
339
+ c.line(cx, cy + radius * 0.4, cx + rand() * 2 - 1, horizon - 1, mix(color, '#0b1a3a', 0.6));
340
+ }
341
+ return;
342
+ }
343
+ const lanterns = Math.max(3, Math.round(c.width / 30));
344
+ for (let index = 0; index < lanterns; index++) {
345
+ const x = c.width * (0.08 + 0.84 * rand());
346
+ const y = horizon * (0.25 + 0.6 * rand());
347
+ const size = Math.max(1.5, c.height * 0.018 * (0.6 + rand()));
348
+ c.blob(x, y, size * 3, size * 3, (px, py, edge) => mix(c.get(px, py) ?? '#0b1a3a', '#ff9f43', 0.35 * (1 - edge) ** 2));
349
+ c.blob(x, y, size, size * 1.3, (_px, _py, edge) => mix('#ffe08a', '#ff7a1a', edge));
350
+ const glint = horizon + (horizon - y) * 0.25;
351
+ if (glint < c.height - 3)
352
+ c.rect(x - 1, glint, x + 1, glint, '#ffb35c');
353
+ }
354
+ }
355
+ const OWL = [' 1 1 ', '1111111', '1211121', '1113111', '1111111', ' 11111 ', ' 4 4 '];
356
+ const OWL_COLORS = {
357
+ '1': '#3a3550',
358
+ '2': '#ffd166',
359
+ '3': '#c08a3a',
360
+ '4': '#8a6a3a',
361
+ };
362
+ /** Between 01:00 and 05:00 on the viewer's clock, when anyone still at the terminal should be asleep. */
363
+ export function isOwlHour(now) {
364
+ const hour = now.getHours();
365
+ return hour >= 1 && hour < 5;
366
+ }
367
+ function drawOwl(c, horizon) {
368
+ const scale = Math.max(1, Math.round(c.height / 56));
369
+ const left = Math.round(c.width * 0.1) - Math.floor((OWL[0]?.length ?? 0) * scale * 0.5);
370
+ const top = horizon - Math.round(horizon * 0.3) - OWL.length * scale + 1;
371
+ OWL.forEach((row, y) => {
372
+ for (let x = 0; x < row.length; x++) {
373
+ const color = OWL_COLORS[row.charAt(x)];
374
+ if (color)
375
+ c.rect(left + x * scale, top + y * scale, left + (x + 1) * scale - 1, top + (y + 1) * scale - 1, color);
376
+ }
377
+ });
378
+ }
379
+ /** A seascape whose sky, sun or moon (with its real phase), stars, city, and lighthouse follow the campus sun. */
286
380
  export function skyScene(width, height, now) {
287
- const hour = now.getHours() + now.getMinutes() / 60;
381
+ const hour = solarHour(now);
288
382
  const c = new Canvas(width, height);
289
383
  const horizon = Math.round(height * 0.62);
290
384
  const rand = random(11);
@@ -292,6 +386,11 @@ export function skyScene(width, height, now) {
292
386
  const body = drawBody(c, horizon, hour, now);
293
387
  drawSea(c, horizon, hour, rand, body);
294
388
  drawShore(c, horizon, hour, rand);
389
+ const weather = occasion(now)?.weather;
390
+ if (weather)
391
+ drawWeather(c, horizon, hour, weather, random(29));
392
+ if (isOwlHour(now))
393
+ drawOwl(c, horizon);
295
394
  return c.toBitmap();
296
395
  }
297
396
  /** Ridges with a trail and a flag that climbs it as `progress` goes from 0 to 1, one tick per week. */
@@ -0,0 +1,82 @@
1
+ import { fbm3 } from './noise.js';
2
+ import { Canvas, mix, random } from './scene.js';
3
+ export const STAR_COLORS = {
4
+ repair: '#fbbf24',
5
+ workshop: '#5eead4',
6
+ conference: '#c4b5fd',
7
+ meeting: '#93c5fd',
8
+ birthday: '#f9a8d4',
9
+ other: '#f1f5f9',
10
+ };
11
+ const YEAR_MS = 365 * 86_400_000;
12
+ const CONSTELLATION_GAP_MS = 45 * 86_400_000;
13
+ const CONSTELLATION_SIZE = 5;
14
+ /** The past year as a night sky: one star per event, left to right in time, with events of a kind joined into constellations. */
15
+ export function starMapScene(width, height, stars, now) {
16
+ const c = new Canvas(width, height);
17
+ const rand = random(7);
18
+ for (let y = 0; y < height; y++) {
19
+ for (let x = 0; x < width; x++) {
20
+ const base = mix('#050b1e', '#13234a', y / height);
21
+ const band = Math.exp(-(((y / height - 0.75 + (x / width) * 0.5) / 0.18) ** 2));
22
+ const dust = fbm3([x / 18, y / 9, 0.5], 3, 3);
23
+ c.set(x, y, mix(base, '#3b4f8a', band * dust * 0.55));
24
+ }
25
+ }
26
+ for (let index = 0; index < width * height * 0.004; index++) {
27
+ c.set(rand() * width, rand() * height, rand() > 0.5 ? '#4a5a85' : '#6b7aa6');
28
+ }
29
+ const start = now.getTime() - YEAR_MS;
30
+ const unit = (seed) => (((seed % 997) + 997) % 997) / 997;
31
+ const placed = [];
32
+ for (const kind of Object.keys(STAR_COLORS)) {
33
+ const chain = stars
34
+ .filter((star) => star.kind === kind && star.at >= start && star.at <= now.getTime())
35
+ .sort((a, b) => a.at - b.at);
36
+ let group = [];
37
+ let centre = 0.5;
38
+ for (const star of chain) {
39
+ const previous = group.at(-1);
40
+ if (!previous ||
41
+ group.length >= CONSTELLATION_SIZE ||
42
+ star.at - previous.star.at > CONSTELLATION_GAP_MS) {
43
+ group = [];
44
+ centre = 0.2 + 0.6 * unit(star.seed);
45
+ }
46
+ const y = Math.min(0.95, Math.max(0.05, centre + (unit(star.seed * 31) - 0.5) * 0.35));
47
+ const point = {
48
+ star,
49
+ x: 2 + ((star.at - start) / YEAR_MS) * (width - 5),
50
+ y: y * (height - 3),
51
+ };
52
+ if (previous && group.length > 0) {
53
+ const steps = Math.max(1, Math.round(Math.hypot(point.x - previous.x, point.y - previous.y)));
54
+ for (let step = 0; step <= steps; step++) {
55
+ const x = previous.x + ((point.x - previous.x) * step) / steps;
56
+ const ly = previous.y + ((point.y - previous.y) * step) / steps;
57
+ c.set(x, ly, mix(c.get(x, ly) ?? '#050b1e', STAR_COLORS[kind], 0.22));
58
+ }
59
+ }
60
+ group.push(point);
61
+ placed.push(point);
62
+ }
63
+ }
64
+ for (const { star, x, y } of placed) {
65
+ const color = STAR_COLORS[star.kind];
66
+ const glow = star.kind === 'conference' ? 2 : 1;
67
+ c.blob(x, y, glow + 1.5, glow + 1.5, (px, py, edge) => mix(c.get(px, py) ?? '#050b1e', color, 0.6 * (1 - edge) ** 2));
68
+ c.set(x, y, '#ffffff');
69
+ for (const [dx, dy] of [
70
+ [-1, 0],
71
+ [1, 0],
72
+ [0, -1],
73
+ [0, 1],
74
+ ])
75
+ c.set(x + dx, y + dy, color);
76
+ }
77
+ for (let month = 0; month < 12; month++) {
78
+ const first = new Date(now.getFullYear(), now.getMonth() - month, 1).getTime();
79
+ c.set(2 + ((first - start) / YEAR_MS) * (width - 5), height - 1, '#2a3a66');
80
+ }
81
+ return c.toBitmap();
82
+ }
@@ -0,0 +1,27 @@
1
+ const CAMPUS = { latitude: 29.9, longitude: 121.6, utcOffset: 8 };
2
+ const RAD = Math.PI / 180;
3
+ const DAY_MS = 86_400_000;
4
+ /** Sunrise and sunset on the campus clock, in hours, for the calendar day of `date`. */
5
+ export function sunHours(date) {
6
+ const day = (Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()) -
7
+ Date.UTC(date.getFullYear(), 0, 0)) /
8
+ DAY_MS;
9
+ const declination = -23.44 * RAD * Math.cos(((2 * Math.PI) / 365) * (day + 10));
10
+ const b = ((2 * Math.PI) / 364) * (day - 81);
11
+ const equationOfTime = 9.87 * Math.sin(2 * b) - 7.53 * Math.cos(b) - 1.5 * Math.sin(b);
12
+ const noon = 12 + CAMPUS.utcOffset - CAMPUS.longitude / 15 - equationOfTime / 60;
13
+ const lat = CAMPUS.latitude * RAD;
14
+ const cosHalfDay = (Math.sin(-0.833 * RAD) - Math.sin(lat) * Math.sin(declination)) /
15
+ (Math.cos(lat) * Math.cos(declination));
16
+ const halfDay = Math.acos(Math.min(1, Math.max(-1, cosHalfDay))) / RAD / 15;
17
+ return { rise: noon - halfDay, set: noon + halfDay };
18
+ }
19
+ /** Stretches the clock so campus sunrise lands on 06:00 and sunset on 18:00, the hours the sky palette assumes. */
20
+ export function solarHour(now) {
21
+ const hour = now.getHours() + now.getMinutes() / 60;
22
+ const { rise, set } = sunHours(now);
23
+ if (hour >= rise && hour < set)
24
+ return 6 + (12 * (hour - rise)) / (set - rise);
25
+ const night = 24 - (set - rise);
26
+ return (18 + (12 * ((hour - set + 24) % 24)) / night) % 24;
27
+ }
package/dist/cli.js CHANGED
@@ -224,6 +224,7 @@ function printHelp() {
224
224
  console.log(` status ${trans.menu.statusDesc}`);
225
225
  console.log(' schedule <login|logout|status|terms|export>');
226
226
  console.log(` ${c.cmdSchedule}`);
227
+ console.log(` prompt ${c.cmdPrompt}`);
227
228
  console.log(` exams ${trans.records.exams}`);
228
229
  console.log(` grades ${trans.records.grades}`);
229
230
  console.log(` website ${c.cmdWebsite}`);
@@ -256,6 +257,7 @@ function printHelp() {
256
257
  console.log(` --term=<year:code> ${c.flagTerm}`);
257
258
  console.log(` --output=<path> ${c.flagOutput}`);
258
259
  console.log(` --week-one=<date> ${c.flagWeekOne}`);
260
+ console.log(` --shell=<name> ${c.flagShell}`);
259
261
  }
260
262
  async function runEventsCommand(flags) {
261
263
  const searchFlag = Array.from(flags).find((flag) => flag.startsWith('--search='));
@@ -27,6 +27,8 @@ export const URLS = {
27
27
  cloud: 'https://cloud.nbtca.space',
28
28
  mirror: 'https://i.nbtca.space',
29
29
  };
30
+ // From https://docs.nbtca.space/about/what-is-nbtca.html, which gives the month but no day.
31
+ export const FOUNDED = { year: 2002, month: 3 };
30
32
  export const APP_INFO = {
31
33
  name: 'Prompt',
32
34
  version: readPackageVersion(),
@@ -10,6 +10,10 @@ export const ansi = {
10
10
  home: `${CSI}H`,
11
11
  cursorToRow: (row) => `${CSI}${row};1H`,
12
12
  clearAll: `${CSI}2J`,
13
+ pushTitle: `${CSI}22;0t`,
14
+ // Terminals without a title stack ignore the pop, so clear the title first.
15
+ popTitle: `\x1b]0;\x07${CSI}23;0t`,
16
+ title: (text) => `\x1b]0;${text}\x07`,
13
17
  };
14
18
  let registered = false;
15
19
  export function ensureCursorRestored() {
package/dist/core/logo.js CHANGED
@@ -23,6 +23,12 @@ const LOGO_TIERS = [
23
23
  { file: 'ca-dotmatrix.txt', minCols: 44, minRows: 24 },
24
24
  { file: 'ca-dotmatrix-small.txt', minCols: 0, minRows: 0 },
25
25
  ];
26
+ const ASCII_EMBLEMS = [
27
+ 'ascii-emblem-large.txt',
28
+ 'ascii-emblem-medium.txt',
29
+ 'ascii-emblem-small.txt',
30
+ 'ascii-emblem-tiny.txt',
31
+ ];
26
32
  function paint(text, color) {
27
33
  return color ? brand(text) : text;
28
34
  }
@@ -39,10 +45,7 @@ function logoContent() {
39
45
  ...(useUnicodeIcons()
40
46
  ? LOGO_TIERS.filter((tier) => (cols ?? 0) >= tier.minCols && (rows ?? 0) >= tier.minRows).map((tier) => tier.file)
41
47
  : []),
42
- ...(useUnicodeIcons()
43
- ? []
44
- : ['ascii-emblem-large.txt', 'ascii-emblem-medium.txt', 'ascii-emblem.txt']),
45
- 'ascii-logo.txt',
48
+ ...ASCII_EMBLEMS,
46
49
  undefined,
47
50
  ];
48
51
  for (const file of files) {
@@ -119,7 +122,7 @@ export async function runStartup() {
119
122
  }
120
123
  const EMBLEM_FILES = {
121
124
  unicode: ['ca-dotmatrix-large.txt', 'ca-dotmatrix.txt', 'ca-dotmatrix-small.txt'],
122
- ascii: ['ascii-emblem-large.txt', 'ascii-emblem-medium.txt', 'ascii-emblem.txt'],
125
+ ascii: ASCII_EMBLEMS,
123
126
  };
124
127
  /** The largest emblem that fits the box, painted with the brand gradient; undefined when none fits. */
125
128
  export function emblemLines(maxCols, maxRows) {