@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/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;
|
|
@@ -117,6 +118,28 @@ export function truncateStart(str, maxWidth, marker = '...') {
|
|
|
117
118
|
}
|
|
118
119
|
return fittedMarker + value;
|
|
119
120
|
}
|
|
121
|
+
function indexOfIgnoreCase(text, needle) {
|
|
122
|
+
const target = needle.toLowerCase();
|
|
123
|
+
for (let index = 0; index + needle.length <= text.length; index += 1) {
|
|
124
|
+
if (text.slice(index, index + needle.length).toLowerCase() === target)
|
|
125
|
+
return index;
|
|
126
|
+
}
|
|
127
|
+
return -1;
|
|
128
|
+
}
|
|
129
|
+
export function excerptAround(text, needle, maxWidth, marker = '...') {
|
|
130
|
+
if (visualWidth(text) <= maxWidth)
|
|
131
|
+
return text;
|
|
132
|
+
const at = needle ? indexOfIgnoreCase(text, needle) : -1;
|
|
133
|
+
const markerWidth = visualWidth(marker);
|
|
134
|
+
if (at <= 0 || visualWidth(text.slice(0, at + needle.length)) + markerWidth <= maxWidth) {
|
|
135
|
+
return truncate(text, maxWidth, marker);
|
|
136
|
+
}
|
|
137
|
+
const rest = text.slice(at);
|
|
138
|
+
const available = maxWidth - markerWidth;
|
|
139
|
+
const lead = Math.max(Math.floor(available / 4), available - visualWidth(rest));
|
|
140
|
+
const head = truncateStart(text.slice(0, at), lead + markerWidth, marker);
|
|
141
|
+
return head + truncate(rest, maxWidth - visualWidth(head), marker);
|
|
142
|
+
}
|
|
120
143
|
function osc8State(sequence) {
|
|
121
144
|
const match = OSC8_RE.exec(sequence);
|
|
122
145
|
if (!match)
|
|
@@ -212,8 +235,8 @@ function renderWrappedSegment(tokens, start, end, activeSgr, activeOsc8) {
|
|
|
212
235
|
const osc8AtEnd = advanceOsc8(activeOsc8, tokens, start, end);
|
|
213
236
|
return osc8AtEnd ? `${withReset}${OSC8_CLOSE}` : withReset;
|
|
214
237
|
}
|
|
215
|
-
const NO_LINE_START = /^[。.、,;:?!)]}〉》」』】〕・ー~…‥%‰°℃,.;:?!)\]}
|
|
216
|
-
const NO_LINE_END = /^[([{〈《「『【〔([{
|
|
238
|
+
const NO_LINE_START = /^[。.、,;:?!)]}〉》」』】〕・ー~…‥%‰°℃,.;:?!)\]}>”’]$/u;
|
|
239
|
+
const NO_LINE_END = /^[([{〈《「『【〔([{<“‘]$/u;
|
|
217
240
|
function visibleAt(tokens, index) {
|
|
218
241
|
const token = tokens[index];
|
|
219
242
|
return token && !token.sgr && token.width > 0 ? token : undefined;
|
|
@@ -318,17 +341,8 @@ export function wrapAnsiToVisualWidth(str, maxWidth, continuationWidth = maxWidt
|
|
|
318
341
|
}
|
|
319
342
|
export function wrapAnsiWithIndent(str, maxWidth, preferredIndent = '') {
|
|
320
343
|
const width = Number.isFinite(maxWidth)
|
|
321
|
-
? Math.max(1, Math.floor(maxWidth))
|
|
344
|
+
? bodyEdge(Math.max(1, Math.floor(maxWidth)))
|
|
322
345
|
: 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}`);
|
|
346
|
+
const indent = visualWidth(preferredIndent) + 2 <= width ? preferredIndent : '';
|
|
347
|
+
return wrapAnsiToVisualWidth(str, Math.max(1, width - visualWidth(indent))).map((line) => `${indent}${line}`);
|
|
334
348
|
}
|
package/dist/core/theme.js
CHANGED
|
@@ -54,6 +54,7 @@ export const glyph = {
|
|
|
54
54
|
rule: () => pickIcon('─', '-'),
|
|
55
55
|
bar: () => pickIcon('│', '|'),
|
|
56
56
|
bullet: () => pickIcon('·', '.'),
|
|
57
|
+
sep: () => pickIcon('·', '-'),
|
|
57
58
|
dot: () => pickIcon('●', '*'),
|
|
58
59
|
updown: () => pickIcon('↑↓', 'up/down'),
|
|
59
60
|
enter: () => pickIcon('⏎', 'enter'),
|
|
@@ -64,6 +65,19 @@ export const MAX_FRAME_COLS = 120;
|
|
|
64
65
|
export const space = {
|
|
65
66
|
indent: ' ',
|
|
66
67
|
};
|
|
68
|
+
export function frameWidth(cols) {
|
|
69
|
+
return Math.min(cols, MAX_FRAME_COLS);
|
|
70
|
+
}
|
|
71
|
+
export function frameLeft(cols) {
|
|
72
|
+
return Math.floor((cols - frameWidth(cols)) / 2);
|
|
73
|
+
}
|
|
74
|
+
const RIGHT_MARGIN_MIN_COLS = 40;
|
|
75
|
+
export function bodyEdge(cols) {
|
|
76
|
+
return cols >= RIGHT_MARGIN_MIN_COLS ? cols - space.indent.length : cols;
|
|
77
|
+
}
|
|
78
|
+
export function bodyWidth(cols) {
|
|
79
|
+
return Number.isFinite(cols) ? bodyEdge(Math.max(1, Math.floor(cols))) : Number.POSITIVE_INFINITY;
|
|
80
|
+
}
|
|
67
81
|
export const type = {
|
|
68
82
|
heading: (s) => chalk.bold(s),
|
|
69
83
|
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
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
1
|
import { pickIcon } from '../core/icons.js';
|
|
3
|
-
import { space, type } from '../core/theme.js';
|
|
2
|
+
import { bodyWidth, c, space, type } from '../core/theme.js';
|
|
4
3
|
import { t, getCurrentLanguage } from '../i18n/index.js';
|
|
5
4
|
import { visualWidth } from '../core/text.js';
|
|
6
5
|
function parseBucketDate(date) {
|
|
@@ -13,33 +12,46 @@ function parseBucketDate(date) {
|
|
|
13
12
|
function utcDayToMonIndex(utcDay) {
|
|
14
13
|
return (utcDay + 6) % 7;
|
|
15
14
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (count === 3)
|
|
24
|
-
return pickIcon('▓', '-');
|
|
25
|
-
return pickIcon('█', '=');
|
|
26
|
-
}
|
|
27
|
-
const HEATMAP_RAMP = ['#1b4332', '#2d6a4f', '#40916c', '#52b788'];
|
|
15
|
+
const LEVEL_GLYPHS = [
|
|
16
|
+
['·', ' '],
|
|
17
|
+
['░', '.'],
|
|
18
|
+
['▒', ':'],
|
|
19
|
+
['▓', '-'],
|
|
20
|
+
['█', '='],
|
|
21
|
+
];
|
|
28
22
|
const MAX_WEEK_COLUMNS = 53;
|
|
29
23
|
const GRID_PREFIX_WIDTH = 6;
|
|
30
|
-
function
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
24
|
+
function levelCell(count, useColor) {
|
|
25
|
+
const level = Math.max(0, Math.min(count, LEVEL_GLYPHS.length - 1));
|
|
26
|
+
const [unicode, ascii] = LEVEL_GLYPHS[level] ?? LEVEL_GLYPHS[0];
|
|
27
|
+
const cell = pickIcon(unicode, ascii);
|
|
28
|
+
if (!useColor)
|
|
29
|
+
return cell;
|
|
30
|
+
return level === 0 ? type.hint(cell) : c.success(cell);
|
|
31
|
+
}
|
|
32
|
+
function placeMonthLabels(anchors, width, format, strict) {
|
|
33
|
+
let line = '';
|
|
34
|
+
for (const [index, anchor] of anchors.entries()) {
|
|
35
|
+
const label = format(anchor.date);
|
|
36
|
+
const end = anchor.start + visualWidth(label);
|
|
37
|
+
const used = visualWidth(line);
|
|
38
|
+
const gap = index === 0 ? 2 : 1;
|
|
39
|
+
const limit = (anchors[index + 1]?.start ?? width + gap) - gap;
|
|
40
|
+
if (anchor.start >= used + (used > 0 ? 1 : 0) && end <= limit) {
|
|
41
|
+
line += ' '.repeat(anchor.start - used) + label;
|
|
42
|
+
}
|
|
43
|
+
else if (strict && index > 0) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return line;
|
|
35
48
|
}
|
|
36
49
|
export function renderHeatmap(buckets, today, options) {
|
|
37
50
|
const useColor = options?.color === true;
|
|
38
51
|
const trans = t();
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
: Math.floor((options.cols - GRID_PREFIX_WIDTH) / cellWidth);
|
|
52
|
+
const cols = bodyWidth(options?.cols ?? Number.POSITIVE_INFINITY);
|
|
53
|
+
const cellWidth = cols < GRID_PREFIX_WIDTH + MAX_WEEK_COLUMNS * 2 ? 1 : 2;
|
|
54
|
+
const availableColumns = Math.floor((cols - GRID_PREFIX_WIDTH) / cellWidth);
|
|
43
55
|
const numCols = Math.max(1, Math.min(MAX_WEEK_COLUMNS, availableColumns));
|
|
44
56
|
const countByDate = new Map();
|
|
45
57
|
for (const b of buckets) {
|
|
@@ -78,30 +90,23 @@ export function renderHeatmap(buckets, today, options) {
|
|
|
78
90
|
timeZone: 'UTC',
|
|
79
91
|
});
|
|
80
92
|
const cellsWidth = numCols * cellWidth;
|
|
81
|
-
|
|
93
|
+
const anchors = [];
|
|
82
94
|
let prevMonth = -1;
|
|
83
|
-
for (
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const cell = columns[col]?.[row];
|
|
87
|
-
if (cell !== null && cell !== undefined) {
|
|
88
|
-
labelDate = parseBucketDate(cell.date);
|
|
89
|
-
break;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
if (labelDate === null)
|
|
95
|
+
for (const [col, column] of columns.entries()) {
|
|
96
|
+
const cell = column.find((candidate) => candidate !== null);
|
|
97
|
+
if (!cell)
|
|
93
98
|
continue;
|
|
94
|
-
const
|
|
95
|
-
if (
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const used = visualWidth(monthLine);
|
|
100
|
-
if (start >= used + (used > 0 ? 1 : 0) && start + visualWidth(label) <= cellsWidth) {
|
|
101
|
-
monthLine += ' '.repeat(start - used) + label;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
99
|
+
const date = parseBucketDate(cell.date);
|
|
100
|
+
if (date.getUTCMonth() === prevMonth)
|
|
101
|
+
continue;
|
|
102
|
+
prevMonth = date.getUTCMonth();
|
|
103
|
+
anchors.push({ start: col * cellWidth, date });
|
|
104
104
|
}
|
|
105
|
+
const monthNumber = (date) => String(date.getUTCMonth() + 1);
|
|
106
|
+
const monthLine = placeMonthLabels(anchors, cellsWidth, (date) => monthFmt.format(date), true) ??
|
|
107
|
+
placeMonthLabels(anchors, cellsWidth, monthNumber, true) ??
|
|
108
|
+
placeMonthLabels(anchors, cellsWidth, monthNumber, false) ??
|
|
109
|
+
'';
|
|
105
110
|
const monthLabelLine = space.indent + weekdayLabel + monthLine;
|
|
106
111
|
const weekdayNames = [
|
|
107
112
|
trans.timetable.weekdayMon.slice(0, 2),
|
|
@@ -122,28 +127,12 @@ export function renderHeatmap(buckets, today, options) {
|
|
|
122
127
|
const cell = col[row];
|
|
123
128
|
if (cell === null || cell === undefined)
|
|
124
129
|
return ' ';
|
|
125
|
-
|
|
126
|
-
return applyColor(glyph, cell.count, useColor);
|
|
130
|
+
return levelCell(cell.count, useColor);
|
|
127
131
|
});
|
|
128
132
|
lines.push(`${space.indent}${wdLabel} ${cells.join(cellWidth === 2 ? ' ' : '')}`);
|
|
129
133
|
}
|
|
130
|
-
const
|
|
131
|
-
pickIcon('·', ' '),
|
|
132
|
-
pickIcon('░', '.'),
|
|
133
|
-
pickIcon('▒', ':'),
|
|
134
|
-
pickIcon('▓', '-'),
|
|
135
|
-
pickIcon('█', '='),
|
|
136
|
-
];
|
|
137
|
-
const legendColored = useColor
|
|
138
|
-
? [
|
|
139
|
-
legendGlyphs[0] ?? '·',
|
|
140
|
-
applyColor(legendGlyphs[1] ?? '░', 1, true),
|
|
141
|
-
applyColor(legendGlyphs[2] ?? '▒', 2, true),
|
|
142
|
-
applyColor(legendGlyphs[3] ?? '▓', 3, true),
|
|
143
|
-
applyColor(legendGlyphs[4] ?? '█', 4, true),
|
|
144
|
-
]
|
|
145
|
-
: legendGlyphs;
|
|
134
|
+
const legend = LEVEL_GLYPHS.map((_, level) => levelCell(level, useColor)).join('');
|
|
146
135
|
lines.push('');
|
|
147
|
-
lines.push(`${space.indent}${type.hint(trans.calendar.heatmap.legendLess)} ${
|
|
136
|
+
lines.push(`${space.indent}${type.hint(trans.calendar.heatmap.legendLess)} ${legend} ${type.hint(trans.calendar.heatmap.legendMore)}`);
|
|
148
137
|
return lines.join('\n');
|
|
149
138
|
}
|
|
@@ -22,7 +22,7 @@ export function eventEnd(event) {
|
|
|
22
22
|
? new Date(event.start.getFullYear(), event.start.getMonth(), event.start.getDate() + 1)
|
|
23
23
|
: event.start));
|
|
24
24
|
}
|
|
25
|
-
function hasEnded(event, now) {
|
|
25
|
+
export function hasEnded(event, now) {
|
|
26
26
|
return event.start < now && eventEnd(event) <= now;
|
|
27
27
|
}
|
|
28
28
|
export function currentEvents(calendar, now) {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { fetchFeedConditional, parseCalendar, createCalendar, FeedFetchError, FeedParseError, eventToICS, } from '@nbtca/nbtcal';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
|
-
import { c, type, space, glyph } from '../core/theme.js';
|
|
3
|
+
import { c, type, space, glyph, bodyWidth } from '../core/theme.js';
|
|
4
4
|
import { pickIcon } from '../core/icons.js';
|
|
5
5
|
import { padEndV, sanitizeTerminalLine, sanitizeTerminalText, truncate, visualWidth, wrapAnsiWithIndent, wrapAnsiToVisualWidth, } from '../core/text.js';
|
|
6
6
|
import { t } from '../i18n/index.js';
|
|
7
7
|
import { localDayDifference } from '../core/calendar-day.js';
|
|
8
|
-
import { countdownParts, isCountdownUrgent, buildExportFilename, formatDuration, pastYearRange, } from './calendar-query.js';
|
|
8
|
+
import { countdownParts, eventEnd, isCountdownUrgent, buildExportFilename, formatDuration, pastYearRange, } from './calendar-query.js';
|
|
9
9
|
import { loadFeedCache, saveFeedCache, touchFeedCache } from './calendar-store.js';
|
|
10
10
|
import { writeFileSync, existsSync } from 'fs';
|
|
11
11
|
import { join } from 'path';
|
|
@@ -88,6 +88,22 @@ export function toDisplayEvent(e) {
|
|
|
88
88
|
uid: e.uid,
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
|
+
export function eventTimeRange(e) {
|
|
92
|
+
const dash = pickIcon('–', '-');
|
|
93
|
+
const startDate = formatDate(e.start);
|
|
94
|
+
if (e.isAllDay) {
|
|
95
|
+
const lastDay = new Date(eventEnd(e).getTime() - 1);
|
|
96
|
+
const endDate = formatDate(lastDay);
|
|
97
|
+
return endDate === startDate ? startDate : `${startDate} ${dash} ${endDate}`;
|
|
98
|
+
}
|
|
99
|
+
const start = `${startDate} ${formatTime(e.start)}`;
|
|
100
|
+
if (!e.end || e.end <= e.start)
|
|
101
|
+
return start;
|
|
102
|
+
const endDate = formatDate(e.end);
|
|
103
|
+
return endDate === startDate
|
|
104
|
+
? `${start}${dash}${formatTime(e.end)}`
|
|
105
|
+
: `${start} ${dash} ${endDate} ${formatTime(e.end)}`;
|
|
106
|
+
}
|
|
91
107
|
export async function loadCalendarOrCache(signal) {
|
|
92
108
|
try {
|
|
93
109
|
return { calendar: await loadCalendarOrThrow(signal), stale: false };
|
|
@@ -186,7 +202,7 @@ export function recurringMark(e) {
|
|
|
186
202
|
return e.recurring ? ` ${pickIcon('↻', '~')}` : '';
|
|
187
203
|
}
|
|
188
204
|
function hangingLines(marker, content, cols) {
|
|
189
|
-
const width =
|
|
205
|
+
const width = bodyWidth(cols);
|
|
190
206
|
const prefixes = [`${space.indent}${marker} `, `${marker} `, marker, ''];
|
|
191
207
|
const prefix = prefixes.find((candidate) => visualWidth(candidate) < width) ?? '';
|
|
192
208
|
const continuation = ' '.repeat(visualWidth(prefix));
|
|
@@ -194,7 +210,7 @@ function hangingLines(marker, content, cols) {
|
|
|
194
210
|
return wrapAnsiToVisualWidth(content, contentWidth).map((line, index) => `${index === 0 ? prefix : continuation}${line}`);
|
|
195
211
|
}
|
|
196
212
|
export function renderEventBriefLines(e, now, cols = Number.POSITIVE_INFINITY) {
|
|
197
|
-
const dot =
|
|
213
|
+
const dot = glyph.sep();
|
|
198
214
|
const proximity = eventProximity(e.startDate, now);
|
|
199
215
|
const dateStyle = proximity === 'today'
|
|
200
216
|
? type.active
|
|
@@ -203,7 +219,7 @@ export function renderEventBriefLines(e, now, cols = Number.POSITIVE_INFINITY) {
|
|
|
203
219
|
: proximity === 'week'
|
|
204
220
|
? type.body
|
|
205
221
|
: type.hint;
|
|
206
|
-
const marker = proximity === 'today' ? type.active(pickIcon('●', '*')) : dateStyle(
|
|
222
|
+
const marker = proximity === 'today' ? type.active(pickIcon('●', '*')) : dateStyle(glyph.sep());
|
|
207
223
|
const titleStyled = styleTitle(e.title, proximity === 'today' ? type.active : type.body);
|
|
208
224
|
const content = `${dateStyle(eventWhen(e))} ${type.hint(dot)} ${titleStyled}${type.hint(recurringMark(e))}`;
|
|
209
225
|
return hangingLines(marker, content, cols);
|
|
@@ -220,9 +236,9 @@ export function renderCountdownBanner(event, now, cols = Number.POSITIVE_INFINIT
|
|
|
220
236
|
? trans.calendar.startingNow
|
|
221
237
|
: `${trans.calendar.inPrefix} ${formatDuration(p)}`;
|
|
222
238
|
const whenStyled = isCountdownUrgent(p) ? c.warn(when) : type.hint(when);
|
|
223
|
-
const dot =
|
|
239
|
+
const dot = glyph.sep();
|
|
224
240
|
const content = `${type.label(trans.calendar.next)} ${dot} ${type.body(event.title)} ${dot} ${whenStyled}`;
|
|
225
|
-
return hangingLines(type.active(glyph.
|
|
241
|
+
return hangingLines(type.active(glyph.dot()), content, cols).join('\n');
|
|
226
242
|
}
|
|
227
243
|
export function exportEventIcs(event, dir = process.cwd()) {
|
|
228
244
|
const base = buildExportFilename(event);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
2
|
import { createDocsClient, parseDoc } from '@nbtca/docs';
|
|
3
|
+
import { URLS } from '../config/data.js';
|
|
3
4
|
import { createDocsStore } from './docs-store.js';
|
|
4
5
|
const contextKey = Symbol.for('@nbtca/prompt/docs-fetch-context/v2');
|
|
5
6
|
const globalWithContext = globalThis;
|
|
@@ -160,7 +161,8 @@ function beginDocsFetch() {
|
|
|
160
161
|
};
|
|
161
162
|
}
|
|
162
163
|
const store = createDocsStore();
|
|
163
|
-
const
|
|
164
|
+
const options = { store, mirror: `${URLS.docs}/docs-api` };
|
|
165
|
+
const defaultClient = createDocsClient(options);
|
|
164
166
|
const clientsBySignal = new WeakMap();
|
|
165
167
|
const clients = new Set([defaultClient]);
|
|
166
168
|
function clientFor(signal) {
|
|
@@ -169,7 +171,7 @@ function clientFor(signal) {
|
|
|
169
171
|
const existing = clientsBySignal.get(signal);
|
|
170
172
|
if (existing)
|
|
171
173
|
return existing;
|
|
172
|
-
const client = createDocsClient(
|
|
174
|
+
const client = createDocsClient(options);
|
|
173
175
|
clientsBySignal.set(signal, client);
|
|
174
176
|
clients.add(client);
|
|
175
177
|
signal.addEventListener('abort', () => {
|
|
@@ -26,38 +26,30 @@ const CJK_SOFT_BREAK = new RegExp(`(?<=${CJK})[ \\t]*\\n[ \\t]*(?=${CJK})`, 'gu'
|
|
|
26
26
|
function joinSoftBreaks(text) {
|
|
27
27
|
return text.replace(CJK_SOFT_BREAK, '').replace(/[ \t]*\n[ \t]*/g, ' ');
|
|
28
28
|
}
|
|
29
|
-
function renderInline(tokens
|
|
30
|
-
return (tokens ?? []).map((token) => renderInlineToken(token
|
|
29
|
+
function renderInline(tokens) {
|
|
30
|
+
return (tokens ?? []).map((token) => renderInlineToken(token)).join('');
|
|
31
31
|
}
|
|
32
|
-
function renderLink(token
|
|
33
|
-
|
|
34
|
-
const bare = (href) => href.replace(/^(?:https?:\/\/|mailto:)/, '').replace(/\/$/, '');
|
|
35
|
-
const selfLabelled = bare(stripAnsi(text)) === bare(token.href);
|
|
36
|
-
if (isInternalHref(token.href) || token.href.startsWith('#') || selfLabelled) {
|
|
37
|
-
return chalk.underline(c.accent(text));
|
|
38
|
-
}
|
|
39
|
-
return hrefs ? `${c.accent(text)} ${c.url(`(${token.href})`)}` : c.accent(text);
|
|
32
|
+
function renderLink(token) {
|
|
33
|
+
return chalk.underline(c.accent(renderInline(token.tokens)));
|
|
40
34
|
}
|
|
41
|
-
function renderInlineToken(token
|
|
35
|
+
function renderInlineToken(token) {
|
|
42
36
|
switch (token.type) {
|
|
43
37
|
case 'text':
|
|
44
|
-
return token.tokens
|
|
45
|
-
? renderInline(token.tokens, hrefs)
|
|
46
|
-
: joinSoftBreaks(decodeEntities(token.text));
|
|
38
|
+
return token.tokens ? renderInline(token.tokens) : joinSoftBreaks(decodeEntities(token.text));
|
|
47
39
|
case 'escape':
|
|
48
40
|
return token.text;
|
|
49
41
|
case 'strong':
|
|
50
|
-
return chalk.bold(renderInline(token.tokens
|
|
42
|
+
return chalk.bold(renderInline(token.tokens));
|
|
51
43
|
case 'em':
|
|
52
|
-
return chalk.italic(renderInline(token.tokens
|
|
44
|
+
return chalk.italic(renderInline(token.tokens));
|
|
53
45
|
case 'del':
|
|
54
|
-
return chalk.strikethrough(c.muted(renderInline(token.tokens
|
|
46
|
+
return chalk.strikethrough(c.muted(renderInline(token.tokens)));
|
|
55
47
|
case 'codespan':
|
|
56
48
|
return c.code(token.text);
|
|
57
49
|
case 'br':
|
|
58
50
|
return '\n';
|
|
59
51
|
case 'link':
|
|
60
|
-
return renderLink(token
|
|
52
|
+
return renderLink(token);
|
|
61
53
|
case 'image':
|
|
62
54
|
return `${pickIcon('🖼️', '[image]')} ${token.text || 'image'}`;
|
|
63
55
|
case 'html':
|
|
@@ -94,7 +86,7 @@ function styleHeading(text, depth) {
|
|
|
94
86
|
return chalk.bold(text);
|
|
95
87
|
}
|
|
96
88
|
function renderHeading(token, width) {
|
|
97
|
-
const lines = wrap(styleHeading(renderInline(token.tokens
|
|
89
|
+
const lines = wrap(styleHeading(renderInline(token.tokens), token.depth), width);
|
|
98
90
|
if (token.depth !== 2)
|
|
99
91
|
return lines;
|
|
100
92
|
const underline = Math.min(width, Math.max(...lines.map(visualWidth)));
|
|
@@ -173,8 +165,8 @@ function renderRecords(header, rows, width) {
|
|
|
173
165
|
return lines;
|
|
174
166
|
}
|
|
175
167
|
function renderTable(token, width) {
|
|
176
|
-
const header = token.header.map((cell) => renderInline(cell.tokens
|
|
177
|
-
const rows = token.rows.map((row) => row.map((cell) => renderInline(cell.tokens
|
|
168
|
+
const header = token.header.map((cell) => renderInline(cell.tokens));
|
|
169
|
+
const rows = token.rows.map((row) => row.map((cell) => renderInline(cell.tokens)));
|
|
178
170
|
const natural = header.map((label, column) => Math.max(cellWidth(label), ...rows.map((row) => cellWidth(row[column] ?? ''))));
|
|
179
171
|
const available = width - (3 * header.length + 1);
|
|
180
172
|
const floor = natural.map((columnWidth) => Math.min(columnWidth, MIN_COLUMN));
|
|
@@ -216,9 +208,9 @@ function renderBlock(token, width, depth) {
|
|
|
216
208
|
case 'heading':
|
|
217
209
|
return renderHeading(token, width);
|
|
218
210
|
case 'paragraph':
|
|
219
|
-
return wrap(renderInline(token.tokens
|
|
211
|
+
return wrap(renderInline(token.tokens), width);
|
|
220
212
|
case 'text':
|
|
221
|
-
return wrap(renderInlineToken(token
|
|
213
|
+
return wrap(renderInlineToken(token), width);
|
|
222
214
|
case 'code':
|
|
223
215
|
return renderCode(token, width);
|
|
224
216
|
case 'blockquote':
|
|
@@ -245,7 +237,7 @@ function renderBlock(token, width, depth) {
|
|
|
245
237
|
case 'image':
|
|
246
238
|
case 'link':
|
|
247
239
|
case 'strong':
|
|
248
|
-
return wrap(renderInlineToken(token
|
|
240
|
+
return wrap(renderInlineToken(token), width);
|
|
249
241
|
}
|
|
250
242
|
}
|
|
251
243
|
function renderBlocks(tokens, width, depth, tight) {
|