@nbtca/prompt 1.5.16 → 1.5.17
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 +19 -26
- package/dist/app/fields/list-field.js +2 -2
- 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 +139 -87
- package/dist/app/views/events-render.js +42 -24
- package/dist/app/views/events.js +50 -18
- package/dist/app/views/home.js +1 -1
- package/dist/app/views/schedule-render.js +70 -27
- package/dist/app/views/schedule.js +5 -2
- package/dist/app/views/settings-render.js +1 -0
- package/dist/app/views/settings.js +37 -12
- package/dist/core/components/menu.js +7 -4
- package/dist/core/logo.js +23 -5
- package/dist/core/text.js +6 -14
- package/dist/core/theme.js +10 -0
- package/dist/features/about.js +2 -2
- package/dist/features/calendar-heatmap.js +49 -59
- package/dist/features/calendar-query.js +1 -1
- package/dist/features/calendar.js +18 -2
- package/dist/features/docs-client.js +4 -2
- package/dist/features/docs-markdown.js +16 -24
- package/dist/features/docs.js +44 -21
- package/dist/features/schedule-render.js +160 -139
- package/dist/features/status.js +5 -1
- package/dist/i18n/locales/en.json +29 -11
- package/dist/i18n/locales/zh.json +21 -3
- 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
6
|
import { pickIcon } from '../../core/icons.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
49
|
const dot = pickIcon('·', '-');
|
|
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),
|
|
@@ -82,7 +98,7 @@ function showDetail(raw) {
|
|
|
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,14 @@ 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, `${trans.calendar.search}: ${query}`, [...upcoming, ...past], fmt(trans.calendar.searchNoResultsFor, { query }),
|
|
283
|
+
showList(ctx, `${trans.calendar.search}: ${query}`, [...upcoming, ...past], fmt(trans.calendar.searchNoResultsFor, { query }), (event) => hasEnded(event, now));
|
|
251
284
|
}
|
|
252
285
|
return;
|
|
253
286
|
}
|
|
254
287
|
case 'loading':
|
|
255
|
-
case 'error':
|
|
256
288
|
return;
|
|
257
289
|
}
|
|
258
290
|
},
|
package/dist/app/views/home.js
CHANGED
|
@@ -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)
|
|
@@ -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) {
|
|
@@ -110,9 +110,8 @@ function hubPreGridLines(state, now, cols) {
|
|
|
110
110
|
];
|
|
111
111
|
return { inlineLines, fallbackLines: [...lines, weekHeading], week, tt };
|
|
112
112
|
}
|
|
113
|
-
const MIN_GRID_COLS = 100;
|
|
114
113
|
function fittingWeekGrid(tt, week, now, rows, cols, cursor) {
|
|
115
|
-
if (cols <
|
|
114
|
+
if (cols < Math.min(MAX_FRAME_COLS, weekGridFullWidth(tt, week, now)))
|
|
116
115
|
return null;
|
|
117
116
|
const grid = renderWeekGrid(tt, week, now, cols, cursor).split('\n');
|
|
118
117
|
return grid.length <= rows ? grid : null;
|
|
@@ -124,11 +123,23 @@ function renderDayFallback(tt, week, todayWd, now, cols, cursor) {
|
|
|
124
123
|
...renderDayTimeline(createTimetableSchedule(tt).meetingsOnDay(week, selectedWd), tt.periods, now, { weekday: selectedWd, isToday: selectedWd === todayWd }, cursor?.period, cols).split('\n'),
|
|
125
124
|
];
|
|
126
125
|
}
|
|
127
|
-
function
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
126
|
+
function renderHubWeek(inlineLines, fallbackLines, tt, week, todayWd, now, rows, cols, cursor) {
|
|
127
|
+
const layouts = [
|
|
128
|
+
[fittingWeekGrid(tt, week, now, rows, cols, cursor), true],
|
|
129
|
+
[renderWeekAgenda(tt, week, now, cols, cursor), false],
|
|
130
|
+
];
|
|
131
|
+
for (const [layout, grid] of layouts) {
|
|
132
|
+
if (!layout)
|
|
133
|
+
continue;
|
|
134
|
+
for (const head of [inlineLines, inlineLines.filter((line) => line !== ''), fallbackLines]) {
|
|
135
|
+
if (head.length + layout.length <= rows)
|
|
136
|
+
return { lines: [...head, ...layout], grid };
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
lines: [...fallbackLines, ...renderDayFallback(tt, week, todayWd, now, cols, cursor)],
|
|
141
|
+
grid: false,
|
|
142
|
+
};
|
|
132
143
|
}
|
|
133
144
|
function renderWeekBody(tt, week, todayWd, now, bodyRows, cols, cursor) {
|
|
134
145
|
const rows = Math.max(0, Math.floor(bodyRows));
|
|
@@ -155,39 +166,71 @@ function renderWeekBody(tt, week, todayWd, now, bodyRows, cols, cursor) {
|
|
|
155
166
|
];
|
|
156
167
|
}
|
|
157
168
|
const MIN_HUB_CONTENT_ROWS = 4;
|
|
158
|
-
|
|
159
|
-
|
|
169
|
+
const MIN_PATH_COLS = 12;
|
|
170
|
+
function middleClip(text, width) {
|
|
171
|
+
if (visualWidth(text) <= width)
|
|
172
|
+
return text;
|
|
173
|
+
const mark = pickIcon('…', '...');
|
|
174
|
+
const room = width - visualWidth(mark);
|
|
175
|
+
const tail = Math.ceil((room * 2) / 3);
|
|
176
|
+
return `${truncate(text, room - tail, '')}${mark}${truncateStart(text, tail, '')}`;
|
|
177
|
+
}
|
|
178
|
+
function hubStatusLines(state, cols) {
|
|
179
|
+
if (state.exportedPath !== undefined) {
|
|
180
|
+
const template = t().timetable.exportSaved;
|
|
181
|
+
const path = sanitizeTerminalLine(state.exportedPath);
|
|
182
|
+
const room = lineBudget(cols) - visualWidth(space.indent + fmt(template, { path: '' }));
|
|
183
|
+
return room < MIN_PATH_COLS
|
|
184
|
+
? hintLines(fmt(template, { path }), cols)
|
|
185
|
+
: [hint(fmt(template, { path: middleClip(path, room) }))];
|
|
186
|
+
}
|
|
187
|
+
return state.statusMessage ? hintLines(state.statusMessage, cols) : [];
|
|
188
|
+
}
|
|
189
|
+
function layoutHub(state, now, bodyRows, cols, shortcuts) {
|
|
160
190
|
const pre = hubPreGridLines(state, now, cols);
|
|
161
|
-
const
|
|
191
|
+
const status = hubStatusLines(state, cols);
|
|
162
192
|
const rows = Math.max(0, Math.floor(bodyRows));
|
|
163
193
|
const build = (shortcutLines, gap = true) => {
|
|
164
194
|
const tail = [];
|
|
165
|
-
if (gap && pre && (
|
|
195
|
+
if (gap && pre && (status.length > 0 || shortcutLines.length > 0))
|
|
166
196
|
tail.push('');
|
|
167
|
-
if (
|
|
168
|
-
tail.push(...
|
|
197
|
+
if (status.length > 0) {
|
|
198
|
+
tail.push(...status);
|
|
169
199
|
if (shortcutLines.length > 0)
|
|
170
200
|
tail.push('');
|
|
171
201
|
}
|
|
172
202
|
tail.push(...shortcutLines);
|
|
173
|
-
const
|
|
174
|
-
?
|
|
175
|
-
: [];
|
|
176
|
-
return {
|
|
203
|
+
const week = pre
|
|
204
|
+
? renderHubWeek(pre.inlineLines, pre.fallbackLines, pre.tt, pre.week, createTimetableSchedule(pre.tt).weekdayAt(now), now, rows - tail.length, cols, state.gridCursor)
|
|
205
|
+
: { lines: [], grid: false };
|
|
206
|
+
return { ...week, tail };
|
|
177
207
|
};
|
|
178
208
|
const labelled = renderShortcutLines(shortcuts, cols);
|
|
179
209
|
const full = build(labelled);
|
|
180
|
-
if (full.
|
|
181
|
-
return [...full.
|
|
210
|
+
if (full.lines.length + full.tail.length <= rows) {
|
|
211
|
+
return { lines: [...full.lines, ...full.tail], grid: full.grid };
|
|
212
|
+
}
|
|
182
213
|
const tight = build(labelled, false);
|
|
183
214
|
if (rows - tight.tail.length >= MIN_HUB_CONTENT_ROWS) {
|
|
184
|
-
const content = tight.
|
|
185
|
-
return
|
|
215
|
+
const content = tight.lines.filter((line) => line !== '');
|
|
216
|
+
return {
|
|
217
|
+
lines: [...content.slice(0, rows - tight.tail.length), ...tight.tail],
|
|
218
|
+
grid: tight.grid,
|
|
219
|
+
};
|
|
186
220
|
}
|
|
187
221
|
const compact = build(renderShortcutLines(shortcuts, cols, true));
|
|
188
|
-
if (compact.tail.length >= rows)
|
|
189
|
-
return rows > 0 ? compact.tail.slice(-rows) : [];
|
|
190
|
-
|
|
222
|
+
if (compact.tail.length >= rows) {
|
|
223
|
+
return { lines: rows > 0 ? compact.tail.slice(-rows) : [], grid: false };
|
|
224
|
+
}
|
|
225
|
+
return {
|
|
226
|
+
lines: [...compact.lines.slice(0, rows - compact.tail.length), ...compact.tail],
|
|
227
|
+
grid: compact.grid,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
function renderHubBody(state, now, bodyRows, cols) {
|
|
231
|
+
const shortcuts = state.timetable ? hubShortcuts(state.timetable) : [];
|
|
232
|
+
const withGrid = layoutHub(state, now, bodyRows, cols, shortcuts.filter((shortcut) => shortcut.key !== 'w'));
|
|
233
|
+
return withGrid.grid ? withGrid.lines : layoutHub(state, now, bodyRows, cols, shortcuts).lines;
|
|
191
234
|
}
|
|
192
235
|
const TERM_PROGRESS_WIDTH = 20;
|
|
193
236
|
function renderTermProgressBar(w, cols) {
|
|
@@ -37,8 +37,9 @@ function gridFooterHint(tabCount, cols) {
|
|
|
37
37
|
const dot = pickIcon('·', '-');
|
|
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
|
}
|
|
@@ -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,4 +1,4 @@
|
|
|
1
|
-
import { glyph, type, space } from '../theme.js';
|
|
1
|
+
import { glyph, type, space, bodyEdge } from '../theme.js';
|
|
2
2
|
import { visualWidth, padEndV, wrapAnsiToVisualWidth, clipAnsiToVisualWidth } from '../text.js';
|
|
3
3
|
import { pickIcon } from '../icons.js';
|
|
4
4
|
import { createPainter } from './painter.js';
|
|
@@ -73,10 +73,11 @@ 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;
|
|
80
81
|
function clipWithEllipsis(value, width) {
|
|
81
82
|
if (visualWidth(value) <= width)
|
|
82
83
|
return value;
|
|
@@ -88,7 +89,9 @@ function fitColumns(columns, 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 ?? '';
|
|
@@ -113,7 +116,7 @@ export function renderMenuOption(option, selected, columns = menuColumns([option
|
|
|
113
116
|
const prefixes = [`${space.indent}${marker} `, `${marker} `, marker, ''];
|
|
114
117
|
const prefix = prefixes.find((candidate) => visualWidth(candidate) < width) ?? '';
|
|
115
118
|
const continuation = ' '.repeat(visualWidth(prefix));
|
|
116
|
-
const contentWidth = Math.max(1, width - visualWidth(prefix));
|
|
119
|
+
const contentWidth = Math.max(1, bodyEdge(width) - visualWidth(prefix));
|
|
117
120
|
const cells = optionCells(option, columns, contentWidth);
|
|
118
121
|
const style = selected ? type.active : option.dim ? type.hint : type.body;
|
|
119
122
|
const hint = cells.hint ? ` ${type.hint(cells.hint)}` : '';
|
package/dist/core/logo.js
CHANGED
|
@@ -4,11 +4,12 @@ import { dirname, join } from 'path';
|
|
|
4
4
|
import chalk from 'chalk';
|
|
5
5
|
import { useUnicodeIcons } from './icons.js';
|
|
6
6
|
import { APP_INFO } from '../config/data.js';
|
|
7
|
-
import { typeReveal, materializeBraille } from './motion.js';
|
|
8
|
-
import { brandGradient as brand, c } from './theme.js';
|
|
7
|
+
import { typeReveal, materializeBraille, sleep } from './motion.js';
|
|
8
|
+
import { brandGradient as brand, c, frameLeft, space } from './theme.js';
|
|
9
9
|
import { visualWidth } from './text.js';
|
|
10
10
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
11
11
|
const TAGLINE = 'To be at the intersection of technology and liberal arts.';
|
|
12
|
+
const FINAL_FRAME_MS = 400;
|
|
12
13
|
function readArt(file) {
|
|
13
14
|
try {
|
|
14
15
|
return readFileSync(join(__dirname, '../logo', file), 'utf-8').replace(/\s+$/, '');
|
|
@@ -53,6 +54,16 @@ export function buildLogoLines() {
|
|
|
53
54
|
'',
|
|
54
55
|
];
|
|
55
56
|
}
|
|
57
|
+
export function startupOffset(cols, width) {
|
|
58
|
+
if (cols === undefined)
|
|
59
|
+
return 0;
|
|
60
|
+
return Math.max(0, Math.min(frameLeft(cols) + space.indent.length, cols - width));
|
|
61
|
+
}
|
|
62
|
+
function indentBlock(text, cols) {
|
|
63
|
+
const lines = text.split('\n');
|
|
64
|
+
const pad = ' '.repeat(startupOffset(cols, Math.max(...lines.map(visualWidth))));
|
|
65
|
+
return lines.map((line) => pad + line).join('\n');
|
|
66
|
+
}
|
|
56
67
|
function skipOnKeypress() {
|
|
57
68
|
const controller = new AbortController();
|
|
58
69
|
const stdin = process.stdin;
|
|
@@ -84,15 +95,22 @@ export async function runStartup() {
|
|
|
84
95
|
const art = loadArt();
|
|
85
96
|
if (!startupFitsTerminal(process.stdout.rows, process.stdout.columns, art))
|
|
86
97
|
return;
|
|
98
|
+
const cols = process.stdout.columns;
|
|
87
99
|
const color = !process.env['NO_COLOR'];
|
|
88
100
|
const skip = skipOnKeypress();
|
|
89
101
|
process.stdout.write('\n');
|
|
90
102
|
try {
|
|
91
|
-
await materializeBraille(art, (s) => paint(s, color), {
|
|
92
|
-
paintProgress: (s) => (color ? c.brand(s) : s),
|
|
103
|
+
await materializeBraille(art, (s) => indentBlock(paint(s, color), cols), {
|
|
104
|
+
paintProgress: (s) => indentBlock(color ? c.brand(s) : s, cols),
|
|
93
105
|
signal: skip.signal,
|
|
94
106
|
});
|
|
95
|
-
await typeReveal([
|
|
107
|
+
await typeReveal([
|
|
108
|
+
'',
|
|
109
|
+
indentBlock(color ? brand(TAGLINE) : TAGLINE, cols),
|
|
110
|
+
indentBlock(chalk.dim(`@nbtca/prompt v${APP_INFO.version}`), cols),
|
|
111
|
+
'',
|
|
112
|
+
], { signal: skip.signal });
|
|
113
|
+
await sleep(FINAL_FRAME_MS, skip.signal);
|
|
96
114
|
}
|
|
97
115
|
finally {
|
|
98
116
|
skip.release();
|
package/dist/core/text.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { bodyEdge } from './theme.js';
|
|
1
2
|
const GRAPHEME_SEGMENTER = new Intl.Segmenter(undefined, { granularity: 'grapheme' });
|
|
2
3
|
const MARK_RE = /^\p{Mark}$/u;
|
|
3
4
|
const EMOJI_PRESENTATION_RE = /\p{Emoji_Presentation}/u;
|
|
@@ -212,8 +213,8 @@ function renderWrappedSegment(tokens, start, end, activeSgr, activeOsc8) {
|
|
|
212
213
|
const osc8AtEnd = advanceOsc8(activeOsc8, tokens, start, end);
|
|
213
214
|
return osc8AtEnd ? `${withReset}${OSC8_CLOSE}` : withReset;
|
|
214
215
|
}
|
|
215
|
-
const NO_LINE_START = /^[。.、,;:?!)]}〉》」』】〕・ー~…‥%‰°℃,.;:?!)\]}
|
|
216
|
-
const NO_LINE_END = /^[([{〈《「『【〔([{
|
|
216
|
+
const NO_LINE_START = /^[。.、,;:?!)]}〉》」』】〕・ー~…‥%‰°℃,.;:?!)\]}>”’]$/u;
|
|
217
|
+
const NO_LINE_END = /^[([{〈《「『【〔([{<“‘]$/u;
|
|
217
218
|
function visibleAt(tokens, index) {
|
|
218
219
|
const token = tokens[index];
|
|
219
220
|
return token && !token.sgr && token.width > 0 ? token : undefined;
|
|
@@ -318,17 +319,8 @@ export function wrapAnsiToVisualWidth(str, maxWidth, continuationWidth = maxWidt
|
|
|
318
319
|
}
|
|
319
320
|
export function wrapAnsiWithIndent(str, maxWidth, preferredIndent = '') {
|
|
320
321
|
const width = Number.isFinite(maxWidth)
|
|
321
|
-
? Math.max(1, Math.floor(maxWidth))
|
|
322
|
+
? bodyEdge(Math.max(1, Math.floor(maxWidth)))
|
|
322
323
|
: Number.POSITIVE_INFINITY;
|
|
323
|
-
const
|
|
324
|
-
|
|
325
|
-
let indent = indentWidth >= width || (contentWidth > width - indentWidth && contentWidth <= width)
|
|
326
|
-
? ''
|
|
327
|
-
: preferredIndent;
|
|
328
|
-
let lines = wrapAnsiToVisualWidth(str, Math.max(1, width - visualWidth(indent)));
|
|
329
|
-
if (indent && lines.some((line) => visualWidth(indent + line) > width)) {
|
|
330
|
-
indent = '';
|
|
331
|
-
lines = wrapAnsiToVisualWidth(str, width);
|
|
332
|
-
}
|
|
333
|
-
return lines.map((line) => `${indent}${line}`);
|
|
324
|
+
const indent = visualWidth(preferredIndent) + 2 <= width ? preferredIndent : '';
|
|
325
|
+
return wrapAnsiToVisualWidth(str, Math.max(1, width - visualWidth(indent))).map((line) => `${indent}${line}`);
|
|
334
326
|
}
|
package/dist/core/theme.js
CHANGED
|
@@ -64,6 +64,16 @@ export const MAX_FRAME_COLS = 120;
|
|
|
64
64
|
export const space = {
|
|
65
65
|
indent: ' ',
|
|
66
66
|
};
|
|
67
|
+
export function frameWidth(cols) {
|
|
68
|
+
return Math.min(cols, MAX_FRAME_COLS);
|
|
69
|
+
}
|
|
70
|
+
export function frameLeft(cols) {
|
|
71
|
+
return Math.floor((cols - frameWidth(cols)) / 2);
|
|
72
|
+
}
|
|
73
|
+
const RIGHT_MARGIN_MIN_COLS = 40;
|
|
74
|
+
export function bodyEdge(cols) {
|
|
75
|
+
return cols >= RIGHT_MARGIN_MIN_COLS ? cols - space.indent.length : cols;
|
|
76
|
+
}
|
|
67
77
|
export const type = {
|
|
68
78
|
heading: (s) => chalk.bold(s),
|
|
69
79
|
label: (s) => s,
|
package/dist/features/about.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
2
|
import { APP_INFO, URLS } from '../config/data.js';
|
|
3
3
|
import { note } from '../core/components/note.js';
|
|
4
|
-
import { pickIcon } from '../core/icons.js';
|
|
5
4
|
import { padEndV } from '../core/text.js';
|
|
6
5
|
import { t } from '../i18n/index.js';
|
|
7
6
|
export function showAbout() {
|
|
@@ -17,7 +16,8 @@ export function showAbout() {
|
|
|
17
16
|
link(trans.about.website, URLS.homepage),
|
|
18
17
|
link(trans.about.email, URLS.email),
|
|
19
18
|
'',
|
|
20
|
-
row(trans.about.license,
|
|
19
|
+
row(trans.about.license, 'MIT'),
|
|
20
|
+
row(trans.about.author, 'm1ngsama'),
|
|
21
21
|
].join('\n');
|
|
22
22
|
note(content, trans.about.title);
|
|
23
23
|
}
|