@nbtca/prompt 1.5.22 → 1.5.24
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/ambient.js +98 -0
- package/dist/app/app.js +3 -2
- package/dist/app/chrome.js +6 -2
- package/dist/app/views/docs-render.js +23 -15
- package/dist/app/views/docs.js +3 -0
- package/dist/app/views/events-render.js +57 -21
- package/dist/app/views/events.js +62 -9
- package/dist/app/views/home.js +66 -31
- package/dist/app/views/schedule-render.js +9 -2
- package/dist/app/views/schedule.js +7 -1
- package/dist/app/views/settings-render.js +13 -2
- package/dist/app/views/settings.js +27 -1
- package/dist/art/bitmaps.js +76 -0
- package/dist/art/glyphs.js +101 -0
- package/dist/art/motifs.js +198 -0
- package/dist/art/noise.js +43 -0
- package/dist/art/planet.js +184 -0
- package/dist/art/scene.js +446 -0
- package/dist/config/preferences.js +8 -1
- package/dist/core/components/empty-state.js +50 -0
- package/dist/core/components/menu.js +2 -2
- package/dist/core/components/picture.js +18 -0
- package/dist/core/logo.js +65 -43
- package/dist/core/pixel-art-fine.js +157 -0
- package/dist/core/pixel-art.js +223 -0
- package/dist/core/theme.js +1 -1
- package/dist/features/calendar-heatmap.js +35 -10
- package/dist/features/calendar.js +2 -2
- package/dist/features/event-art.js +16 -0
- package/dist/features/schedule-view.js +10 -0
- package/dist/i18n/locales/en.json +14 -5
- package/dist/i18n/locales/zh.json +13 -4
- package/dist/logo/ascii-emblem-large.txt +26 -0
- package/dist/logo/ascii-emblem-medium.txt +19 -0
- package/dist/logo/ascii-emblem-small.txt +12 -0
- package/dist/logo/ascii-emblem-tiny.txt +9 -0
- package/package.json +4 -4
- package/dist/logo/ascii-logo.txt +0 -12
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { emblemLines } from '../core/logo.js';
|
|
2
|
+
import { padEndV, visualWidth } from '../core/text.js';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import { pictureMode, renderBitmap } from '../core/pixel-art.js';
|
|
5
|
+
import { mountainScene, scaleBitmap, shelfScene, skyScene } from '../art/scene.js';
|
|
6
|
+
import { teaCup } from '../art/motifs.js';
|
|
7
|
+
import { gasGiantLines, moonLines, planetSize } from '../art/planet.js';
|
|
8
|
+
import { space } from '../core/theme.js';
|
|
9
|
+
const GAP = 4;
|
|
10
|
+
const MIN_COLS = 30;
|
|
11
|
+
const MIN_ROWS = 7;
|
|
12
|
+
const MIN_PANORAMA_ROWS = 8;
|
|
13
|
+
const MAX_COLS = 130;
|
|
14
|
+
const TEA_COLS = 16;
|
|
15
|
+
const TEA_ROWS = 6;
|
|
16
|
+
const SCENE_GAMMA = 0.8;
|
|
17
|
+
const FINE = { x: 2, y: 4 };
|
|
18
|
+
const cache = new Map();
|
|
19
|
+
function remember(key, build) {
|
|
20
|
+
const hit = cache.get(key);
|
|
21
|
+
if (hit)
|
|
22
|
+
return hit;
|
|
23
|
+
const lines = build();
|
|
24
|
+
if (cache.size >= 8)
|
|
25
|
+
cache.delete(cache.keys().next().value ?? '');
|
|
26
|
+
cache.set(key, lines);
|
|
27
|
+
return lines;
|
|
28
|
+
}
|
|
29
|
+
/** A landscape that fills the given box of cells with Braille-fine pixels, or undefined when the box is too small. */
|
|
30
|
+
function scene(spec, cols, rows, now) {
|
|
31
|
+
if (spec.kind !== 'sky' && spec.kind !== 'mountain' && spec.kind !== 'shelf')
|
|
32
|
+
return undefined;
|
|
33
|
+
const width = Math.min(cols, MAX_COLS);
|
|
34
|
+
if (width < MIN_COLS || rows < MIN_ROWS)
|
|
35
|
+
return undefined;
|
|
36
|
+
const minute = Math.floor(now.getTime() / 300_000);
|
|
37
|
+
const key = [
|
|
38
|
+
spec.kind,
|
|
39
|
+
width,
|
|
40
|
+
rows,
|
|
41
|
+
minute,
|
|
42
|
+
spec.kind === 'mountain' ? spec.progress.toFixed(3) : '',
|
|
43
|
+
pictureMode(),
|
|
44
|
+
chalk.level,
|
|
45
|
+
].join('|');
|
|
46
|
+
return remember(key, () => {
|
|
47
|
+
const pixels = { width: width * FINE.x, height: rows * FINE.y };
|
|
48
|
+
const bitmap = spec.kind === 'sky'
|
|
49
|
+
? skyScene(pixels.width, pixels.height, now)
|
|
50
|
+
: spec.kind === 'mountain'
|
|
51
|
+
? mountainScene(pixels.width, pixels.height, spec.progress, spec.weeks, now)
|
|
52
|
+
: shelfScene(pixels.width, pixels.height);
|
|
53
|
+
return renderBitmap(bitmap, undefined, SCENE_GAMMA);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function compact(spec, cols, rows, now) {
|
|
57
|
+
if (spec.kind === 'emblem')
|
|
58
|
+
return emblemLines(cols, rows);
|
|
59
|
+
if (spec.kind === 'sky') {
|
|
60
|
+
if (spec.rest)
|
|
61
|
+
return cols < TEA_COLS || rows < TEA_ROWS ? undefined : teaCup(now.getTime());
|
|
62
|
+
return cols < MIN_COLS ? undefined : moonLines(planetSize(cols, rows), now);
|
|
63
|
+
}
|
|
64
|
+
if (spec.kind === 'planet') {
|
|
65
|
+
const size = planetSize(cols, rows);
|
|
66
|
+
return spec.style === 'moon' ? moonLines(size, now) : gasGiantLines(size);
|
|
67
|
+
}
|
|
68
|
+
if (spec.kind !== 'icon')
|
|
69
|
+
return undefined;
|
|
70
|
+
const factor = Math.min(Math.floor(cols / (spec.icon.rows[0]?.length ?? 1)), Math.floor((rows * 2) / spec.icon.rows.length), 3);
|
|
71
|
+
return factor >= 2 ? renderBitmap(scaleBitmap(spec.icon, factor)) : undefined;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Fills the empty space of a page: a full-width panorama underneath when enough rows are free,
|
|
75
|
+
* otherwise a picture to the right of the content, as large as the leftover space allows.
|
|
76
|
+
*/
|
|
77
|
+
export function withAmbient(body, spec, cols, bodyRows, now = new Date()) {
|
|
78
|
+
if (!spec || !Number.isFinite(cols) || !Number.isFinite(bodyRows))
|
|
79
|
+
return [...body];
|
|
80
|
+
const indent = visualWidth(space.indent);
|
|
81
|
+
const rows = Math.floor(bodyRows);
|
|
82
|
+
const below = rows - body.length - 1;
|
|
83
|
+
const panorama = scene(spec, cols - indent * 2, below, now);
|
|
84
|
+
if (panorama && below >= MIN_PANORAMA_ROWS) {
|
|
85
|
+
return [...body, '', ...panorama.map((line) => space.indent + line)];
|
|
86
|
+
}
|
|
87
|
+
const contentWidth = Math.max(0, ...body.map(visualWidth));
|
|
88
|
+
const width = cols - contentWidth - GAP - indent;
|
|
89
|
+
const side = Math.min(rows - 1, Math.round(Math.min(width, MAX_COLS) * 0.55));
|
|
90
|
+
const art = scene(spec, width, side, now) ?? compact(spec, width, rows - 1, now);
|
|
91
|
+
if (!art)
|
|
92
|
+
return [...body];
|
|
93
|
+
return Array.from({ length: Math.max(body.length, art.length) }, (_, index) => {
|
|
94
|
+
const left = body[index] ?? '';
|
|
95
|
+
const right = art[index];
|
|
96
|
+
return right === undefined ? left : `${padEndV(left, contentWidth + GAP)}${right}`;
|
|
97
|
+
});
|
|
98
|
+
}
|
package/dist/app/app.js
CHANGED
|
@@ -4,6 +4,7 @@ import { frameWidth } from '../core/theme.js';
|
|
|
4
4
|
import { isPrintableKey, KeyStreamDecoder, routeGlobalKey, } from './keys.js';
|
|
5
5
|
import { renderHeader, renderFooter, resolveChromeLayout } from './chrome.js';
|
|
6
6
|
import { homeView } from './views/home.js';
|
|
7
|
+
import { withAmbient } from './ambient.js';
|
|
7
8
|
import { scheduleView } from './views/schedule.js';
|
|
8
9
|
import { docsView } from './views/docs.js';
|
|
9
10
|
import { eventsView } from './views/events.js';
|
|
@@ -89,11 +90,11 @@ export async function runApp() {
|
|
|
89
90
|
const activeTab = tabs.find((tab) => tab.id === view);
|
|
90
91
|
const body = helpOpen
|
|
91
92
|
? renderHelp(activeTab?.title ?? '', active?.shortcuts?.() ?? [], tabs.length, cols)
|
|
92
|
-
: (active?.render(ctx) ?? []);
|
|
93
|
+
: withAmbient(active?.render(ctx) ?? [], active?.ambient?.(), cols, ctx.bodyRows);
|
|
93
94
|
const bodyScroll = !helpOpen && active?.capturesInput?.() ? Number.MAX_SAFE_INTEGER : scroll;
|
|
94
95
|
const height = computeBodyRows(rows, chrome.headerLines, chrome.footerLines);
|
|
95
96
|
lastBody = { length: body.length, height };
|
|
96
|
-
const footer = renderFooter(view, cols, tabs.length, helpOpen ? t().help.close : active?.footerHint?.(tabs.length, cols), chrome.footerLines, helpOpen || active?.scrollsBody?.() === true ? scrollPercent() : undefined);
|
|
97
|
+
const footer = renderFooter(view, cols, tabs.length, helpOpen ? t().help.close : active?.footerHint?.(tabs.length, cols, body.length > height), chrome.footerLines, helpOpen || active?.scrollsBody?.() === true ? scrollPercent() : undefined);
|
|
97
98
|
const lines = composeFrameLines(header, body, footer, rows, terminalCols, bodyScroll);
|
|
98
99
|
const patch = diffFrame(painted?.cols === terminalCols ? painted.lines : undefined, lines);
|
|
99
100
|
painted = { cols: terminalCols, lines };
|
package/dist/app/chrome.js
CHANGED
|
@@ -22,7 +22,7 @@ function renderRule(cols) {
|
|
|
22
22
|
const width = Number.isFinite(cols) ? Math.max(1, Math.floor(cols)) : 80;
|
|
23
23
|
const indent = visualWidth(space.indent) < width ? space.indent : '';
|
|
24
24
|
const ruleWidth = Math.max(1, bodyEdge(width) - visualWidth(indent));
|
|
25
|
-
return indent +
|
|
25
|
+
return indent + c.muted(glyph.rule().repeat(ruleWidth));
|
|
26
26
|
}
|
|
27
27
|
function renderTabs(views, active, cols) {
|
|
28
28
|
const dot = glyph.sep();
|
|
@@ -111,12 +111,16 @@ export function digitTabHint(tabCount) {
|
|
|
111
111
|
const dot = glyph.sep();
|
|
112
112
|
return tabCount > 1 ? `1-${tabCount} / Tab ${t().menu.hintTabs} ${dot} ` : '';
|
|
113
113
|
}
|
|
114
|
-
export function passiveFooterHint(tabCount, cols = Number.POSITIVE_INFINITY, canGoBack = true) {
|
|
114
|
+
export function passiveFooterHint(tabCount, cols = Number.POSITIVE_INFINITY, canGoBack = true, canScroll = false) {
|
|
115
115
|
const trans = t();
|
|
116
116
|
const dot = glyph.sep();
|
|
117
117
|
const compactTabs = tabCount > 1 ? `1-${tabCount}/Tab ${dot} ` : '';
|
|
118
118
|
const back = canGoBack ? `Esc ${trans.menu.hintBack} ${dot} ` : '';
|
|
119
119
|
const backKey = canGoBack ? `Esc ${dot} ` : '';
|
|
120
|
+
if (canScroll) {
|
|
121
|
+
const move = glyph.updown();
|
|
122
|
+
return fitFooterHint(cols, `${digitTabHint(tabCount)}${move} ${trans.help.scroll} ${dot} ${back}q ${trans.menu.hintQuit} ${dot} ${trans.help.hint}`, `${compactTabs}${move} ${dot} ${backKey}q ${dot} ?`, `${move} ${dot} ${backKey}q`, `${move} q`, 'q');
|
|
123
|
+
}
|
|
120
124
|
return fitFooterHint(cols, `${digitTabHint(tabCount)}${back}q ${trans.menu.hintQuit} ${dot} ${trans.help.hint}`, `${digitTabHint(tabCount)}${back}q ${trans.menu.hintQuit}`, `${compactTabs}${backKey}q ${dot} ?`, `${backKey}q ${dot} ?`, `${backKey}q`, 'q');
|
|
121
125
|
}
|
|
122
126
|
function interactiveFooterHint(tabCount, cols) {
|
|
@@ -4,6 +4,7 @@ import { renderListFieldWithContext } from '../fields/list-field.js';
|
|
|
4
4
|
import { offlineNotice } from '../chrome.js';
|
|
5
5
|
import { visualWidth, wrapAnsiWithIndent } from '../../core/text.js';
|
|
6
6
|
import { loadingLines } from '../../core/components/spinner.js';
|
|
7
|
+
import { emptyStateLines, loadingStateLines, offlineContext, } from '../../core/components/empty-state.js';
|
|
7
8
|
function hintLines(label, cols) {
|
|
8
9
|
return wrapAnsiWithIndent(type.hint(label), cols, space.indent);
|
|
9
10
|
}
|
|
@@ -36,10 +37,20 @@ function listFieldForState(state) {
|
|
|
36
37
|
}
|
|
37
38
|
export function renderDocs(state, cols = 80, bodyRows = Number.POSITIVE_INFINITY) {
|
|
38
39
|
const trans = t();
|
|
40
|
+
const errorContext = state.errorMessage ? [...hintLines(state.errorMessage, cols), ''] : [];
|
|
41
|
+
const emptyContext = state.mode === 'searchResults' && state.searchResultsEmpty
|
|
42
|
+
? [
|
|
43
|
+
...emptyStateLines('search', trans.docs.searchNoResults, cols, bodyRows -
|
|
44
|
+
errorContext.length -
|
|
45
|
+
(state.searchResultsField?.render(Number.POSITIVE_INFINITY, cols).length ?? 0) -
|
|
46
|
+
1),
|
|
47
|
+
'',
|
|
48
|
+
]
|
|
49
|
+
: [];
|
|
39
50
|
let lines;
|
|
40
51
|
switch (state.mode) {
|
|
41
52
|
case 'loading':
|
|
42
|
-
lines =
|
|
53
|
+
lines = loadingStateLines(trans.common.loading, cols, bodyRows);
|
|
43
54
|
break;
|
|
44
55
|
case 'sections': {
|
|
45
56
|
const context = state.stale ? offlineNotice(cols) : [];
|
|
@@ -52,7 +63,9 @@ export function renderDocs(state, cols = 80, bodyRows = Number.POSITIVE_INFINITY
|
|
|
52
63
|
break;
|
|
53
64
|
}
|
|
54
65
|
case 'files':
|
|
55
|
-
lines =
|
|
66
|
+
lines =
|
|
67
|
+
state.filesField?.render(bodyRows, cols) ??
|
|
68
|
+
loadingStateLines(trans.common.loading, cols, bodyRows);
|
|
56
69
|
break;
|
|
57
70
|
case 'archivedGroups':
|
|
58
71
|
lines = state.archivedGroupsField?.render(bodyRows, cols) ?? [];
|
|
@@ -60,7 +73,7 @@ export function renderDocs(state, cols = 80, bodyRows = Number.POSITIVE_INFINITY
|
|
|
60
73
|
case 'archivedFiles':
|
|
61
74
|
lines =
|
|
62
75
|
state.archivedFilesField?.render(bodyRows, cols) ??
|
|
63
|
-
|
|
76
|
+
loadingStateLines(trans.common.loading, cols, bodyRows);
|
|
64
77
|
break;
|
|
65
78
|
case 'search':
|
|
66
79
|
lines = state.searchField?.render(cols) ?? [];
|
|
@@ -72,11 +85,7 @@ export function renderDocs(state, cols = 80, bodyRows = Number.POSITIVE_INFINITY
|
|
|
72
85
|
break;
|
|
73
86
|
case 'searchResults':
|
|
74
87
|
lines = state.searchResultsField
|
|
75
|
-
? renderListFieldWithContext(
|
|
76
|
-
...(state.searchResultsEmpty
|
|
77
|
-
? [...hintLines(trans.docs.searchNoResults, cols), '']
|
|
78
|
-
: []),
|
|
79
|
-
], state.searchResultsField, bodyRows, cols)
|
|
88
|
+
? renderListFieldWithContext(emptyContext, state.searchResultsField, bodyRows, cols)
|
|
80
89
|
: [];
|
|
81
90
|
break;
|
|
82
91
|
case 'readerLoading':
|
|
@@ -88,11 +97,11 @@ export function renderDocs(state, cols = 80, bodyRows = Number.POSITIVE_INFINITY
|
|
|
88
97
|
: renderReader(state.readerRender ?? (() => []), cols);
|
|
89
98
|
break;
|
|
90
99
|
case 'error': {
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
100
|
+
const message = type.body(state.errorMessage ?? trans.docs.loadError);
|
|
101
|
+
const hint = hintLines(trans.docs.offlineHint, cols);
|
|
102
|
+
const plain = [...wrapAnsiWithIndent(message, cols, space.indent), ...hint, ''];
|
|
103
|
+
const fieldRows = state.errorField?.render(Number.POSITIVE_INFINITY, cols).length ?? 0;
|
|
104
|
+
const context = offlineContext(message, hint, plain, cols, bodyRows - fieldRows);
|
|
96
105
|
return state.errorField
|
|
97
106
|
? renderListFieldWithContext(context, state.errorField, bodyRows, cols)
|
|
98
107
|
: context;
|
|
@@ -100,12 +109,11 @@ export function renderDocs(state, cols = 80, bodyRows = Number.POSITIVE_INFINITY
|
|
|
100
109
|
}
|
|
101
110
|
if (!state.errorMessage)
|
|
102
111
|
return lines;
|
|
103
|
-
const errorContext = [...hintLines(state.errorMessage, cols), ''];
|
|
104
112
|
const listField = listFieldForState(state);
|
|
105
113
|
if (!listField)
|
|
106
114
|
return [...errorContext, ...lines];
|
|
107
115
|
const context = state.mode === 'searchResults' && state.searchResultsEmpty
|
|
108
|
-
? [...errorContext, ...
|
|
116
|
+
? [...errorContext, ...emptyContext]
|
|
109
117
|
: errorContext;
|
|
110
118
|
return renderListFieldWithContext(context, listField, bodyRows, cols);
|
|
111
119
|
}
|
package/dist/app/views/docs.js
CHANGED
|
@@ -521,6 +521,9 @@ export const docsView = {
|
|
|
521
521
|
state.readerLinksField?.setMaxVisible(maxVisible);
|
|
522
522
|
return renderDocs(state, ctx.size.cols, ctx.bodyRows);
|
|
523
523
|
},
|
|
524
|
+
ambient() {
|
|
525
|
+
return state.mode === 'sections' ? { kind: 'shelf' } : undefined;
|
|
526
|
+
},
|
|
524
527
|
isBusy() {
|
|
525
528
|
return (state.mode === 'loading' || state.mode === 'searchLoading' || state.mode === 'readerLoading');
|
|
526
529
|
},
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { type, space } from '../../core/theme.js';
|
|
2
|
-
import { t } from '../../i18n/index.js';
|
|
1
|
+
import { glyph, type, space } from '../../core/theme.js';
|
|
2
|
+
import { fmt, t } from '../../i18n/index.js';
|
|
3
3
|
import { renderListFieldWithContext } from '../fields/list-field.js';
|
|
4
4
|
import { offlineNotice } from '../chrome.js';
|
|
5
|
-
import { renderCountdownBanner, renderEventBriefLines, } from '../../features/calendar.js';
|
|
5
|
+
import { renderCountdownBanner, renderEventBriefLines, eventWhen, } from '../../features/calendar.js';
|
|
6
6
|
import { renderHeatmap } from '../../features/calendar-heatmap.js';
|
|
7
7
|
import { wrapAnsiWithIndent } from '../../core/text.js';
|
|
8
|
-
import {
|
|
8
|
+
import { pictureBeside } from '../../core/components/picture.js';
|
|
9
|
+
import { renderBitmap } from '../../core/pixel-art.js';
|
|
10
|
+
import { eventIcon } from '../../features/event-art.js';
|
|
11
|
+
import { emptyStateLines, loadingStateLines, offlineContext, } from '../../core/components/empty-state.js';
|
|
9
12
|
function wrappedIndentedLines(label, cols, style) {
|
|
10
13
|
return wrapAnsiWithIndent(style(label), cols ?? Number.POSITIVE_INFINITY, space.indent);
|
|
11
14
|
}
|
|
@@ -13,12 +16,31 @@ const EXPANDED_HUB_MIN_BODY_ROWS = 29;
|
|
|
13
16
|
export function hubShowsHeatmap(bodyRows, buckets = []) {
|
|
14
17
|
return bodyRows >= EXPANDED_HUB_MIN_BODY_ROWS && buckets.length > 0;
|
|
15
18
|
}
|
|
16
|
-
function heatmapLines(buckets, now, cols) {
|
|
19
|
+
function heatmapLines(buckets, now, cols, cursor) {
|
|
17
20
|
return renderHeatmap(buckets, now, {
|
|
18
21
|
color: true,
|
|
19
22
|
...(cols === undefined ? {} : { cols }),
|
|
23
|
+
...(cursor === undefined ? {} : { cursor }),
|
|
20
24
|
}).split('\n');
|
|
21
25
|
}
|
|
26
|
+
function heatmapDayLines(state, cols) {
|
|
27
|
+
if (state.heatmapCursor === undefined)
|
|
28
|
+
return [];
|
|
29
|
+
const trans = t();
|
|
30
|
+
const events = state.heatmapDay ?? [];
|
|
31
|
+
const heading = fmt(trans.calendar.heatmap.dayCount, {
|
|
32
|
+
date: state.heatmapCursor,
|
|
33
|
+
count: events.length,
|
|
34
|
+
sep: glyph.sep(),
|
|
35
|
+
});
|
|
36
|
+
return [
|
|
37
|
+
'',
|
|
38
|
+
...wrappedIndentedLines(heading, cols, type.heading),
|
|
39
|
+
...(events.length === 0
|
|
40
|
+
? wrappedIndentedLines(trans.calendar.heatmap.dayEmpty, cols, type.hint)
|
|
41
|
+
: events.flatMap((event) => wrappedIndentedLines(`${eventWhen(event)} ${glyph.sep()} ${event.title}`, cols, type.body))),
|
|
42
|
+
];
|
|
43
|
+
}
|
|
22
44
|
function renderHubBody(state, now, bodyRows, cols) {
|
|
23
45
|
const trans = t();
|
|
24
46
|
const lines = [];
|
|
@@ -57,10 +79,12 @@ function renderHubBody(state, now, bodyRows, cols) {
|
|
|
57
79
|
lines.push(...activityHeading, ...eventLines, '');
|
|
58
80
|
}
|
|
59
81
|
else if (!state.nextEvent) {
|
|
60
|
-
const notice = [...wrappedIndentedLines(trans.calendar.noEvents, cols, type.hint), ''];
|
|
61
82
|
const fieldRows = state.hubField?.render(Number.POSITIVE_INFINITY, cols).length ?? 0;
|
|
62
|
-
|
|
63
|
-
lines.
|
|
83
|
+
const notice = [
|
|
84
|
+
...emptyStateLines('calendar', trans.calendar.noEvents, cols, rows - lines.length - fieldRows - 1),
|
|
85
|
+
'',
|
|
86
|
+
];
|
|
87
|
+
lines.push(...notice);
|
|
64
88
|
}
|
|
65
89
|
if (state.hubField) {
|
|
66
90
|
return renderListFieldWithContext(lines, state.hubField, bodyRows, cols);
|
|
@@ -72,15 +96,18 @@ export function renderEvents(state, now, bodyRows = 100, cols) {
|
|
|
72
96
|
const notice = state.stale ? offlineNotice(cols ?? Number.POSITIVE_INFINITY) : [];
|
|
73
97
|
switch (state.mode) {
|
|
74
98
|
case 'loading':
|
|
75
|
-
return
|
|
99
|
+
return loadingStateLines(trans.calendar.loading, cols, bodyRows);
|
|
76
100
|
case 'hub':
|
|
77
101
|
return renderHubBody(state, now, bodyRows, cols);
|
|
78
102
|
case 'heatmap':
|
|
79
103
|
return [
|
|
80
104
|
...notice,
|
|
81
105
|
...(state.heatmapBuckets && state.heatmapBuckets.length > 0
|
|
82
|
-
?
|
|
83
|
-
|
|
106
|
+
? [
|
|
107
|
+
...heatmapLines(state.heatmapBuckets, now, cols, state.heatmapCursor),
|
|
108
|
+
...heatmapDayLines(state, cols),
|
|
109
|
+
]
|
|
110
|
+
: emptyStateLines('calendar', trans.calendar.noEvents, cols, bodyRows - notice.length)),
|
|
84
111
|
];
|
|
85
112
|
case 'list': {
|
|
86
113
|
if (!state.listField)
|
|
@@ -91,16 +118,19 @@ export function renderEvents(state, now, bodyRows = 100, cols) {
|
|
|
91
118
|
...notice,
|
|
92
119
|
...wrappedIndentedLines(state.listTitle ?? '', cols, type.heading),
|
|
93
120
|
'',
|
|
94
|
-
...
|
|
121
|
+
...emptyStateLines('calendar', state.listNotice, cols, bodyRows -
|
|
122
|
+
notice.length -
|
|
123
|
+
wrappedIndentedLines(state.listTitle ?? '', cols, type.heading).length -
|
|
124
|
+
state.listField.render(Number.POSITIVE_INFINITY, cols).length -
|
|
125
|
+
2),
|
|
95
126
|
'',
|
|
96
127
|
];
|
|
97
128
|
return renderListFieldWithContext(context, state.listField, bodyRows, cols);
|
|
98
129
|
}
|
|
99
130
|
case 'detail': {
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
...wrappedIndentedLines(state.detailMeta ?? '', cols, type.hint),
|
|
131
|
+
const headerText = [type.heading(state.detailTitle ?? ''), type.hint(state.detailMeta ?? '')];
|
|
132
|
+
const plainHeader = headerText.flatMap((line) => wrappedIndentedLines(line, cols, (value) => value));
|
|
133
|
+
const body = [
|
|
104
134
|
'',
|
|
105
135
|
...(state.detailDescription
|
|
106
136
|
? state.detailDescription
|
|
@@ -112,6 +142,12 @@ export function renderEvents(state, now, bodyRows = 100, cols) {
|
|
|
112
142
|
? [...wrappedIndentedLines(state.statusMessage, cols, type.hint), '']
|
|
113
143
|
: []),
|
|
114
144
|
];
|
|
145
|
+
const fieldRows = state.detailField?.render(Number.POSITIVE_INFINITY, cols ?? 80).length ?? 0;
|
|
146
|
+
const picture = pictureBeside(renderBitmap(eventIcon(state.detailTitle ?? '', state.detailDescription ?? '')), headerText, cols ?? Number.POSITIVE_INFINITY);
|
|
147
|
+
const withPicture = picture !== undefined &&
|
|
148
|
+
(!Number.isFinite(bodyRows) ||
|
|
149
|
+
notice.length + picture.length + body.length + fieldRows <= bodyRows);
|
|
150
|
+
const context = [...notice, ...(withPicture ? picture : plainHeader), ...body];
|
|
115
151
|
return state.detailField
|
|
116
152
|
? renderListFieldWithContext(context, state.detailField, bodyRows, cols)
|
|
117
153
|
: Number.isFinite(bodyRows)
|
|
@@ -121,11 +157,11 @@ export function renderEvents(state, now, bodyRows = 100, cols) {
|
|
|
121
157
|
case 'search':
|
|
122
158
|
return [...notice, ...(state.searchField?.render(cols) ?? [])];
|
|
123
159
|
case 'error': {
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
160
|
+
const message = state.errorMessage ?? trans.calendar.error;
|
|
161
|
+
const hint = wrappedIndentedLines(trans.calendar.errorHint, cols, type.hint);
|
|
162
|
+
const plain = [...wrappedIndentedLines(message, cols, type.body), ...hint, ''];
|
|
163
|
+
const fieldRows = state.errorField?.render(Number.POSITIVE_INFINITY, cols).length ?? 0;
|
|
164
|
+
const context = offlineContext(type.body(message), hint, plain, cols, bodyRows - fieldRows);
|
|
129
165
|
if (state.errorField) {
|
|
130
166
|
return renderListFieldWithContext(context, state.errorField, bodyRows, cols);
|
|
131
167
|
}
|
package/dist/app/views/events.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { eventIcon } from '../../features/event-art.js';
|
|
2
|
+
import { eventIconDefault } from '../../art/bitmaps.js';
|
|
1
3
|
import { captureFooterHint, passiveFooterHint } from '../chrome.js';
|
|
2
4
|
import { ListField, computeMaxVisible } from '../fields/list-field.js';
|
|
3
5
|
import { TextField } from '../fields/text-field.js';
|
|
@@ -7,6 +9,7 @@ import { glyph } from '../../core/theme.js';
|
|
|
7
9
|
import { padEndV, visualWidth } from '../../core/text.js';
|
|
8
10
|
import { fmt, t } from '../../i18n/index.js';
|
|
9
11
|
import { eventTimeRange, eventWhen, exportEventIcs, loadCalendarOrCache, recurringMark, toDisplayEvent, yearHeatmap, } from '../../features/calendar.js';
|
|
12
|
+
import { heatmapRange, shiftHeatmapDay } from '../../features/calendar-heatmap.js';
|
|
10
13
|
import { currentEvents, hasEnded, monthRange, pastEvents, searchEvents, weekRange, } from '../../features/calendar-query.js';
|
|
11
14
|
let state = { mode: 'loading' };
|
|
12
15
|
let calendar = null;
|
|
@@ -15,10 +18,11 @@ let currentList = [];
|
|
|
15
18
|
let listState;
|
|
16
19
|
let hubField;
|
|
17
20
|
let hubValues = [];
|
|
21
|
+
let hubHeatmapInline = false;
|
|
18
22
|
function backLabel() {
|
|
19
23
|
return t().common.back;
|
|
20
24
|
}
|
|
21
|
-
function buildHubField(selected,
|
|
25
|
+
function buildHubField(selected, heatmapInline) {
|
|
22
26
|
const trans = t();
|
|
23
27
|
const options = [
|
|
24
28
|
{ value: 'upcoming', label: trans.calendar.next30Days },
|
|
@@ -26,9 +30,13 @@ function buildHubField(selected, withHeatmap) {
|
|
|
26
30
|
{ value: 'month', label: trans.calendar.thisMonth },
|
|
27
31
|
{ value: 'search', label: trans.calendar.search },
|
|
28
32
|
{ value: 'past', label: trans.calendar.pastEvents },
|
|
29
|
-
|
|
33
|
+
{
|
|
34
|
+
value: 'heatmap',
|
|
35
|
+
label: heatmapInline ? trans.calendar.heatmap.inspect : trans.calendar.heatmap.title,
|
|
36
|
+
},
|
|
30
37
|
];
|
|
31
38
|
hubValues = options.map((option) => option.value);
|
|
39
|
+
hubHeatmapInline = heatmapInline;
|
|
32
40
|
const initialIndex = Math.max(0, selected === undefined ? 0 : hubValues.indexOf(selected));
|
|
33
41
|
return new ListField({ title: trans.calendar.browse, options, initialIndex });
|
|
34
42
|
}
|
|
@@ -38,10 +46,10 @@ function selectedHubValue() {
|
|
|
38
46
|
function syncHubField(bodyRows) {
|
|
39
47
|
if (state.mode !== 'hub')
|
|
40
48
|
return;
|
|
41
|
-
const
|
|
42
|
-
if (
|
|
49
|
+
const heatmapInline = hubShowsHeatmap(bodyRows, state.heatmapBuckets);
|
|
50
|
+
if (hubHeatmapInline === heatmapInline)
|
|
43
51
|
return;
|
|
44
|
-
hubField = buildHubField(selectedHubValue(),
|
|
52
|
+
hubField = buildHubField(selectedHubValue(), heatmapInline);
|
|
45
53
|
state = { ...state, hubField };
|
|
46
54
|
}
|
|
47
55
|
function showList(ctx, title, events, emptyMessage, isEnded = () => false) {
|
|
@@ -76,12 +84,40 @@ function showList(ctx, title, events, emptyMessage, isEnded = () => false) {
|
|
|
76
84
|
};
|
|
77
85
|
}
|
|
78
86
|
const RECENT_EVENTS_CAP = 5;
|
|
87
|
+
function eventsOnDay(date) {
|
|
88
|
+
if (!calendar)
|
|
89
|
+
return [];
|
|
90
|
+
const [year = 0, month = 1, day = 1] = date.split('-').map(Number);
|
|
91
|
+
return calendar.inRange(new Date(year, month - 1, day), new Date(year, month - 1, day + 1));
|
|
92
|
+
}
|
|
93
|
+
function selectHeatmapDay(date) {
|
|
94
|
+
state = {
|
|
95
|
+
...state,
|
|
96
|
+
heatmapCursor: date,
|
|
97
|
+
heatmapDay: eventsOnDay(date).map(toDisplayEvent),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
const HEATMAP_STEPS = {
|
|
101
|
+
'\x1b[A': -1,
|
|
102
|
+
'\x1b[B': 1,
|
|
103
|
+
'\x1b[D': -7,
|
|
104
|
+
'\x1b[C': 7,
|
|
105
|
+
};
|
|
106
|
+
function moveHeatmapCursor(key, cols) {
|
|
107
|
+
const step = HEATMAP_STEPS[key];
|
|
108
|
+
const now = new Date();
|
|
109
|
+
const { start, end } = heatmapRange(now, cols);
|
|
110
|
+
const current = state.heatmapCursor ?? end;
|
|
111
|
+
if (step === undefined)
|
|
112
|
+
return;
|
|
113
|
+
const next = shiftHeatmapDay(current, step);
|
|
114
|
+
selectHeatmapDay(next < start ? start : next > end ? end : next);
|
|
115
|
+
}
|
|
79
116
|
function goToHub() {
|
|
80
117
|
const now = new Date();
|
|
81
118
|
const upcoming = calendar ? currentEvents(calendar, now) : [];
|
|
82
119
|
const nextEvent = upcoming.find((event) => event.start >= now);
|
|
83
|
-
|
|
84
|
-
hubField = buildHubField(selectedHubValue(), withHeatmap);
|
|
120
|
+
hubField = buildHubField(selectedHubValue(), hubHeatmapInline);
|
|
85
121
|
state = {
|
|
86
122
|
mode: 'hub',
|
|
87
123
|
hubField,
|
|
@@ -147,6 +183,15 @@ export const eventsView = {
|
|
|
147
183
|
syncHubField(ctx.bodyRows);
|
|
148
184
|
return renderEvents(stale ? { ...state, stale } : state, new Date(), ctx.bodyRows, ctx.size.cols);
|
|
149
185
|
},
|
|
186
|
+
ambient() {
|
|
187
|
+
if (state.mode !== 'hub')
|
|
188
|
+
return undefined;
|
|
189
|
+
const next = state.nextEvent;
|
|
190
|
+
return {
|
|
191
|
+
kind: 'icon',
|
|
192
|
+
icon: next ? eventIcon(next.title, next.description) : eventIconDefault,
|
|
193
|
+
};
|
|
194
|
+
},
|
|
150
195
|
isBusy() {
|
|
151
196
|
return state.mode === 'loading';
|
|
152
197
|
},
|
|
@@ -162,7 +207,7 @@ export const eventsView = {
|
|
|
162
207
|
footerHint(tabCount, cols = Number.POSITIVE_INFINITY) {
|
|
163
208
|
if (state.mode === 'search')
|
|
164
209
|
return captureFooterHint(cols);
|
|
165
|
-
const passive = state.mode === 'loading'
|
|
210
|
+
const passive = state.mode === 'loading';
|
|
166
211
|
return passive ? passiveFooterHint(tabCount, cols) : undefined;
|
|
167
212
|
},
|
|
168
213
|
handleBack() {
|
|
@@ -212,6 +257,7 @@ export const eventsView = {
|
|
|
212
257
|
}
|
|
213
258
|
if (result.selected === 'heatmap') {
|
|
214
259
|
state = { ...state, mode: 'heatmap' };
|
|
260
|
+
selectHeatmapDay(heatmapRange(now, ctx.size.cols).end);
|
|
215
261
|
return;
|
|
216
262
|
}
|
|
217
263
|
if (result.selected === 'search') {
|
|
@@ -228,7 +274,14 @@ export const eventsView = {
|
|
|
228
274
|
return;
|
|
229
275
|
}
|
|
230
276
|
case 'heatmap': {
|
|
231
|
-
|
|
277
|
+
if (key === '\r' && state.heatmapCursor !== undefined) {
|
|
278
|
+
const date = state.heatmapCursor;
|
|
279
|
+
const events = eventsOnDay(date);
|
|
280
|
+
if (events.length > 0)
|
|
281
|
+
showList(ctx, date, events, t().calendar.noEvents);
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
moveHeatmapCursor(key, ctx.size.cols);
|
|
232
285
|
return;
|
|
233
286
|
}
|
|
234
287
|
case 'list': {
|