@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.
@@ -6,8 +6,9 @@ import { setVimKeysActive } from '../../core/vim-keys.js';
6
6
  import { pickIcon } from '../../core/icons.js';
7
7
  import { glyph } from '../../core/theme.js';
8
8
  import { fmt, getCurrentLanguage, t } from '../../i18n/index.js';
9
- import { sanitizeTerminalLine, truncate } from '../../core/text.js';
10
- import { localizeDocSections, fetchSections, peekSections, fetchDocMetadata, fetchSectionMetadata, peekListedDocs, searchDocuments, getArchivedGroups, displayDocTitle, loadDocForReader, openDocsInBrowser, docsUrlFromPath, clearDocsCache, } from '../../features/docs.js';
9
+ import { sanitizeTerminalLine } from '../../core/text.js';
10
+ import { localizeDocSections, fetchSections, peekSections, fetchDocMetadata, fetchSectionMetadata, peekListedDocs, searchDocuments, getArchivedGroups, displayDocTitle, loadDocForReader, openDocsInBrowser, docsUrlFromPath, clearDocsCache, withFileNameTitle, } from '../../features/docs.js';
11
+ import { launchBrowserUrl } from '../../features/links.js';
11
12
  let state = { mode: 'loading' };
12
13
  let sections = [];
13
14
  let archivedGroups = new Map();
@@ -17,6 +18,7 @@ let loadedLanguage = null;
17
18
  let currentSectionKey = null;
18
19
  let currentArchivedGroupKey = null;
19
20
  let currentSearchResults = [];
21
+ let currentSearchQuery = '';
20
22
  let sectionsRequestId = 0;
21
23
  let metadataRequestId = 0;
22
24
  let searchRequestId = 0;
@@ -26,7 +28,6 @@ let readerPrevState = null;
26
28
  let readerLoadingPrevState = null;
27
29
  let readerRequestId = 0;
28
30
  let lifecycleGeneration = 0;
29
- const DOC_HINT_WIDTH = 44;
30
31
  function isLifecycleActive(ctx, generation) {
31
32
  return generation === lifecycleGeneration && ctx.signal?.aborted !== true;
32
33
  }
@@ -40,10 +41,10 @@ function backLabel() {
40
41
  return t().common.back;
41
42
  }
42
43
  function optionalHint(hint) {
43
- return hint === undefined ? {} : { hint };
44
+ return hint ? { hint, hintColumn: true } : {};
44
45
  }
