@nbtca/prompt 1.5.16 → 1.5.18
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/app.js +28 -29
- package/dist/app/chrome.js +22 -31
- package/dist/app/fields/list-field.js +3 -4
- package/dist/app/frame.js +2 -5
- package/dist/app/help.js +2 -2
- package/dist/app/views/docs-render.js +24 -8
- package/dist/app/views/docs.js +157 -95
- package/dist/app/views/events-render.js +42 -24
- package/dist/app/views/events.js +57 -21
- package/dist/app/views/home.js +2 -2
- package/dist/app/views/schedule-grid-cursor.js +1 -1
- package/dist/app/views/schedule-render.js +81 -29
- package/dist/app/views/schedule.js +8 -3
- package/dist/app/views/settings-render.js +1 -0
- package/dist/app/views/settings.js +37 -12
- package/dist/config/preferences.js +1 -1
- package/dist/core/components/menu.js +13 -8
- package/dist/core/logo.js +23 -5
- package/dist/core/text.js +28 -14
- package/dist/core/theme.js +14 -0
- package/dist/features/about.js +2 -2
- package/dist/features/calendar-heatmap.js +52 -63
- package/dist/features/calendar-query.js +1 -1
- package/dist/features/calendar.js +23 -7
- package/dist/features/docs-client.js +4 -2
- package/dist/features/docs-markdown.js +16 -24
- package/dist/features/docs.js +58 -24
- package/dist/features/schedule-render.js +185 -150
- package/dist/features/status.js +5 -1
- package/dist/i18n/locales/en.json +38 -21
- package/dist/i18n/locales/zh.json +41 -24
- package/package.json +2 -2
package/dist/app/views/events.js
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
import { captureFooterHint, passiveFooterHint } from '../chrome.js';
|
|
2
2
|
import { ListField, computeMaxVisible } from '../fields/list-field.js';
|
|
3
3
|
import { TextField } from '../fields/text-field.js';
|
|
4
|
-
import { renderEvents } from './events-render.js';
|
|
4
|
+
import { hubShowsHeatmap, renderEvents } from './events-render.js';
|
|
5
5
|
import { setVimKeysActive } from '../../core/vim-keys.js';
|
|
6
|
-
import {
|
|
6
|
+
import { glyph } from '../../core/theme.js';
|
|
7
7
|
import { padEndV, visualWidth } from '../../core/text.js';
|
|
8
8
|
import { fmt, t } from '../../i18n/index.js';
|
|
9
|
-
import { eventWhen, exportEventIcs, loadCalendarOrCache, recurringMark, toDisplayEvent, yearHeatmap, } from '../../features/calendar.js';
|
|
10
|
-
import { currentEvents, monthRange, pastEvents, searchEvents, weekRange, } from '../../features/calendar-query.js';
|
|
9
|
+
import { eventTimeRange, eventWhen, exportEventIcs, loadCalendarOrCache, recurringMark, toDisplayEvent, yearHeatmap, } from '../../features/calendar.js';
|
|
10
|
+
import { currentEvents, hasEnded, monthRange, pastEvents, searchEvents, weekRange, } from '../../features/calendar-query.js';
|
|
11
11
|
let state = { mode: 'loading' };
|
|
12
12
|
let calendar = null;
|
|
13
13
|
let stale = false;
|
|
14
14
|
let currentList = [];
|
|
15
15
|
let listState;
|
|
16
16
|
let hubField;
|
|
17
|
+
let hubValues = [];
|
|
17
18
|
function backLabel() {
|
|
18
19
|
return t().common.back;
|
|
19
20
|
}
|
|
20
|
-
function buildHubField(
|
|
21
|
+
function buildHubField(selected, withHeatmap) {
|
|
21
22
|
const trans = t();
|
|
22
23
|
const options = [
|
|
23
24
|
{ value: 'upcoming', label: trans.calendar.next30Days },
|
|
@@ -25,18 +26,33 @@ function buildHubField(initialIndex) {
|
|
|
25
26
|
{ value: 'month', label: trans.calendar.thisMonth },
|
|
26
27
|
{ value: 'search', label: trans.calendar.search },
|
|
27
28
|
{ value: 'past', label: trans.calendar.pastEvents },
|
|
28
|
-
{ value: 'heatmap', label: trans.calendar.heatmap.title },
|
|
29
|
+
...(withHeatmap ? [{ value: 'heatmap', label: trans.calendar.heatmap.title }] : []),
|
|
29
30
|
];
|
|
31
|
+
hubValues = options.map((option) => option.value);
|
|
32
|
+
const initialIndex = Math.max(0, selected === undefined ? 0 : hubValues.indexOf(selected));
|
|
30
33
|
return new ListField({ title: trans.calendar.browse, options, initialIndex });
|
|
31
34
|
}
|
|
32
|
-
function
|
|
35
|
+
function selectedHubValue() {
|
|
36
|
+
return hubField ? hubValues[hubField.selectedIndex] : undefined;
|
|
37
|
+
}
|
|
38
|
+
function syncHubField(bodyRows) {
|
|
39
|
+
if (state.mode !== 'hub')
|
|
40
|
+
return;
|
|
41
|
+
const withHeatmap = !hubShowsHeatmap(bodyRows, state.heatmapBuckets);
|
|
42
|
+
if (hubValues.includes('heatmap') === withHeatmap)
|
|
43
|
+
return;
|
|
44
|
+
hubField = buildHubField(selectedHubValue(), withHeatmap);
|
|
45
|
+
state = { ...state, hubField };
|
|
46
|
+
}
|
|
47
|
+
function showList(ctx, title, events, emptyMessage, isEnded = () => false) {
|
|
33
48
|
const trans = t();
|
|
34
|
-
const dot =
|
|
49
|
+
const dot = glyph.sep();
|
|
35
50
|
const display = events.map(toDisplayEvent);
|
|
36
51
|
const whenWidth = Math.max(0, ...display.map((event) => visualWidth(eventWhen(event))));
|
|
37
52
|
const options = [
|
|
38
53
|
...display.map((event, index) => {
|
|
39
|
-
const
|
|
54
|
+
const raw = events[index];
|
|
55
|
+
const ended = raw !== undefined && isEnded(raw);
|
|
40
56
|
return {
|
|
41
57
|
value: String(index),
|
|
42
58
|
label: `${padEndV(eventWhen(event), whenWidth)} ${event.title}${recurringMark(event)}`,
|
|
@@ -64,11 +80,11 @@ function goToHub() {
|
|
|
64
80
|
const now = new Date();
|
|
65
81
|
const upcoming = calendar ? currentEvents(calendar, now) : [];
|
|
66
82
|
const nextEvent = upcoming.find((event) => event.start >= now);
|
|
67
|
-
|
|
83
|
+
const withHeatmap = hubValues.length === 0 || hubValues.includes('heatmap');
|
|
84
|
+
hubField = buildHubField(selectedHubValue(), withHeatmap);
|
|
68
85
|
state = {
|
|
69
86
|
mode: 'hub',
|
|
70
87
|
hubField,
|
|
71
|
-
...(stale ? { stale } : {}),
|
|
72
88
|
...(nextEvent === undefined ? {} : { nextEvent: toDisplayEvent(nextEvent) }),
|
|
73
89
|
heatmapBuckets: calendar ? yearHeatmap(calendar, now) : [],
|
|
74
90
|
recentEvents: upcoming.slice(0, RECENT_EVENTS_CAP).map(toDisplayEvent),
|
|
@@ -78,11 +94,11 @@ function showDetail(raw) {
|
|
|
78
94
|
const trans = t();
|
|
79
95
|
listState = state;
|
|
80
96
|
const e = toDisplayEvent(raw);
|
|
81
|
-
const dot =
|
|
97
|
+
const dot = glyph.sep();
|
|
82
98
|
state = {
|
|
83
99
|
mode: 'detail',
|
|
84
100
|
detailTitle: e.title,
|
|
85
|
-
detailMeta: `${
|
|
101
|
+
detailMeta: `${eventTimeRange(raw)} ${dot} ${e.location}${raw.recurring ? ` ${dot} ${trans.calendar.recurringLabel}` : ''}`,
|
|
86
102
|
detailDescription: e.description,
|
|
87
103
|
detailEvent: raw,
|
|
88
104
|
detailField: new ListField({
|
|
@@ -102,6 +118,7 @@ export const eventsView = {
|
|
|
102
118
|
return;
|
|
103
119
|
state = { mode: 'loading' };
|
|
104
120
|
hubField = undefined;
|
|
121
|
+
hubValues = [];
|
|
105
122
|
ctx.rerender();
|
|
106
123
|
try {
|
|
107
124
|
const loaded = await loadCalendarOrCache(ctx.signal);
|
|
@@ -114,14 +131,21 @@ export const eventsView = {
|
|
|
114
131
|
catch {
|
|
115
132
|
if (ctx.signal?.aborted)
|
|
116
133
|
return;
|
|
117
|
-
state = {
|
|
134
|
+
state = {
|
|
135
|
+
mode: 'error',
|
|
136
|
+
errorMessage: t().calendar.offlineError,
|
|
137
|
+
errorField: new ListField({
|
|
138
|
+
options: [{ value: 'retry', label: t().calendar.retry }],
|
|
139
|
+
}),
|
|
140
|
+
};
|
|
118
141
|
}
|
|
119
142
|
if (!ctx.signal?.aborted)
|
|
120
143
|
ctx.rerender();
|
|
121
144
|
},
|
|
122
145
|
render(ctx) {
|
|
123
146
|
state.listField?.setMaxVisible(computeMaxVisible(ctx.bodyRows));
|
|
124
|
-
|
|
147
|
+
syncHubField(ctx.bodyRows);
|
|
148
|
+
return renderEvents(stale ? { ...state, stale } : state, new Date(), ctx.bodyRows, ctx.size.cols);
|
|
125
149
|
},
|
|
126
150
|
isBusy() {
|
|
127
151
|
return state.mode === 'loading';
|
|
@@ -130,12 +154,15 @@ export const eventsView = {
|
|
|
130
154
|
return state.mode === 'search';
|
|
131
155
|
},
|
|
132
156
|
capturesPageKeys() {
|
|
133
|
-
return state.mode === 'hub' ||
|
|
157
|
+
return (state.mode === 'hub' ||
|
|
158
|
+
state.mode === 'list' ||
|
|
159
|
+
state.mode === 'detail' ||
|
|
160
|
+
state.mode === 'error');
|
|
134
161
|
},
|
|
135
162
|
footerHint(tabCount, cols = Number.POSITIVE_INFINITY) {
|
|
136
163
|
if (state.mode === 'search')
|
|
137
164
|
return captureFooterHint(cols);
|
|
138
|
-
const passive = state.mode === 'loading' || state.mode === '
|
|
165
|
+
const passive = state.mode === 'loading' || state.mode === 'heatmap';
|
|
139
166
|
return passive ? passiveFooterHint(tabCount, cols) : undefined;
|
|
140
167
|
},
|
|
141
168
|
handleBack() {
|
|
@@ -155,6 +182,11 @@ export const eventsView = {
|
|
|
155
182
|
return false;
|
|
156
183
|
},
|
|
157
184
|
handleKey(key, ctx) {
|
|
185
|
+
if (state.mode === 'error') {
|
|
186
|
+
if (state.errorField?.handleKey(key).selected === 'retry')
|
|
187
|
+
void eventsView.load(ctx);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
158
190
|
if (!calendar)
|
|
159
191
|
return;
|
|
160
192
|
switch (state.mode) {
|
|
@@ -171,7 +203,7 @@ export const eventsView = {
|
|
|
171
203
|
if (result.selected === 'week' || result.selected === 'month') {
|
|
172
204
|
const r = result.selected === 'week' ? weekRange(now) : monthRange(now);
|
|
173
205
|
const title = result.selected === 'week' ? trans.calendar.thisWeek : trans.calendar.thisMonth;
|
|
174
|
-
showList(ctx, title, calendar.inRange(r.start, r.end), trans.calendar.noEventsInRange);
|
|
206
|
+
showList(ctx, title, calendar.inRange(r.start, r.end), trans.calendar.noEventsInRange, (event) => hasEnded(event, now));
|
|
175
207
|
return;
|
|
176
208
|
}
|
|
177
209
|
if (result.selected === 'past') {
|
|
@@ -245,14 +277,18 @@ export const eventsView = {
|
|
|
245
277
|
goToHub();
|
|
246
278
|
return;
|
|
247
279
|
}
|
|
248
|
-
const
|
|
280
|
+
const now = new Date();
|
|
281
|
+
const { upcoming, past } = searchEvents(calendar, query, now);
|
|
249
282
|
const trans = t();
|
|
250
|
-
showList(ctx,
|
|
283
|
+
showList(ctx, fmt(trans.calendar.searchResultsTitle, {
|
|
284
|
+
query,
|
|
285
|
+
count: upcoming.length + past.length,
|
|
286
|
+
sep: glyph.sep(),
|
|
287
|
+
}), [...upcoming, ...past], fmt(trans.calendar.searchNoResultsFor, { query }), (event) => hasEnded(event, now));
|
|
251
288
|
}
|
|
252
289
|
return;
|
|
253
290
|
}
|
|
254
291
|
case 'loading':
|
|
255
|
-
case 'error':
|
|
256
292
|
return;
|
|
257
293
|
}
|
|
258
294
|
},
|
package/dist/app/views/home.js
CHANGED
|
@@ -101,7 +101,7 @@ export function renderHome(data, now, bodyRows = 100, cols = 80) {
|
|
|
101
101
|
}
|
|
102
102
|
const unresolvedCount = data.schedule?.timetable.unresolvedItems.length ?? 0;
|
|
103
103
|
if (unresolvedCount > 0) {
|
|
104
|
-
lines.push(...wrappedIndentedLines(`${pickIcon('⚠', '!')} ${trans.timetable.hubUnresolved}
|
|
104
|
+
lines.push(...wrappedIndentedLines(`${pickIcon('⚠', '!')} ${trans.timetable.hubUnresolved} ${glyph.sep()} ${unresolvedCount}`, cols, c.warn));
|
|
105
105
|
lines.push('');
|
|
106
106
|
}
|
|
107
107
|
lines.push(...panelHeading(trans.menu.events, cols));
|
|
@@ -161,7 +161,7 @@ export const homeView = {
|
|
|
161
161
|
id: 'home',
|
|
162
162
|
title: 'Home',
|
|
163
163
|
footerHint(tabCount, cols = Number.POSITIVE_INFINITY) {
|
|
164
|
-
return passiveFooterHint(tabCount, cols);
|
|
164
|
+
return passiveFooterHint(tabCount, cols, false);
|
|
165
165
|
},
|
|
166
166
|
async load(ctx) {
|
|
167
167
|
if (ctx.signal?.aborted)
|
|
@@ -42,7 +42,7 @@ export function handleGridKey(key, cursor, tt, week) {
|
|
|
42
42
|
return { kind: 'moveCursor', cursor: moveCursorPeriod(cursor, tt.periods, 1) };
|
|
43
43
|
if (key === KEY_ENTER_CR || key === KEY_ENTER_LF) {
|
|
44
44
|
const meeting = createTimetableSchedule(tt).meetingAt(week, cursor.weekday, cursor.period);
|
|
45
|
-
return meeting ? { kind: 'openDetail', meeting } : { kind: '
|
|
45
|
+
return meeting ? { kind: 'openDetail', meeting } : { kind: 'emptyCell' };
|
|
46
46
|
}
|
|
47
47
|
return { kind: 'none' };
|
|
48
48
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { campusIsoDate, createTimetableSchedule, } from '@nbtca/nbtcal/timetable';
|
|
2
|
-
import { c, type, space, glyph } from '../../core/theme.js';
|
|
2
|
+
import { c, type, space, glyph, MAX_FRAME_COLS } from '../../core/theme.js';
|
|
3
3
|
import { pickIcon } from '../../core/icons.js';
|
|
4
4
|
import { t, fmt } from '../../i18n/index.js';
|
|
5
5
|
import { renderListFieldWithContext } from '../fields/list-field.js';
|
|
6
|
-
import { renderNextClassBanner, renderWeekGrid, renderUnresolvedItems, renderTodayTimeline, weekdayShortLabel, renderTermDensity, renderMeetingDetail, renderDayTimeline, renderDaySwitcher, renderWeekAgenda, lineBudget, } from '../../features/schedule-render.js';
|
|
7
|
-
import { sanitizeTerminalLine, visualWidth, wrapAnsiWithIndent } from '../../core/text.js';
|
|
6
|
+
import { renderNextClassBanner, renderWeekGrid, renderUnresolvedItems, renderTodayTimeline, weekdayShortLabel, renderTermDensity, renderMeetingDetail, renderDayTimeline, renderDaySwitcher, renderWeekAgenda, weekGridFullWidth, lineBudget, } from '../../features/schedule-render.js';
|
|
7
|
+
import { sanitizeTerminalLine, truncate, truncateStart, visualWidth, wrapAnsiWithIndent, } from '../../core/text.js';
|
|
8
8
|
import { isoDayDifference } from '../../core/calendar-day.js';
|
|
9
9
|
import { loadingLines } from '../../core/components/spinner.js';
|
|
10
10
|
function heading(label) {
|
|
@@ -91,6 +91,7 @@ function hubPreGridLines(state, now, cols) {
|
|
|
91
91
|
lines.push(hint(fmt(trans.timetable.termStartsIn, {
|
|
92
92
|
date: state.weekOne,
|
|
93
93
|
days: String(daysUntil(now, state.weekOne)),
|
|
94
|
+
sep: glyph.sep(),
|
|
94
95
|
})));
|
|
95
96
|
lines.push('');
|
|
96
97
|
lines.push(heading(trans.timetable.termPreviewWeek));
|
|
@@ -103,6 +104,7 @@ function hubPreGridLines(state, now, cols) {
|
|
|
103
104
|
heading(fmt(trans.timetable.todayHeading, {
|
|
104
105
|
weekday: weekdayShortLabel(todayWd),
|
|
105
106
|
week: String(week),
|
|
107
|
+
sep: glyph.sep(),
|
|
106
108
|
})),
|
|
107
109
|
...renderTodayTimeline(today, tt.periods, now, cols).split('\n'),
|
|
108
110
|
'',
|
|
@@ -110,9 +112,8 @@ function hubPreGridLines(state, now, cols) {
|
|
|
110
112
|
];
|
|
111
113
|
return { inlineLines, fallbackLines: [...lines, weekHeading], week, tt };
|
|
112
114
|
}
|
|
113
|
-
const MIN_GRID_COLS = 100;
|
|
114
115
|
function fittingWeekGrid(tt, week, now, rows, cols, cursor) {
|
|
115
|
-
if (cols <
|
|
116
|
+
if (cols < Math.min(MAX_FRAME_COLS, weekGridFullWidth(tt, week, now)))
|
|
116
117
|
return null;
|
|
117
118
|
const grid = renderWeekGrid(tt, week, now, cols, cursor).split('\n');
|
|
118
119
|
return grid.length <= rows ? grid : null;
|
|
@@ -124,11 +125,23 @@ function renderDayFallback(tt, week, todayWd, now, cols, cursor) {
|
|
|
124
125
|
...renderDayTimeline(createTimetableSchedule(tt).meetingsOnDay(week, selectedWd), tt.periods, now, { weekday: selectedWd, isToday: selectedWd === todayWd }, cursor?.period, cols).split('\n'),
|
|
125
126
|
];
|
|
126
127
|
}
|
|
127
|
-
function
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
128
|
+
function renderHubWeek(inlineLines, fallbackLines, tt, week, todayWd, now, rows, cols, cursor) {
|
|
129
|
+
const layouts = [
|
|
130
|
+
[fittingWeekGrid(tt, week, now, rows, cols, cursor), true],
|
|
131
|
+
[renderWeekAgenda(tt, week, now, cols, cursor), false],
|
|
132
|
+
];
|
|
133
|
+
for (const [layout, grid] of layouts) {
|
|
134
|
+
if (!layout)
|
|
135
|
+
continue;
|
|
136
|
+
for (const head of [inlineLines, inlineLines.filter((line) => line !== ''), fallbackLines]) {
|
|
137
|
+
if (head.length + layout.length <= rows)
|
|
138
|
+
return { lines: [...head, ...layout], grid };
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
lines: [...fallbackLines, ...renderDayFallback(tt, week, todayWd, now, cols, cursor)],
|
|
143
|
+
grid: false,
|
|
144
|
+
};
|
|
132
145
|
}
|
|
133
146
|
function renderWeekBody(tt, week, todayWd, now, bodyRows, cols, cursor) {
|
|
134
147
|
const rows = Math.max(0, Math.floor(bodyRows));
|
|
@@ -155,39 +168,71 @@ function renderWeekBody(tt, week, todayWd, now, bodyRows, cols, cursor) {
|
|
|
155
168
|
];
|
|
156
169
|
}
|
|
157
170
|
const MIN_HUB_CONTENT_ROWS = 4;
|
|
158
|
-
|
|
159
|
-
|
|
171
|
+
const MIN_PATH_COLS = 12;
|
|
172
|
+
function middleClip(text, width) {
|
|
173
|
+
if (visualWidth(text) <= width)
|
|
174
|
+
return text;
|
|
175
|
+
const mark = pickIcon('…', '...');
|
|
176
|
+
const room = width - visualWidth(mark);
|
|
177
|
+
const tail = Math.ceil((room * 2) / 3);
|
|
178
|
+
return `${truncate(text, room - tail, '')}${mark}${truncateStart(text, tail, '')}`;
|
|
179
|
+
}
|
|
180
|
+
function hubStatusLines(state, cols) {
|
|
181
|
+
if (state.exportedPath !== undefined) {
|
|
182
|
+
const template = t().timetable.exportSaved;
|
|
183
|
+
const path = sanitizeTerminalLine(state.exportedPath);
|
|
184
|
+
const room = lineBudget(cols) - visualWidth(space.indent + fmt(template, { path: '' }));
|
|
185
|
+
return room < MIN_PATH_COLS
|
|
186
|
+
? hintLines(fmt(template, { path }), cols)
|
|
187
|
+
: [hint(fmt(template, { path: middleClip(path, room) }))];
|
|
188
|
+
}
|
|
189
|
+
return state.statusMessage ? hintLines(state.statusMessage, cols) : [];
|
|
190
|
+
}
|
|
191
|
+
function layoutHub(state, now, bodyRows, cols, shortcuts) {
|
|
160
192
|
const pre = hubPreGridLines(state, now, cols);
|
|
161
|
-
const
|
|
193
|
+
const status = hubStatusLines(state, cols);
|
|
162
194
|
const rows = Math.max(0, Math.floor(bodyRows));
|
|
163
195
|
const build = (shortcutLines, gap = true) => {
|
|
164
196
|
const tail = [];
|
|
165
|
-
if (gap && pre && (
|
|
197
|
+
if (gap && pre && (status.length > 0 || shortcutLines.length > 0))
|
|
166
198
|
tail.push('');
|
|
167
|
-
if (
|
|
168
|
-
tail.push(...
|
|
199
|
+
if (status.length > 0) {
|
|
200
|
+
tail.push(...status);
|
|
169
201
|
if (shortcutLines.length > 0)
|
|
170
202
|
tail.push('');
|
|
171
203
|
}
|
|
172
204
|
tail.push(...shortcutLines);
|
|
173
|
-
const
|
|
174
|
-
?
|
|
175
|
-
: [];
|
|
176
|
-
return {
|
|
205
|
+
const week = pre
|
|
206
|
+
? renderHubWeek(pre.inlineLines, pre.fallbackLines, pre.tt, pre.week, createTimetableSchedule(pre.tt).weekdayAt(now), now, rows - tail.length, cols, state.gridCursor)
|
|
207
|
+
: { lines: [], grid: false };
|
|
208
|
+
return { ...week, tail };
|
|
177
209
|
};
|
|
178
210
|
const labelled = renderShortcutLines(shortcuts, cols);
|
|
179
211
|
const full = build(labelled);
|
|
180
|
-
if (full.
|
|
181
|
-
return [...full.
|
|
212
|
+
if (full.lines.length + full.tail.length <= rows) {
|
|
213
|
+
return { lines: [...full.lines, ...full.tail], grid: full.grid };
|
|
214
|
+
}
|
|
182
215
|
const tight = build(labelled, false);
|
|
183
216
|
if (rows - tight.tail.length >= MIN_HUB_CONTENT_ROWS) {
|
|
184
|
-
const content = tight.
|
|
185
|
-
return
|
|
217
|
+
const content = tight.lines.filter((line) => line !== '');
|
|
218
|
+
return {
|
|
219
|
+
lines: [...content.slice(0, rows - tight.tail.length), ...tight.tail],
|
|
220
|
+
grid: tight.grid,
|
|
221
|
+
};
|
|
186
222
|
}
|
|
187
223
|
const compact = build(renderShortcutLines(shortcuts, cols, true));
|
|
188
|
-
if (compact.tail.length >= rows)
|
|
189
|
-
return rows > 0 ? compact.tail.slice(-rows) : [];
|
|
190
|
-
|
|
224
|
+
if (compact.tail.length >= rows) {
|
|
225
|
+
return { lines: rows > 0 ? compact.tail.slice(-rows) : [], grid: false };
|
|
226
|
+
}
|
|
227
|
+
return {
|
|
228
|
+
lines: [...compact.lines.slice(0, rows - compact.tail.length), ...compact.tail],
|
|
229
|
+
grid: compact.grid,
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
function renderHubBody(state, now, bodyRows, cols) {
|
|
233
|
+
const shortcuts = state.timetable ? hubShortcuts(state.timetable) : [];
|
|
234
|
+
const withGrid = layoutHub(state, now, bodyRows, cols, shortcuts.filter((shortcut) => shortcut.key !== 'w'));
|
|
235
|
+
return withGrid.grid ? withGrid.lines : layoutHub(state, now, bodyRows, cols, shortcuts).lines;
|
|
191
236
|
}
|
|
192
237
|
const TERM_PROGRESS_WIDTH = 20;
|
|
193
238
|
function renderTermProgressBar(w, cols) {
|
|
@@ -224,11 +269,18 @@ function renderPublicBody(state, now, bodyRows, cols) {
|
|
|
224
269
|
lines.push(...hintLines(trans.timetable.publicUnavailable, cols));
|
|
225
270
|
}
|
|
226
271
|
else if (w.status === 'onBreak') {
|
|
227
|
-
lines.push(...headingLines(fmt(trans.timetable.onBreak, {
|
|
272
|
+
lines.push(...headingLines(fmt(trans.timetable.onBreak, {
|
|
273
|
+
title: sanitizeTerminalLine(w.breakTitle),
|
|
274
|
+
sep: glyph.sep(),
|
|
275
|
+
}), cols));
|
|
228
276
|
}
|
|
229
277
|
else {
|
|
230
278
|
const semesterLabel = w.semester === '1' ? trans.timetable.semester1 : trans.timetable.semester2;
|
|
231
|
-
lines.push(...headingLines(
|
|
279
|
+
lines.push(...headingLines([
|
|
280
|
+
fmt(trans.timetable.academicYearSuffix, { year: sanitizeTerminalLine(w.academicYear) }),
|
|
281
|
+
semesterLabel,
|
|
282
|
+
fmt(trans.timetable.weekLabel2, { week: String(w.currentWeek) }),
|
|
283
|
+
].join(` ${glyph.sep()} `), cols));
|
|
232
284
|
const bar = renderTermProgressBar(w, cols);
|
|
233
285
|
if (bar)
|
|
234
286
|
lines.push(...bar);
|
|
@@ -34,11 +34,12 @@ function gridKeys() {
|
|
|
34
34
|
}
|
|
35
35
|
function gridFooterHint(tabCount, cols) {
|
|
36
36
|
const trans = t();
|
|
37
|
-
const dot =
|
|
37
|
+
const dot = glyph.sep();
|
|
38
38
|
const keys = gridKeys();
|
|
39
39
|
const local = `${keys.days} ${trans.timetable.footerDay} ${dot} ${keys.periods} ${trans.timetable.footerClass} ${dot} ${keys.enter} ${trans.timetable.footerDetail}`;
|
|
40
|
+
const labelled = `Esc ${trans.menu.hintBack} ${dot} q ${trans.menu.hintQuit}`;
|
|
40
41
|
const quit = `Esc ${dot} q ${trans.menu.hintQuit}`;
|
|
41
|
-
return fitFooterHint(cols, `${digitTabHint(tabCount)}${local} ${dot} ${
|
|
42
|
+
return fitFooterHint(cols, `${digitTabHint(tabCount)}${local} ${dot} ${labelled} ${dot} ${trans.help.hint}`, `${digitTabHint(tabCount)}${local} ${dot} ${labelled}`, `${digitTabHint(tabCount)}${local} ${dot} ${quit}`, `${local} ${dot} ${labelled}`, `${local} ${dot} ${quit}`, `${local} ${dot} Esc ${dot} q`, local, `Esc ${dot} q`, 'q');
|
|
42
43
|
}
|
|
43
44
|
function isLifecycleActive(ctx, generation) {
|
|
44
45
|
return generation === lifecycleGeneration && ctx.signal?.aborted !== true;
|
|
@@ -550,10 +551,12 @@ export const scheduleView = {
|
|
|
550
551
|
});
|
|
551
552
|
const out = `timetable-${hubKey}.ics`;
|
|
552
553
|
writePrivateIcs(out, ics);
|
|
553
|
-
state = { ...state,
|
|
554
|
+
state = { ...state, exportedPath: path.resolve(out) };
|
|
555
|
+
delete state.statusMessage;
|
|
554
556
|
}
|
|
555
557
|
catch (error) {
|
|
556
558
|
state = { ...state, statusMessage: safeMessage(error) };
|
|
559
|
+
delete state.exportedPath;
|
|
557
560
|
}
|
|
558
561
|
return;
|
|
559
562
|
}
|
|
@@ -591,6 +594,8 @@ export const scheduleView = {
|
|
|
591
594
|
};
|
|
592
595
|
return;
|
|
593
596
|
}
|
|
597
|
+
if (nav.kind === 'emptyCell')
|
|
598
|
+
return;
|
|
594
599
|
returnToHub();
|
|
595
600
|
return;
|
|
596
601
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ListField } from '../fields/list-field.js';
|
|
2
2
|
import { renderSettings } from './settings-render.js';
|
|
3
3
|
import { applyColorModePreference, loadPreferences, resetPreferences, setColorMode, setIconMode, } from '../../config/preferences.js';
|
|
4
|
-
import { resetIconCache
|
|
4
|
+
import { resetIconCache } from '../../core/icons.js';
|
|
5
5
|
import { APP_INFO, URLS } from '../../config/data.js';
|
|
6
6
|
import { t, getCurrentLanguage, saveLanguagePreference, clearTranslationCache, } from '../../i18n/index.js';
|
|
7
7
|
import { padEndV } from '../../core/text.js';
|
|
@@ -28,7 +28,7 @@ function modeOptions(modes, current) {
|
|
|
28
28
|
...currentHint(mode === current, t().common.current),
|
|
29
29
|
}));
|
|
30
30
|
}
|
|
31
|
-
function buildMenuField(statusMessage) {
|
|
31
|
+
function buildMenuField(statusMessage, focus) {
|
|
32
32
|
const trans = t();
|
|
33
33
|
const prefs = loadPreferences();
|
|
34
34
|
const currentLang = getCurrentLanguage();
|
|
@@ -46,11 +46,14 @@ function buildMenuField(statusMessage) {
|
|
|
46
46
|
return {
|
|
47
47
|
mode: 'menu',
|
|
48
48
|
...(statusMessage === undefined ? {} : { statusMessage }),
|
|
49
|
-
menuField: new ListField({
|
|
49
|
+
menuField: new ListField({
|
|
50
|
+
options,
|
|
51
|
+
initialIndex: Math.max(0, options.findIndex((option) => option.value === focus)),
|
|
52
|
+
}),
|
|
50
53
|
};
|
|
51
54
|
}
|
|
52
55
|
function goToMenu(statusMessage) {
|
|
53
|
-
state = buildMenuField(statusMessage);
|
|
56
|
+
state = buildMenuField(statusMessage, state.mode);
|
|
54
57
|
}
|
|
55
58
|
export const settingsView = {
|
|
56
59
|
id: 'settings',
|
|
@@ -135,11 +138,17 @@ export const settingsView = {
|
|
|
135
138
|
return;
|
|
136
139
|
}
|
|
137
140
|
if (result.selected === 'reset') {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
141
|
+
state = {
|
|
142
|
+
mode: 'reset',
|
|
143
|
+
subField: new ListField({
|
|
144
|
+
title: trans.theme.resetConfirm,
|
|
145
|
+
options: [
|
|
146
|
+
{ value: 'reset', label: trans.theme.resetLabel },
|
|
147
|
+
{ value: 'cancel', label: trans.common.cancel },
|
|
148
|
+
],
|
|
149
|
+
initialIndex: 1,
|
|
150
|
+
}),
|
|
151
|
+
};
|
|
143
152
|
return;
|
|
144
153
|
}
|
|
145
154
|
if (result.selected === 'about') {
|
|
@@ -158,7 +167,8 @@ export const settingsView = {
|
|
|
158
167
|
row(trans.about.website, URLS.homepage),
|
|
159
168
|
row(trans.about.email, URLS.email),
|
|
160
169
|
'',
|
|
161
|
-
row(trans.about.license,
|
|
170
|
+
row(trans.about.license, 'MIT'),
|
|
171
|
+
row(trans.about.author, 'm1ngsama'),
|
|
162
172
|
],
|
|
163
173
|
backField: new ListField({
|
|
164
174
|
title: '',
|
|
@@ -190,7 +200,7 @@ export const settingsView = {
|
|
|
190
200
|
const saved = setIconMode(result.selected);
|
|
191
201
|
resetIconCache();
|
|
192
202
|
resetCapabilities();
|
|
193
|
-
goToMenu(saved ? trans.theme.
|
|
203
|
+
goToMenu(saved ? trans.theme.iconUpdated : trans.theme.iconUpdatedSessionOnly);
|
|
194
204
|
return;
|
|
195
205
|
}
|
|
196
206
|
case 'color': {
|
|
@@ -200,7 +210,22 @@ export const settingsView = {
|
|
|
200
210
|
const saved = setColorMode(result.selected);
|
|
201
211
|
applyColorModePreference(false);
|
|
202
212
|
resetCapabilities();
|
|
203
|
-
goToMenu(saved ? trans.theme.
|
|
213
|
+
goToMenu(saved ? trans.theme.colorUpdated : trans.theme.colorUpdatedSessionOnly);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
case 'reset': {
|
|
217
|
+
const result = state.subField?.handleKey(key);
|
|
218
|
+
if (!result?.selected)
|
|
219
|
+
return;
|
|
220
|
+
if (result.selected !== 'reset') {
|
|
221
|
+
goToMenu();
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
const saved = resetPreferences();
|
|
225
|
+
resetIconCache();
|
|
226
|
+
applyColorModePreference(false);
|
|
227
|
+
resetCapabilities();
|
|
228
|
+
goToMenu(saved ? trans.theme.reset : trans.theme.resetSessionOnly);
|
|
204
229
|
return;
|
|
205
230
|
}
|
|
206
231
|
case 'about': {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { glyph, type, space } from '../theme.js';
|
|
2
|
-
import { visualWidth, padEndV, wrapAnsiToVisualWidth, clipAnsiToVisualWidth } from '../text.js';
|
|
1
|
+
import { glyph, type, space, bodyEdge } from '../theme.js';
|
|
2
|
+
import { visualWidth, padEndV, wrapAnsiToVisualWidth, clipAnsiToVisualWidth, excerptAround, } from '../text.js';
|
|
3
3
|
import { pickIcon } from '../icons.js';
|
|
4
4
|
import { createPainter } from './painter.js';
|
|
5
5
|
import { startRawInput } from './input-session.js';
|
|
@@ -73,22 +73,25 @@ function normalizedWidth(cols) {
|
|
|
73
73
|
function renderIndentedText(label, cols, style) {
|
|
74
74
|
const width = normalizedWidth(cols);
|
|
75
75
|
const indent = visualWidth(space.indent) < width ? space.indent : '';
|
|
76
|
-
const contentWidth = Math.max(1, width - visualWidth(indent));
|
|
76
|
+
const contentWidth = Math.max(1, bodyEdge(width) - visualWidth(indent));
|
|
77
77
|
return wrapAnsiToVisualWidth(style(label), contentWidth).map((line) => `${indent}${line}`);
|
|
78
78
|
}
|
|
79
79
|
const MIN_LABEL_COLUMN = 24;
|
|
80
|
+
const MIN_HINT_COLUMN = 16;
|
|
81
|
+
const ellipsis = () => pickIcon('…', '~');
|
|
80
82
|
function clipWithEllipsis(value, width) {
|
|
81
83
|
if (visualWidth(value) <= width)
|
|
82
84
|
return value;
|
|
83
|
-
|
|
84
|
-
return clipAnsiToVisualWidth(value, width - visualWidth(ellipsis)) + ellipsis;
|
|
85
|
+
return clipAnsiToVisualWidth(value, width - visualWidth(ellipsis())) + ellipsis();
|
|
85
86
|
}
|
|
86
87
|
function fitColumns(columns, contentWidth) {
|
|
87
88
|
if (columns.label + 2 + columns.hint <= contentWidth)
|
|
88
89
|
return columns;
|
|
89
90
|
const hint = Math.min(columns.hint, Math.max(contentWidth - 2 - columns.label, Math.ceil(contentWidth / 3)));
|
|
90
91
|
const label = Math.min(columns.label, contentWidth - 2 - hint);
|
|
91
|
-
|
|
92
|
+
const readable = label >= Math.min(MIN_LABEL_COLUMN, columns.label) &&
|
|
93
|
+
hint >= Math.min(MIN_HINT_COLUMN, columns.hint);
|
|
94
|
+
return readable ? { label, hint } : undefined;
|
|
92
95
|
}
|
|
93
96
|
function optionCells(option, columns, contentWidth) {
|
|
94
97
|
const hint = option.hint ?? '';
|
|
@@ -97,7 +100,9 @@ function optionCells(option, columns, contentWidth) {
|
|
|
97
100
|
return fitted
|
|
98
101
|
? {
|
|
99
102
|
label: padEndV(clipWithEllipsis(option.label, fitted.label), fitted.label),
|
|
100
|
-
hint:
|
|
103
|
+
hint: option.hintFocus
|
|
104
|
+
? excerptAround(hint, option.hintFocus, fitted.hint, ellipsis())
|
|
105
|
+
: clipWithEllipsis(hint, fitted.hint),
|
|
101
106
|
}
|
|
102
107
|
: { label: option.label, hint: '' };
|
|
103
108
|
}
|
|
@@ -113,7 +118,7 @@ export function renderMenuOption(option, selected, columns = menuColumns([option
|
|
|
113
118
|
const prefixes = [`${space.indent}${marker} `, `${marker} `, marker, ''];
|
|
114
119
|
const prefix = prefixes.find((candidate) => visualWidth(candidate) < width) ?? '';
|
|
115
120
|
const continuation = ' '.repeat(visualWidth(prefix));
|
|
116
|
-
const contentWidth = Math.max(1, width - visualWidth(prefix));
|
|
121
|
+
const contentWidth = Math.max(1, bodyEdge(width) - visualWidth(prefix));
|
|
117
122
|
const cells = optionCells(option, columns, contentWidth);
|
|
118
123
|
const style = selected ? type.active : option.dim ? type.hint : type.body;
|
|
119
124
|
const hint = cells.hint ? ` ${type.hint(cells.hint)}` : '';
|