@ftrdotdev/pi-tracker 0.5.2 → 0.7.0
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/README.md +136 -46
- package/package.json +8 -2
- package/src/compaction/candidate.test.ts +191 -0
- package/src/compaction/candidate.ts +105 -0
- package/src/compaction/classifier.test.ts +422 -0
- package/src/compaction/classifier.ts +198 -0
- package/src/compaction/completion.test.ts +257 -0
- package/src/compaction/completion.ts +94 -0
- package/src/compaction/decision-record.test.ts +91 -0
- package/src/compaction/decision-record.ts +101 -0
- package/src/compaction/digest.test.ts +185 -0
- package/src/compaction/digest.ts +158 -0
- package/src/compaction/footprint.test.ts +135 -0
- package/src/compaction/footprint.ts +387 -0
- package/src/compaction/observations.test.ts +199 -0
- package/src/compaction/observations.ts +348 -0
- package/src/compaction/pointer.test.ts +26 -0
- package/src/compaction/pointer.ts +15 -0
- package/src/compaction/rules.test.ts +253 -0
- package/src/compaction/rules.ts +188 -0
- package/src/compaction/settings.test.ts +315 -0
- package/src/compaction/settings.ts +185 -0
- package/src/compaction/settle.test.ts +370 -0
- package/src/compaction/settle.ts +150 -0
- package/src/{deps.test.ts → core/deps.test.ts} +1 -1
- package/src/{domain.test.ts → core/domain.test.ts} +42 -9
- package/src/{domain.ts → core/domain.ts} +73 -8
- package/src/{persistence.test.ts → core/persistence.test.ts} +7 -7
- package/src/{store.test.ts → core/store.test.ts} +116 -50
- package/src/{store.ts → core/store.ts} +92 -31
- package/src/index.test.ts +728 -84
- package/src/index.ts +237 -49
- package/src/{tool-metadata.test.ts → presentation/tool-metadata.test.ts} +264 -49
- package/src/presentation/tool-metadata.ts +675 -0
- package/src/{ui.test.ts → presentation/ui.test.ts} +128 -9
- package/src/{ui.ts → presentation/ui.ts} +123 -30
- package/src/tool-metadata.ts +0 -452
- /package/src/{deps.ts → core/deps.ts} +0 -0
- /package/src/{persistence.ts → core/persistence.ts} +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { assert, it } from "@effect/vitest";
|
|
2
2
|
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
3
3
|
import { visibleWidth } from "@earendil-works/pi-tui";
|
|
4
|
-
import { orderedItems } from "
|
|
5
|
-
import { TodoItem, TodoList, TrackerState } from "
|
|
4
|
+
import { orderedItems } from "../core/deps.ts";
|
|
5
|
+
import { TodoItem, TodoList, TrackerState } from "../core/domain.ts";
|
|
6
6
|
import {
|
|
7
7
|
makeTrackerOverlay,
|
|
8
8
|
makeTrackerWidget,
|
|
@@ -16,12 +16,13 @@ import {
|
|
|
16
16
|
/**
|
|
17
17
|
* Identity theme: styles pass text through unchanged, so render output is
|
|
18
18
|
* plain text that assertions can search. The overlay and widget only use
|
|
19
|
-
* `fg`, `bold` and `
|
|
19
|
+
* `fg`, `bold`, `strikethrough` and `style`, which this stub covers.
|
|
20
20
|
*/
|
|
21
21
|
const identityTheme = {
|
|
22
22
|
fg: (_color: string, text: string): string => text,
|
|
23
23
|
bold: (text: string): string => text,
|
|
24
24
|
strikethrough: (text: string): string => text,
|
|
25
|
+
style: (text: string): string => text,
|
|
25
26
|
} as unknown as Theme;
|
|
26
27
|
|
|
27
28
|
/** A realistic two-list state: Work is the active list. */
|
|
@@ -32,14 +33,14 @@ const twoListState = (): TrackerState =>
|
|
|
32
33
|
id: 1,
|
|
33
34
|
name: "Work",
|
|
34
35
|
items: [
|
|
35
|
-
new TodoItem({
|
|
36
|
-
new TodoItem({
|
|
36
|
+
new TodoItem({ title: "write plan", done: true }),
|
|
37
|
+
new TodoItem({ title: "implement tracker", done: false }),
|
|
37
38
|
],
|
|
38
39
|
}),
|
|
39
40
|
new TodoList({
|
|
40
41
|
id: 2,
|
|
41
42
|
name: "Home",
|
|
42
|
-
items: [new TodoItem({
|
|
43
|
+
items: [new TodoItem({ title: "water plants", done: false })],
|
|
43
44
|
}),
|
|
44
45
|
],
|
|
45
46
|
activeListId: 1,
|
|
@@ -92,6 +93,25 @@ const flushAsync = (): Promise<void> => new Promise((resolve) => setTimeout(reso
|
|
|
92
93
|
// Interactive overlay: items pane follows the focused list
|
|
93
94
|
// --------------------------------------------------------------------------
|
|
94
95
|
|
|
96
|
+
it("overlay renders a multi-line description as separate lines", () => {
|
|
97
|
+
const list = new TodoList({
|
|
98
|
+
id: 1,
|
|
99
|
+
name: "Work",
|
|
100
|
+
items: [
|
|
101
|
+
new TodoItem({ id: 1, title: "multi", description: "first line\nsecond line", done: false }),
|
|
102
|
+
],
|
|
103
|
+
});
|
|
104
|
+
const h = makeOverlay(new TrackerState({ lists: [list], activeListId: 1, nextListId: 2 }));
|
|
105
|
+
const lines = h.overlay.render(80);
|
|
106
|
+
assert.equal(
|
|
107
|
+
lines.some((line) => line.includes("\n")),
|
|
108
|
+
false,
|
|
109
|
+
);
|
|
110
|
+
const text = lines.join("\n");
|
|
111
|
+
assert.include(text, "first line");
|
|
112
|
+
assert.include(text, "second line");
|
|
113
|
+
});
|
|
114
|
+
|
|
95
115
|
it("previews the focused list's items while navigating the lists pane", () => {
|
|
96
116
|
const h = makeOverlay(twoListState());
|
|
97
117
|
const text = () => h.overlay.render(80).join("\n");
|
|
@@ -191,6 +211,41 @@ it("widget renders nothing when no list is active (bridge hides it)", () => {
|
|
|
191
211
|
assert.deepStrictEqual(renderTrackerWidget(state, identityTheme, 40), []);
|
|
192
212
|
});
|
|
193
213
|
|
|
214
|
+
it("widget shows a dimmed description line truncated to the width", () => {
|
|
215
|
+
const description = "x".repeat(120);
|
|
216
|
+
const list = new TodoList({
|
|
217
|
+
id: 1,
|
|
218
|
+
name: "Work",
|
|
219
|
+
items: [new TodoItem({ id: 1, title: "long item", description, done: false })],
|
|
220
|
+
});
|
|
221
|
+
const state = new TrackerState({ lists: [list], activeListId: 1, nextListId: 2 });
|
|
222
|
+
const width = 40;
|
|
223
|
+
const lines = renderTrackerWidget(state, identityTheme, width);
|
|
224
|
+
const text = lines.join("\n");
|
|
225
|
+
assert.include(text, "long item");
|
|
226
|
+
notContain(text, description);
|
|
227
|
+
const descriptionLine = lines.find((line) => line.includes("x"));
|
|
228
|
+
assert.isDefined(descriptionLine);
|
|
229
|
+
assert.isAtMost(visibleWidth(descriptionLine!), width);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it("widget collapses a multi-line description into one line", () => {
|
|
233
|
+
const list = new TodoList({
|
|
234
|
+
id: 1,
|
|
235
|
+
name: "Work",
|
|
236
|
+
items: [
|
|
237
|
+
new TodoItem({ id: 1, title: "multi", description: "first line\nsecond line", done: false }),
|
|
238
|
+
],
|
|
239
|
+
});
|
|
240
|
+
const state = new TrackerState({ lists: [list], activeListId: 1, nextListId: 2 });
|
|
241
|
+
const lines = renderTrackerWidget(state, identityTheme, 60);
|
|
242
|
+
assert.equal(
|
|
243
|
+
lines.some((line) => line.includes("\n")),
|
|
244
|
+
false,
|
|
245
|
+
);
|
|
246
|
+
assert.include(lines.join("\n"), "first line second line");
|
|
247
|
+
});
|
|
248
|
+
|
|
194
249
|
it("widget survives the setWidget bridge wrapper (render/invalidate handed off by reference)", () => {
|
|
195
250
|
// Mirrors the tracker bridge: `return { render: widget.render, invalidate: widget.invalidate }`.
|
|
196
251
|
// pi calls render as a method of the wrapper; closure components carry no
|
|
@@ -219,7 +274,7 @@ const listOfCount = (count: number, done: number): TodoList =>
|
|
|
219
274
|
nextItemId: count + 1,
|
|
220
275
|
items: Array.from(
|
|
221
276
|
{ length: count },
|
|
222
|
-
(_, index) => new TodoItem({ id: index + 1,
|
|
277
|
+
(_, index) => new TodoItem({ id: index + 1, title: `item ${index + 1}`, done: index < done }),
|
|
223
278
|
),
|
|
224
279
|
});
|
|
225
280
|
|
|
@@ -239,7 +294,7 @@ const listWithDeps = (
|
|
|
239
294
|
(itemDeps, index) =>
|
|
240
295
|
new TodoItem({
|
|
241
296
|
id: index + 1,
|
|
242
|
-
|
|
297
|
+
title: `item ${index + 1}`,
|
|
243
298
|
done: done.includes(index),
|
|
244
299
|
deps: itemDeps,
|
|
245
300
|
}),
|
|
@@ -430,7 +485,7 @@ it("planner anchors on the first ready item, not the first open item", () => {
|
|
|
430
485
|
(_, index) =>
|
|
431
486
|
new TodoItem({
|
|
432
487
|
id: index + 1,
|
|
433
|
-
|
|
488
|
+
title: `item ${index + 1}`,
|
|
434
489
|
done: index === 0,
|
|
435
490
|
deps: index === 1 ? ["Work:30"] : [],
|
|
436
491
|
}),
|
|
@@ -465,3 +520,67 @@ it("annotates a done item whose dependency is open again in the overlay", () =>
|
|
|
465
520
|
assert.match(text, /\(waiting on #Work:1\)/);
|
|
466
521
|
notContain(text, "blocked by");
|
|
467
522
|
});
|
|
523
|
+
|
|
524
|
+
it("paints the selected overlay row with the selection background", () => {
|
|
525
|
+
// Marker theme: `style()` records the background token so the test can see
|
|
526
|
+
// the selection paint without a real terminal theme.
|
|
527
|
+
const markerTheme = {
|
|
528
|
+
...identityTheme,
|
|
529
|
+
style: (text: string, options: { bg?: string }) =>
|
|
530
|
+
options.bg === undefined ? text : `[${options.bg}]${text}[/${options.bg}]`,
|
|
531
|
+
} as unknown as Theme;
|
|
532
|
+
const overlay = makeTrackerOverlay({
|
|
533
|
+
getState: () => twoListState(),
|
|
534
|
+
theme: markerTheme,
|
|
535
|
+
requestRender: () => {},
|
|
536
|
+
onAction: async () => null,
|
|
537
|
+
onClose: () => {},
|
|
538
|
+
});
|
|
539
|
+
// The lists pane opens with the first list selected, so its row carries the
|
|
540
|
+
// background and unselected rows do not.
|
|
541
|
+
const lines = overlay.render(80);
|
|
542
|
+
assert.strictEqual(lines.filter((line) => line.includes("[selectedBg]")).length, 1);
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
/** Overlay with a recording clipboard, so copy tests never touch the OS. */
|
|
546
|
+
const makeCopyOverlay = (): { overlay: TrackerOverlayHandle; copied: string[] } => {
|
|
547
|
+
const copied: string[] = [];
|
|
548
|
+
const overlay = makeTrackerOverlay({
|
|
549
|
+
getState: () => twoListState(),
|
|
550
|
+
theme: identityTheme,
|
|
551
|
+
requestRender: () => {},
|
|
552
|
+
onAction: async () => null,
|
|
553
|
+
onClose: () => {},
|
|
554
|
+
copyText: async (text) => {
|
|
555
|
+
copied.push(text);
|
|
556
|
+
},
|
|
557
|
+
});
|
|
558
|
+
return { overlay, copied };
|
|
559
|
+
};
|
|
560
|
+
|
|
561
|
+
it("copies the selected list and reports it (c in the lists pane)", async () => {
|
|
562
|
+
const { overlay, copied } = makeCopyOverlay();
|
|
563
|
+
overlay.handleInput("c");
|
|
564
|
+
await flushAsync();
|
|
565
|
+
assert.deepStrictEqual(copied, ["Work"]);
|
|
566
|
+
assert.ok(overlay.render(80).some((line) => line.includes("Copied")));
|
|
567
|
+
});
|
|
568
|
+
|
|
569
|
+
it("copies the selected item reference and text (c in the items pane)", async () => {
|
|
570
|
+
const { overlay, copied } = makeCopyOverlay();
|
|
571
|
+
overlay.handleInput("\t"); // switch to the items pane
|
|
572
|
+
overlay.handleInput("c");
|
|
573
|
+
await flushAsync();
|
|
574
|
+
assert.strictEqual(copied.length, 1);
|
|
575
|
+
assert.match(copied[0]!, /^Work:\d+ /);
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
it("moves the selection on wheel events", () => {
|
|
579
|
+
const h = makeOverlay(twoListState());
|
|
580
|
+
assert.ok(h.overlay.render(80).join("\n").includes("→ ● Work"));
|
|
581
|
+
h.overlay.handleMouse({
|
|
582
|
+
type: "wheel",
|
|
583
|
+
wheelDelta: 1,
|
|
584
|
+
} as Parameters<TrackerOverlayHandle["handleMouse"]>[0]);
|
|
585
|
+
assert.ok(h.overlay.render(80).join("\n").includes("→ Home"));
|
|
586
|
+
});
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { copyToClipboard, type Theme } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import type { Component } from "@earendil-works/pi-tui";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
Key,
|
|
5
|
+
matchesKey,
|
|
6
|
+
truncateToWidth,
|
|
7
|
+
visibleWidth,
|
|
8
|
+
type TuiMouseEvent,
|
|
9
|
+
} from "@earendil-works/pi-tui";
|
|
4
10
|
import { makeBorderedBox } from "@ftrdotdev/pi-tui";
|
|
5
11
|
import {
|
|
6
12
|
firstReadyIndex,
|
|
@@ -9,9 +15,9 @@ import {
|
|
|
9
15
|
type DependencyItem,
|
|
10
16
|
type DependencyList,
|
|
11
17
|
type DependencyListView,
|
|
12
|
-
} from "
|
|
13
|
-
import type { TodoItem, TodoList, TrackerState } from "
|
|
14
|
-
import type { UpdateItemPatch } from "
|
|
18
|
+
} from "../core/deps.ts";
|
|
19
|
+
import type { TodoItem, TodoList, TrackerState } from "../core/domain.ts";
|
|
20
|
+
import type { UpdateItemPatch } from "../core/store.ts";
|
|
15
21
|
|
|
16
22
|
const MAX_LISTS = 8;
|
|
17
23
|
const MAX_ITEMS = 12;
|
|
@@ -22,6 +28,9 @@ const MARKER_WIDTH = 2;
|
|
|
22
28
|
const clamp = (value: number, min: number, max: number): number =>
|
|
23
29
|
Math.min(Math.max(value, min), max);
|
|
24
30
|
|
|
31
|
+
/** Positive modulo, so a wheel step past either end wraps. */
|
|
32
|
+
const wrap = (value: number, count: number): number => ((value % count) + count) % count;
|
|
33
|
+
|
|
25
34
|
// --------------------------------------------------------------------------
|
|
26
35
|
// Widget pane (ctx.ui.setWidget)
|
|
27
36
|
// --------------------------------------------------------------------------
|
|
@@ -36,7 +45,8 @@ const widgetLabel =
|
|
|
36
45
|
(theme: Theme): string => {
|
|
37
46
|
const done = list.items.filter((item) => item.done).length;
|
|
38
47
|
return (
|
|
39
|
-
theme.
|
|
48
|
+
theme.style(list.name, { fg: "accent", bold: true }) +
|
|
49
|
+
theme.fg("dim", ` (${done}/${list.items.length})`)
|
|
40
50
|
);
|
|
41
51
|
};
|
|
42
52
|
|
|
@@ -192,8 +202,21 @@ const widgetRows =
|
|
|
192
202
|
const item = view.list.items[row.index]!;
|
|
193
203
|
const blocked = (view.ready[row.index]?.blockers.length ?? 0) > 0;
|
|
194
204
|
const marker = itemMarker(item, blocked, row.index === current, theme);
|
|
195
|
-
const
|
|
196
|
-
|
|
205
|
+
const title = item.done
|
|
206
|
+
? theme.style(item.title, { fg: "muted", strikethrough: true })
|
|
207
|
+
: item.title;
|
|
208
|
+
rows.push(` ${marker}${title}`);
|
|
209
|
+
if (item.description.length > 0) {
|
|
210
|
+
// The widget row is one line, so a multi-line description collapses
|
|
211
|
+
// to single spaces before it is truncated.
|
|
212
|
+
const description = item.description.replace(/\s+/g, " ").trim();
|
|
213
|
+
rows.push(
|
|
214
|
+
truncateToWidth(
|
|
215
|
+
`${" ".repeat(2 + MARKER_WIDTH)}${theme.fg("dim", description)}`,
|
|
216
|
+
Math.max(0, _width),
|
|
217
|
+
),
|
|
218
|
+
);
|
|
219
|
+
}
|
|
197
220
|
}
|
|
198
221
|
return rows;
|
|
199
222
|
};
|
|
@@ -239,7 +262,7 @@ export type TrackerUiAction =
|
|
|
239
262
|
| { readonly type: "createList"; readonly name: string }
|
|
240
263
|
| { readonly type: "deleteList"; readonly listId: number }
|
|
241
264
|
| { readonly type: "setActive"; readonly listId: number | null }
|
|
242
|
-
| { readonly type: "addItem"; readonly listId: number; readonly
|
|
265
|
+
| { readonly type: "addItem"; readonly listId: number; readonly title: string }
|
|
243
266
|
| { readonly type: "updateItem"; readonly itemId: string; readonly patch: UpdateItemPatch }
|
|
244
267
|
| { readonly type: "removeItem"; readonly itemId: string };
|
|
245
268
|
|
|
@@ -261,6 +284,8 @@ export interface TrackerOverlayOptions {
|
|
|
261
284
|
readonly onAction: (action: TrackerUiAction) => Promise<string | null>;
|
|
262
285
|
/** Close the overlay. */
|
|
263
286
|
readonly onClose: () => void;
|
|
287
|
+
/** Write text to the clipboard. Defaults to pi's `copyToClipboard`. */
|
|
288
|
+
readonly copyText?: (text: string) => Promise<void>;
|
|
264
289
|
}
|
|
265
290
|
|
|
266
291
|
/** The interactive overlay surface: render + input + cache invalidation. */
|
|
@@ -268,6 +293,8 @@ export interface TrackerOverlayHandle {
|
|
|
268
293
|
readonly render: (width: number) => string[];
|
|
269
294
|
readonly invalidate: () => void;
|
|
270
295
|
readonly handleInput: (data: string) => void;
|
|
296
|
+
/** Move the cursor on wheel events; other mouse events are ignored. */
|
|
297
|
+
readonly handleMouse: (event: TuiMouseEvent) => { handled: boolean } | undefined;
|
|
271
298
|
}
|
|
272
299
|
|
|
273
300
|
/**
|
|
@@ -287,6 +314,8 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
287
314
|
let itemIndex = 0;
|
|
288
315
|
let input: InputMode | null = null;
|
|
289
316
|
let error: string | null = null;
|
|
317
|
+
let notice: string | null = null;
|
|
318
|
+
const writeClipboard = options.copyText ?? copyToClipboard;
|
|
290
319
|
|
|
291
320
|
// Render cache (tui.md "Performance"): lines are reused while the inputs
|
|
292
321
|
// (width, state snapshot, overlay state) are unchanged.
|
|
@@ -307,6 +336,7 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
307
336
|
if (matchesKey(data, Key.tab) || matchesKey(data, Key.shift("tab"))) {
|
|
308
337
|
mode = mode === "lists" ? "items" : "lists";
|
|
309
338
|
error = null;
|
|
339
|
+
notice = null;
|
|
310
340
|
syncCursors();
|
|
311
341
|
options.requestRender();
|
|
312
342
|
return;
|
|
@@ -315,10 +345,32 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
315
345
|
const handled = mode === "lists" ? handleListsKey(data, state) : handleItemsKey(data, state);
|
|
316
346
|
if (handled) {
|
|
317
347
|
error = null;
|
|
348
|
+
notice = null;
|
|
318
349
|
options.requestRender();
|
|
319
350
|
}
|
|
320
351
|
};
|
|
321
352
|
|
|
353
|
+
const handleMouse = (event: TuiMouseEvent): { handled: boolean } | undefined => {
|
|
354
|
+
if (event.type !== "wheel") return undefined;
|
|
355
|
+
const delta = event.wheelDelta ?? 0;
|
|
356
|
+
if (delta === 0 || input) return { handled: delta !== 0 };
|
|
357
|
+
// pi normalizes wheel events to logical lines (the renderer applies
|
|
358
|
+
// `WheelScrollAccelerator`), so the delta is the step count directly.
|
|
359
|
+
const step = Math.abs(delta);
|
|
360
|
+
const direction = delta > 0 ? step : -step;
|
|
361
|
+
const state = options.getState();
|
|
362
|
+
if (mode === "lists") {
|
|
363
|
+
const count = state.lists.length;
|
|
364
|
+
if (count > 0) listIndex = wrap(listIndex + direction, count);
|
|
365
|
+
} else {
|
|
366
|
+
const list = activeList(state);
|
|
367
|
+
const count = list ? orderedItems(list).length : 0;
|
|
368
|
+
if (count > 0) itemIndex = wrap(itemIndex + direction, count);
|
|
369
|
+
}
|
|
370
|
+
options.requestRender();
|
|
371
|
+
return { handled: true };
|
|
372
|
+
};
|
|
373
|
+
|
|
322
374
|
const render = (width: number): string[] => {
|
|
323
375
|
const theme = options.theme;
|
|
324
376
|
const state = options.getState();
|
|
@@ -335,7 +387,9 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
335
387
|
|
|
336
388
|
// Lists pane
|
|
337
389
|
const listsHeader =
|
|
338
|
-
mode === "lists"
|
|
390
|
+
mode === "lists"
|
|
391
|
+
? theme.style("Lists", { fg: "accent", bold: true })
|
|
392
|
+
: theme.fg("muted", "Lists");
|
|
339
393
|
lines.push(truncateToWidth(` ${listsHeader}`, width));
|
|
340
394
|
|
|
341
395
|
if (state.lists.length === 0) {
|
|
@@ -353,9 +407,12 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
353
407
|
const name = isActive ? `${theme.fg("success", "● ")}${list.name}` : list.name;
|
|
354
408
|
if (selected) {
|
|
355
409
|
lines.push(
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
410
|
+
theme.style(
|
|
411
|
+
truncateToWidth(
|
|
412
|
+
` ${theme.fg("accent", "→ ")}${theme.fg("accent", name)}${counts}`,
|
|
413
|
+
width,
|
|
414
|
+
),
|
|
415
|
+
{ bg: "selectedBg" },
|
|
359
416
|
),
|
|
360
417
|
);
|
|
361
418
|
} else {
|
|
@@ -376,12 +433,11 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
376
433
|
|
|
377
434
|
// Items pane
|
|
378
435
|
const activeListFor = activeList(state);
|
|
379
|
-
const
|
|
380
|
-
|
|
381
|
-
mode === "items"
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
);
|
|
436
|
+
const itemsTitle = `Items — ${activeListFor?.name ?? "(no list)"}`;
|
|
437
|
+
const itemsHeader = theme.style(itemsTitle, {
|
|
438
|
+
fg: mode === "items" ? "accent" : "muted",
|
|
439
|
+
bold: mode === "items",
|
|
440
|
+
});
|
|
385
441
|
lines.push(truncateToWidth(` ${itemsHeader}`, width));
|
|
386
442
|
|
|
387
443
|
if (!activeListFor) {
|
|
@@ -399,8 +455,18 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
399
455
|
const prefix = selected ? theme.fg("accent", "→ ") : " ";
|
|
400
456
|
const blocker = readinessSuffix(item.done, view.ready[index]?.blockers ?? []);
|
|
401
457
|
const check = itemMarker(item, blocker !== "", false, theme);
|
|
402
|
-
const
|
|
403
|
-
|
|
458
|
+
const title = item.done
|
|
459
|
+
? theme.style(item.title, { fg: "muted", strikethrough: true })
|
|
460
|
+
: item.title;
|
|
461
|
+
const row = truncateToWidth(`${prefix}${check}${title}${blocker}`, width);
|
|
462
|
+
lines.push(selected ? theme.style(row, { bg: "selectedBg" }) : row);
|
|
463
|
+
if (item.description.length > 0) {
|
|
464
|
+
// The overlay shows the full description; each source line becomes
|
|
465
|
+
// its own row so no embedded newline reaches the renderer.
|
|
466
|
+
for (const descriptionLine of item.description.split("\n")) {
|
|
467
|
+
lines.push(truncateToWidth(` ${theme.fg("dim", descriptionLine)}`, width));
|
|
468
|
+
}
|
|
469
|
+
}
|
|
404
470
|
}
|
|
405
471
|
if (activeListFor.items.length > MAX_ITEMS) {
|
|
406
472
|
lines.push(
|
|
@@ -419,21 +485,24 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
419
485
|
input.kind === "newList"
|
|
420
486
|
? "New list name"
|
|
421
487
|
: input.kind === "addItem"
|
|
422
|
-
? "Item
|
|
423
|
-
: "Edit item
|
|
488
|
+
? "Item title"
|
|
489
|
+
: "Edit item title";
|
|
424
490
|
lines.push(truncateToWidth(` ${theme.fg("accent", `${prompt}:`)} ${input.buffer}▌`, width));
|
|
425
491
|
lines.push(truncateToWidth(` ${theme.fg("dim", "enter confirm · esc cancel")}`, width));
|
|
426
492
|
} else if (error) {
|
|
427
493
|
lines.push("");
|
|
428
494
|
lines.push(truncateToWidth(` ${theme.fg("warning", `! ${error}`)}`, width));
|
|
495
|
+
} else if (notice) {
|
|
496
|
+
lines.push("");
|
|
497
|
+
lines.push(truncateToWidth(` ${theme.fg("success", `✓ ${notice}`)}`, width));
|
|
429
498
|
}
|
|
430
499
|
|
|
431
500
|
// Help
|
|
432
501
|
lines.push("");
|
|
433
502
|
const help =
|
|
434
503
|
mode === "lists"
|
|
435
|
-
? "[tab] items · [n] new · [d] delete · [space] toggle · [↑↓] move · [enter] active · [esc] close"
|
|
436
|
-
: "[tab] lists · [a] add · [x] toggle · [e] edit · [r] remove · [↑↓] move · [esc] close";
|
|
504
|
+
? "[tab] items · [n] new · [d] delete · [c] copy · [space] toggle · [↑↓] move · [enter] active · [esc] close"
|
|
505
|
+
: "[tab] lists · [a] add · [x] toggle · [e] edit · [r] remove · [c] copy · [↑↓] move · [esc] close";
|
|
437
506
|
lines.push(truncateToWidth(` ${theme.fg("dim", help)}`, width));
|
|
438
507
|
|
|
439
508
|
cachedWidth = width;
|
|
@@ -457,7 +526,7 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
457
526
|
*/
|
|
458
527
|
const thisSignature = (): string => {
|
|
459
528
|
const inputPart = input === null ? "" : `${input.kind}:${input.buffer}`;
|
|
460
|
-
return `${mode}:${listIndex}:${itemIndex}:${error ?? ""}:${inputPart}`;
|
|
529
|
+
return `${mode}:${listIndex}:${itemIndex}:${error ?? ""}:${notice ?? ""}:${inputPart}`;
|
|
461
530
|
};
|
|
462
531
|
|
|
463
532
|
const activeList = (state: TrackerState): TodoList | undefined => {
|
|
@@ -470,6 +539,19 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
470
539
|
return state.lists.find((list) => list.id === state.activeListId);
|
|
471
540
|
};
|
|
472
541
|
|
|
542
|
+
const copyText = (text: string, label: string): void => {
|
|
543
|
+
void writeClipboard(text).then(
|
|
544
|
+
() => {
|
|
545
|
+
notice = `Copied ${label}`;
|
|
546
|
+
options.requestRender();
|
|
547
|
+
},
|
|
548
|
+
(cause: unknown) => {
|
|
549
|
+
error = `Copy failed: ${cause instanceof Error ? cause.message : String(cause)}`;
|
|
550
|
+
options.requestRender();
|
|
551
|
+
},
|
|
552
|
+
);
|
|
553
|
+
};
|
|
554
|
+
|
|
473
555
|
const handleListsKey = (data: string, state: TrackerState): boolean => {
|
|
474
556
|
const lists = state.lists;
|
|
475
557
|
if (lists.length === 0) {
|
|
@@ -504,6 +586,11 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
504
586
|
void runAction({ type: "deleteList", listId: list.id });
|
|
505
587
|
return true;
|
|
506
588
|
}
|
|
589
|
+
if (data === "c") {
|
|
590
|
+
const list = lists[listIndex]!;
|
|
591
|
+
copyText(list.name, `list "${list.name}"`);
|
|
592
|
+
return true;
|
|
593
|
+
}
|
|
507
594
|
if (data === " " || matchesKey(data, Key.space)) {
|
|
508
595
|
// Toggle the highlighted list: selecting another list makes it active,
|
|
509
596
|
// toggling the already-active list deselects it (hiding the widget).
|
|
@@ -555,7 +642,7 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
555
642
|
input = {
|
|
556
643
|
kind: "editItem",
|
|
557
644
|
itemId: `${list.name}:${item.id}`,
|
|
558
|
-
buffer: item.
|
|
645
|
+
buffer: item.title,
|
|
559
646
|
};
|
|
560
647
|
return true;
|
|
561
648
|
}
|
|
@@ -569,6 +656,12 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
569
656
|
input = { kind: "newList", buffer: "" };
|
|
570
657
|
return true;
|
|
571
658
|
}
|
|
659
|
+
if (data === "c") {
|
|
660
|
+
const item = items[itemIndex];
|
|
661
|
+
if (!item) return true;
|
|
662
|
+
copyText(`${list.name}:${item.id} ${item.title}`, `item "${item.title}"`);
|
|
663
|
+
return true;
|
|
664
|
+
}
|
|
572
665
|
return false;
|
|
573
666
|
};
|
|
574
667
|
|
|
@@ -584,11 +677,11 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
584
677
|
current.kind === "newList"
|
|
585
678
|
? { type: "createList", name: current.buffer }
|
|
586
679
|
: current.kind === "addItem"
|
|
587
|
-
? { type: "addItem", listId: current.listId,
|
|
680
|
+
? { type: "addItem", listId: current.listId, title: current.buffer }
|
|
588
681
|
: {
|
|
589
682
|
type: "updateItem",
|
|
590
683
|
itemId: current.itemId,
|
|
591
|
-
patch: {
|
|
684
|
+
patch: { title: current.buffer },
|
|
592
685
|
};
|
|
593
686
|
void runAction(action);
|
|
594
687
|
} else if (matchesKey(data, Key.backspace)) {
|
|
@@ -621,5 +714,5 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
621
714
|
itemIndex = items.length === 0 ? 0 : clamp(itemIndex, 0, items.length - 1);
|
|
622
715
|
};
|
|
623
716
|
|
|
624
|
-
return { render, invalidate, handleInput };
|
|
717
|
+
return { render, invalidate, handleInput, handleMouse };
|
|
625
718
|
};
|