45
- function docHint(value) {
46
- return value ? truncate(value, DOC_HINT_WIDTH) : undefined;
46
+ function docLabel(doc) {
47
+ return doc.title ? { label: doc.title } : { label: pickIcon('…', '...'), dim: true };
47
48
  }
48
49
  function withoutReaderLinksField(value) {
49
50
  const next = { ...value };
@@ -55,35 +56,34 @@ function withoutErrorMessage(value) {
55
56
  delete next.errorMessage;
56
57
  return next;
57
58
  }
58
- async function runBrowserOpen(ctx, path) {
59
+ async function openBrowserFromView(ctx, path, generation = lifecycleGeneration) {
60
+ await openUrlFromView(ctx, docsUrlFromPath(path), () => openDocsInBrowser(path, ctx.signal), generation);
61
+ }
62
+ async function openUrlFromView(ctx, url, open, generation = lifecycleGeneration) {
59
63
  let opened;
60
64
  await ctx.runClassic(async () => {
61
- opened =
62
- path === undefined
63
- ? await openDocsInBrowser(undefined, ctx.signal)
64
- : await openDocsInBrowser(path, ctx.signal);
65
+ opened = await open();
65
66
  });
66
- return opened;
67
- }
68
- async function openBrowserFromView(ctx, path, generation = lifecycleGeneration) {
69
- const opened = await runBrowserOpen(ctx, path);
70
67
  if (!isLifecycleActive(ctx, generation) || opened === true)
71
68
  return;
72
- const url = docsUrlFromPath(path);
73
69
  state = {
74
70
  ...state,
75
- errorMessage: sanitizeTerminalLine(`${t().docs.browserError}. ${fmt(t().links.openManually, { url })}`),
71
+ errorMessage: sanitizeTerminalLine(fmt(t().docs.browserErrorManual, { url })),
76
72
  };
77
73
  ctx.rerender();
78
74
  }
75
+ function countHints(counts) {
76
+ const width = Math.max(0, ...counts.map((count) => String(count).length));
77
+ return counts.map((count) => String(count).padStart(width));
78
+ }
79
79
  function buildSectionsField() {
80
80
  const trans = t();
81
- const countWidth = Math.max(0, ...sections.map((sec) => String(sec.count).length));
81
+ const counts = countHints(sections.map((sec) => sec.count));
82
82
  const options = [
83
- ...sections.map((sec) => ({
83
+ ...sections.map((sec, index) => ({
84
84
  value: sec.key,
85
85
  label: sec.label,
86
- hint: String(sec.count).padStart(countWidth),
86
+ hint: counts[index] ?? '',
87
87
  })),
88
88
  { value: '__search__', label: trans.docs.searchPrompt },
89
89
  { value: '__refresh__', label: trans.docs.refreshCache },
@@ -100,8 +100,8 @@ function buildFilesField(section, maxVisible, initialIndex = 0) {
100
100
  ...(index ? [{ value: index.path, label: trans.docs.overviewLabel }] : []),
101
101
  ...files.map((file) => ({
102
102
  value: file.path,
103
- label: displayDocTitle(file.name, file.title),
104
- ...optionalHint(docHint(file.summary)),
103
+ ...docLabel(file),
104
+ ...optionalHint(file.summary),
105
105
  })),
106
106
  { value: '__back__', label: backLabel() },
107
107
  ];
@@ -120,8 +120,9 @@ function buildArchivedGroupsField(groups, maxVisible, initialIndex = 0) {
120
120
  return 1;
121
121
  return a.localeCompare(b);
122
122
  });
123
+ const counts = countHints(sortedKeys.map((k) => groups.get(k)?.length ?? 0));
123
124
  const options = [
124
- ...sortedKeys.map((k) => ({ value: k, label: k, hint: String(groups.get(k)?.length ?? 0) })),
125
+ ...sortedKeys.map((k, index) => ({ value: k, label: k, hint: counts[index] ?? '' })),
125
126
  { value: '__back__', label: backLabel() },
126
127
  ];
127
128
  return new ListField({ title: trans.docs.categoryArchived, options, maxVisible, initialIndex });
@@ -134,16 +135,16 @@ function buildArchivedFilesField(groupKey, groupFiles, maxVisible, initialIndex
134
135
  const sub = f.path.split('/').slice(2, -1).join('/');
135
136
  return {
136
137
  value: f.path,
137
- label: displayDocTitle(f.name, f.title),
138
- ...optionalHint(docHint(subDirs.size > 1
139
- ? [sanitizeTerminalLine(sub), f.summary].filter(Boolean).join(' · ')
140
- : f.summary)),
138
+ ...docLabel(f),
139
+ ...optionalHint(subDirs.size > 1
140
+ ? [sanitizeTerminalLine(sub), f.summary].filter(Boolean).join(` ${glyph.sep()} `)
141
+ : f.summary),
141
142
  };
142
143
  }),
143
144
  { value: '__back__', label: backLabel() },
144
145
  ];
145
146
  return new ListField({
146
- title: `${trans.docs.categoryArchived} · ${groupKey}`,
147
+ title: `${trans.docs.categoryArchived} ${glyph.sep()} ${groupKey}`,
147
148
  options,
148
149
  maxVisible,
149
150
  initialIndex,
@@ -152,7 +153,14 @@ function buildArchivedFilesField(groupKey, groupFiles, maxVisible, initialIndex
152
153
  function buildReaderLinksField(links, maxVisible, initialIndex = 0) {
153
154
  const trans = t();
154
155
  const options = [
155
- ...links.map((l) => ({ value: l.href, label: l.text })),
156
+ ...links.map((l) => {
157
+ const address = l.external ? l.href.replace(/^https?:\/\//i, '').replace(/\/$/, '') : '';
158
+ return {
159
+ value: l.href,
160
+ label: l.text,
161
+ ...optionalHint(address === l.text ? undefined : address),
162
+ };
163
+ }),
156
164
  { value: '__back__', label: backLabel() },
157
165
  ];
158
166
  return new ListField({ title: trans.docs.readerLinksTitle, options, maxVisible, initialIndex });
@@ -163,15 +171,25 @@ function buildSearchResultsField(matches, maxVisible, initialIndex = 0) {
163
171
  ...matches.map((result) => ({
164
172
  value: result.path,
165
173
  label: displayDocTitle(result.name, result.title),
166
- ...optionalHint(docHint(result.excerpt ||
174
+ ...optionalHint(result.excerpt ||
167
175
  result.summary ||
168
176
  (result.path.includes('/')
169
177
  ? sanitizeTerminalLine(result.path.split('/').slice(0, -1).join('/'))
170
- : undefined))),
178
+ : undefined)),
179
+ hintFocus: currentSearchQuery,
171
180
  })),
172
181
  { value: '__back__', label: backLabel() },
173
182
  ];
174
- return new ListField({ title: trans.docs.chooseDoc, options, maxVisible, initialIndex });
183
+ return new ListField({
184
+ title: fmt(trans.docs.searchResultsTitle, {
185
+ query: currentSearchQuery,
186
+ count: matches.length,
187
+ sep: glyph.sep(),
188
+ }),
189
+ options,
190
+ maxVisible,
191
+ initialIndex,
192
+ });
175
193
  }
176
194
  function relocalizeStateFields(value, maxVisible) {
177
195
  if (value.mode === 'sections') {
@@ -218,6 +236,19 @@ function goToSections() {
218
236
  currentSearchResults = [];
219
237
  state = { mode: 'sections', sectionsField: buildSectionsField(), stale };
220
238
  }
239
+ function showLoadError() {
240
+ const trans = t();
241
+ state = {
242
+ mode: 'error',
243
+ errorMessage: trans.docs.offlineError,
244
+ errorField: new ListField({
245
+ options: [
246
+ { value: '__retry__', label: trans.docs.retryLoad },
247
+ { value: '__browser__', label: trans.docs.openBrowser },
248
+ ],
249
+ }),
250
+ };
251
+ }
221
252
  function replaceSection(section) {
222
253
  sections = sections.map((current) => (current.key === section.key ? section : current));
223
254
  }
@@ -229,37 +260,41 @@ async function openSectionFiles(ctx, section) {
229
260
  currentSectionKey = section.key;
230
261
  const stored = peekListedDocs(section.files);
231
262
  const known = { ...section, files: stored.docs };
232
- state = { mode: 'files', filesField: buildFilesField(known, computeMaxVisible(ctx.bodyRows)) };
263
+ const isCurrent = () => isLifecycleActive(ctx, generation) &&
264
+ requestId === metadataRequestId &&
265
+ state.mode === 'files' &&
266
+ currentSectionKey === section.key;
267
+ const show = (value, extra = {}) => {
268
+ state = {
269
+ mode: 'files',
270
+ filesField: buildFilesField(value, computeMaxVisible(ctx.bodyRows), state.filesField?.selectedIndex),
271
+ ...extra,
272
+ };
273
+ };
274
+ show(known);
233
275
  if (stored.complete) {
234
276
  replaceSection(known);
235
277
  return;
236
278
  }
237
279
  ctx.rerender();
238
280
  try {
239
- const hydrated = await fetchSectionMetadata(section, ctx.signal);
240
- if (!isLifecycleActive(ctx, generation) ||
241
- requestId !== metadataRequestId ||
242
- state.mode !== 'files' ||
243
- currentSectionKey !== section.key)
281
+ const hydrated = await fetchSectionMetadata(section, ctx.signal, (index, doc) => {
282
+ if (!isCurrent() || known.files[index]?.title)
283
+ return;
284
+ known.files[index] = doc;
285
+ show(known);
286
+ ctx.rerender();
287
+ });
288
+ if (!isCurrent())
244
289
  return;
245
290
  const localized = localizeDocSections([hydrated], t())[0] ?? hydrated;
246
291
  replaceSection(localized);
247
- state = {
248
- mode: 'files',
249
- filesField: buildFilesField(localized, computeMaxVisible(ctx.bodyRows), state.filesField?.selectedIndex),
250
- };
292
+ show(localized);
251
293
  }
252
294
  catch {
253
- if (!isLifecycleActive(ctx, generation) ||
254
- requestId !== metadataRequestId ||
255
- state.mode !== 'files' ||
256
- currentSectionKey !== section.key)
295
+ if (!isCurrent())
257
296
  return;
258
- state = {
259
- mode: 'files',
260
- filesField: buildFilesField(section, computeMaxVisible(ctx.bodyRows)),
261
- errorMessage: t().docs.loadError,
262
- };
297
+ show({ ...known, files: known.files.map(withFileNameTitle) }, { errorMessage: t().docs.loadError });
263
298
  }
264
299
  if (isLifecycleActive(ctx, generation))
265
300
  ctx.rerender();
@@ -271,39 +306,40 @@ async function openArchivedFiles(ctx, groupKey, groupFiles) {
271
306
  const requestId = ++metadataRequestId;
272
307
  currentArchivedGroupKey = groupKey;
273
308
  const stored = peekListedDocs(groupFiles);
274
- state = {
275
- mode: 'archivedFiles',
276
- archivedFilesField: buildArchivedFilesField(groupKey, stored.docs, computeMaxVisible(ctx.bodyRows)),
309
+ const isCurrent = () => isLifecycleActive(ctx, generation) &&
310
+ requestId === metadataRequestId &&
311
+ state.mode === 'archivedFiles' &&
312
+ currentArchivedGroupKey === groupKey;
313
+ const show = (files, extra = {}) => {
314
+ state = {
315
+ mode: 'archivedFiles',
316
+ archivedFilesField: buildArchivedFilesField(groupKey, files, computeMaxVisible(ctx.bodyRows), state.archivedFilesField?.selectedIndex),
317
+ ...extra,
318
+ };
277
319
  };
320
+ show(stored.docs);
278
321
  if (stored.complete) {
279
322
  archivedGroups.set(groupKey, stored.docs);
280
323
  return;
281
324
  }
282
325
  ctx.rerender();
283
326
  try {
284
- const hydrated = await fetchDocMetadata(groupFiles, ctx.signal);
285
- if (!isLifecycleActive(ctx, generation) ||
286
- requestId !== metadataRequestId ||
287
- state.mode !== 'archivedFiles' ||
288
- currentArchivedGroupKey !== groupKey)
327
+ const hydrated = await fetchDocMetadata(groupFiles, ctx.signal, (index, doc) => {
328
+ if (!isCurrent() || stored.docs[index]?.title)
329
+ return;
330
+ stored.docs[index] = doc;
331
+ show(stored.docs);
332
+ ctx.rerender();
333
+ });
334
+ if (!isCurrent())
289
335
  return;
290
336
  archivedGroups.set(groupKey, hydrated);
291
- state = {
292
- mode: 'archivedFiles',
293
- archivedFilesField: buildArchivedFilesField(groupKey, hydrated, computeMaxVisible(ctx.bodyRows), state.archivedFilesField?.selectedIndex),
294
- };
337
+ show(hydrated);
295
338
  }
296
339
  catch {
297
- if (!isLifecycleActive(ctx, generation) ||
298
- requestId !== metadataRequestId ||
299
- state.mode !== 'archivedFiles' ||
300
- currentArchivedGroupKey !== groupKey)
340
+ if (!isCurrent())
301
341
  return;
302
- state = {
303
- mode: 'archivedFiles',
304
- archivedFilesField: buildArchivedFilesField(groupKey, groupFiles, computeMaxVisible(ctx.bodyRows)),
305
- errorMessage: t().docs.loadError,
306
- };
342
+ show(stored.docs.map(withFileNameTitle), { errorMessage: t().docs.loadError });
307
343
  }
308
344
  if (isLifecycleActive(ctx, generation))
309
345
  ctx.rerender();
@@ -316,9 +352,15 @@ async function runSearch(ctx, query) {
316
352
  state = { mode: 'searchLoading' };
317
353
  ctx.rerender();
318
354
  try {
319
- const matches = await searchDocuments(query, ctx.signal);
355
+ const matches = await searchDocuments(query, ctx.signal, (done, total) => {
356
+ if (!isLifecycleActive(ctx, generation) || requestId !== searchRequestId)
357
+ return;
358
+ state = { mode: 'searchLoading', searchProgress: { done, total } };
359
+ ctx.rerender();
360
+ });
320
361
  if (!isLifecycleActive(ctx, generation) || requestId !== searchRequestId)
321
362
  return;
363
+ currentSearchQuery = query;
322
364
  currentSearchResults = matches;
323
365
  state = {
324
366
  mode: 'searchResults',
@@ -380,6 +422,25 @@ function enterReaderFrom(ctx, path) {
380
422
  readerCurrentPath = null;
381
423
  void openInReader(ctx, path, false);
382
424
  }
425
+ function reloadDocs(ctx) {
426
+ clearDocsCache();
427
+ sectionsRequestId++;
428
+ metadataRequestId++;
429
+ searchRequestId++;
430
+ loaded = false;
431
+ loadedLanguage = null;
432
+ sections = [];
433
+ archivedGroups = new Map();
434
+ currentSectionKey = null;
435
+ currentArchivedGroupKey = null;
436
+ currentSearchResults = [];
437
+ readerCurrentPath = null;
438
+ readerNavStack = [];
439
+ readerPrevState = null;
440
+ readerLoadingPrevState = null;
441
+ readerRequestId++;
442
+ void docsView.load(ctx);
443
+ }
383
444
  export const docsView = {
384
445
  id: 'docs',
385
446
  title: t().menu.docs,
@@ -436,7 +497,7 @@ export const docsView = {
436
497
  state = { ...state, stale };
437
498
  }
438
499
  else {
439
- state = { mode: 'error', errorMessage: t().docs.loadError };
500
+ showLoadError();
440
501
  }
441
502
  }
442
503
  if (isLifecycleActive(ctx, generation))
@@ -515,19 +576,22 @@ export const docsView = {
515
576
  state.mode === 'archivedGroups' ||
516
577
  state.mode === 'archivedFiles' ||
517
578
  state.mode === 'searchResults' ||
579
+ (state.mode === 'error' && state.errorField !== undefined) ||
518
580
  (state.mode === 'reader' && state.readerLinksField !== undefined));
519
581
  },
520
582
  footerHint(tabCount, cols = Number.POSITIVE_INFINITY) {
521
583
  if (state.mode === 'search')
522
584
  return captureFooterHint(cols);
523
- if (state.mode === 'loading' || state.mode === 'searchLoading' || state.mode === 'error')
585
+ if (state.mode === 'loading' ||
586
+ state.mode === 'searchLoading' ||
587
+ (state.mode === 'error' && !state.errorField))
524
588
  return passiveFooterHint(tabCount, cols);
525
589
  if (state.mode === 'readerLoading') {
526
590
  return fitFooterHint(cols, `${digitTabHint(tabCount)}q ${t().menu.hintQuit}`, `${digitTabHint(tabCount)}q`, 'q');
527
591
  }
528
592
  if (state.mode === 'reader' && !state.readerLinksField) {
529
593
  const trans = t();
530
- const dot = pickIcon('·', '-');
594
+ const dot = glyph.sep();
531
595
  const hasLinks = (state.readerLinks?.length ?? 0) > 0;
532
596
  const linkHint = hasLinks ? `f ${trans.docs.readerLinksHint} ${dot} ` : '';
533
597
  const pageHint = `${glyph.updown()} PgUp/PgDn ${dot} `;
@@ -611,23 +675,7 @@ export const docsView = {
611
675
  return;
612
676
  }
613
677
  if (result.selected === '__refresh__') {
614
- clearDocsCache();
615
- sectionsRequestId++;
616
- metadataRequestId++;
617
- searchRequestId++;
618
- loaded = false;
619
- loadedLanguage = null;
620
- sections = [];
621
- archivedGroups = new Map();
622
- currentSectionKey = null;
623
- currentArchivedGroupKey = null;
624
- currentSearchResults = [];
625
- readerCurrentPath = null;
626
- readerNavStack = [];
627
- readerPrevState = null;
628
- readerLoadingPrevState = null;
629
- readerRequestId++;
630
- void docsView.load(ctx);
678
+ reloadDocs(ctx);
631
679
  return;
632
680
  }
633
681
  if (result.selected === '__browser__') {
@@ -726,8 +774,15 @@ export const docsView = {
726
774
  state = withoutReaderLinksField(state);
727
775
  return;
728
776
  }
729
- if (result.selected)
777
+ const link = state.readerLinks?.find((candidate) => candidate.href === result.selected);
778
+ if (link?.external) {
779
+ const href = link.href;
780
+ state = withoutReaderLinksField(state);
781
+ void openUrlFromView(ctx, href, () => launchBrowserUrl(href));
782
+ }
783
+ else if (result.selected) {
730
784
  void openInReader(ctx, result.selected, true);
785
+ }
731
786
  return;
732
787
  }
733
788
  if (key === 'f' && (state.readerLinks?.length ?? 0) > 0) {
@@ -743,7 +798,14 @@ export const docsView = {
743
798
  }
744
799
  return;
745
800
  }
746
- case 'error':
801
+ case 'error': {
802
+ const result = state.errorField?.handleKey(key);
803
+ if (result?.selected === '__retry__')
804
+ reloadDocs(ctx);
805
+ if (result?.selected === '__browser__')
806
+ void openBrowserFromView(ctx);
807
+ return;
808
+ }
747
809
  case 'loading':
748
810
  case 'readerLoading':
749
811
  case 'searchLoading':
@@ -10,6 +10,15 @@ function wrappedIndentedLines(label, cols, style) {
10
10
  return wrapAnsiWithIndent(style(label), cols ?? Number.POSITIVE_INFINITY, space.indent);
11
11
  }
12
12
  const EXPANDED_HUB_MIN_BODY_ROWS = 29;
13
+ export function hubShowsHeatmap(bodyRows, buckets = []) {
14
+ return bodyRows >= EXPANDED_HUB_MIN_BODY_ROWS && buckets.length > 0;
15
+ }
16
+ function heatmapLines(buckets, now, cols) {
17
+ return renderHeatmap(buckets, now, {
18
+ color: true,
19
+ ...(cols === undefined ? {} : { cols }),
20
+ }).split('\n');
21
+ }
13
22
  function renderHubBody(state, now, bodyRows, cols) {
14
23
  const trans = t();
15
24
  const lines = [];
@@ -22,13 +31,8 @@ function renderHubBody(state, now, bodyRows, cols) {
22
31
  if (banner)
23
32
  lines.push(...banner.split('\n'), '');
24
33
  const buckets = state.heatmapBuckets;
25
- if (bodyRows >= EXPANDED_HUB_MIN_BODY_ROWS && buckets && buckets.length > 0) {
26
- lines.push(...renderHeatmap(buckets, now, {
27
- color: true,
28
- ...(cols === undefined ? {} : { cols }),
29
- }).split('\n'));
30
- lines.push('');
31
- }
34
+ if (buckets && hubShowsHeatmap(bodyRows, buckets))
35
+ lines.push(...heatmapLines(buckets, now, cols), '');
32
36
  if (state.recentEvents && state.recentEvents.length > 0) {
33
37
  const activityHeading = wrappedIndentedLines(trans.calendar.recentActivity, cols, type.heading);
34
38
  const fieldRows = state.hubField
@@ -65,33 +69,36 @@ function renderHubBody(state, now, bodyRows, cols) {
65
69
  }
66
70
  export function renderEvents(state, now, bodyRows = 100, cols) {
67
71
  const trans = t();
72
+ const notice = state.stale ? offlineNotice(cols ?? Number.POSITIVE_INFINITY) : [];
68
73
  switch (state.mode) {
69
74
  case 'loading':
70
75
  return loadingLines(trans.calendar.loading, cols);
71
76
  case 'hub':
72
77
  return renderHubBody(state, now, bodyRows, cols);
73
78
  case 'heatmap':
74
- return state.heatmapBuckets && state.heatmapBuckets.length > 0
75
- ? renderHeatmap(state.heatmapBuckets, now, {
76
- color: true,
77
- ...(cols === undefined ? {} : { cols }),
78
- }).split('\n')
79
- : wrappedIndentedLines(trans.calendar.noEvents, cols, type.hint);
79
+ return [
80
+ ...notice,
81
+ ...(state.heatmapBuckets && state.heatmapBuckets.length > 0
82
+ ? heatmapLines(state.heatmapBuckets, now, cols)
83
+ : wrappedIndentedLines(trans.calendar.noEvents, cols, type.hint)),
84
+ ];
80
85
  case 'list': {
81
86
  if (!state.listField)
82
87
  return [];
83
- if (state.listNotice === undefined)
84
- return state.listField.render(bodyRows, cols);
85
- const context = [
86
- ...wrappedIndentedLines(state.listTitle ?? '', cols, type.heading),
87
- '',
88
- ...wrappedIndentedLines(state.listNotice, cols, type.hint),
89
- '',
90
- ];
88
+ const context = state.listNotice === undefined
89
+ ? notice
90
+ : [
91
+ ...notice,
92
+ ...wrappedIndentedLines(state.listTitle ?? '', cols, type.heading),
93
+ '',
94
+ ...wrappedIndentedLines(state.listNotice, cols, type.hint),
95
+ '',
96
+ ];
91
97
  return renderListFieldWithContext(context, state.listField, bodyRows, cols);
92
98
  }
93
99
  case 'detail': {
94
100
  const context = [
101
+ ...notice,
95
102
  ...wrappedIndentedLines(state.detailTitle ?? '', cols, type.heading),
96
103
  ...wrappedIndentedLines(state.detailMeta ?? '', cols, type.hint),
97
104
  '',
@@ -112,9 +119,20 @@ export function renderEvents(state, now, bodyRows = 100, cols) {
112
119
  : context;
113
120
  }
114
121
  case 'search':
115
- return state.searchField?.render(cols) ?? [];
116
- case 'error':
117
- return wrappedIndentedLines(state.errorMessage ?? trans.calendar.error, cols, type.hint);
122
+ return [...notice, ...(state.searchField?.render(cols) ?? [])];
123
+ case 'error': {
124
+ const context = [
125
+ ...wrappedIndentedLines(state.errorMessage ?? trans.calendar.error, cols, type.body),
126
+ ...wrappedIndentedLines(trans.calendar.errorHint, cols, type.hint),
127
+ '',
128
+ ];
129
+ if (state.errorField) {
130
+ return renderListFieldWithContext(context, state.errorField, bodyRows, cols);
131
+ }
132
+ return Number.isFinite(bodyRows)
133
+ ? context.slice(0, Math.max(0, Math.floor(bodyRows)))
134
+ : context;
135
+ }
118
136
  default:
119
137
  return [];
120
138
  }