@ftrdotdev/pi-tracker 0.7.0 → 0.9.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/CHANGELOG.md +369 -0
- package/README.md +88 -9
- package/package.json +27 -16
- package/src/compaction/candidate.test.ts +66 -125
- package/src/compaction/classifier.test.ts +22 -2
- package/src/compaction/classifier.ts +35 -22
- package/src/compaction/completion.test.ts +24 -16
- package/src/compaction/completion.ts +1 -1
- package/src/compaction/decision-record.test.ts +1 -1
- package/src/compaction/decision-record.ts +1 -1
- package/src/compaction/digest.test.ts +34 -34
- package/src/compaction/footprint.ts +2 -4
- package/src/compaction/settings.test.ts +5 -1
- package/src/compaction/settings.ts +1 -1
- package/src/compaction/settle.test.ts +50 -10
- package/src/compaction/settle.ts +5 -5
- package/src/core/deps.test.ts +128 -109
- package/src/core/deps.ts +3 -2
- package/src/core/domain.test.ts +99 -68
- package/src/core/domain.ts +16 -10
- package/src/core/persistence.test.ts +18 -19
- package/src/core/persistence.ts +4 -3
- package/src/core/store.test.ts +129 -167
- package/src/core/store.ts +77 -57
- package/src/harness-collection.test.ts +75 -0
- package/src/index.test.ts +59 -17
- package/src/index.ts +63 -64
- package/src/layers.test.ts +101 -0
- package/src/layers.ts +46 -0
- package/src/presentation/tool-metadata.test.ts +36 -38
- package/src/presentation/tool-metadata.ts +127 -130
- package/src/presentation/ui.test.ts +128 -67
- package/src/presentation/ui.ts +68 -20
- package/src/presentation/vim-settings.test.ts +101 -0
- package/src/presentation/vim-settings.ts +59 -0
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { assert, it } from "@effect/vitest";
|
|
2
|
-
import
|
|
1
|
+
import { assert, it, vi } from "@effect/vitest";
|
|
2
|
+
import { themeDouble } from "@ftrdotdev/pi-test-kit";
|
|
3
3
|
import { visibleWidth } from "@earendil-works/pi-tui";
|
|
4
|
+
import { VimRouter } from "@ftrdotdev/pi-tui";
|
|
5
|
+
import { Effect } from "effect";
|
|
4
6
|
import { orderedItems } from "../core/deps.ts";
|
|
5
7
|
import { TodoItem, TodoList, TrackerState } from "../core/domain.ts";
|
|
6
8
|
import {
|
|
@@ -15,32 +17,26 @@ import {
|
|
|
15
17
|
|
|
16
18
|
/**
|
|
17
19
|
* Identity theme: styles pass text through unchanged, so render output is
|
|
18
|
-
* plain text that assertions can search.
|
|
19
|
-
* `fg`, `bold`, `strikethrough` and `style`, which this stub covers.
|
|
20
|
+
* plain text that assertions can search.
|
|
20
21
|
*/
|
|
21
|
-
const identityTheme =
|
|
22
|
-
fg: (_color: string, text: string): string => text,
|
|
23
|
-
bold: (text: string): string => text,
|
|
24
|
-
strikethrough: (text: string): string => text,
|
|
25
|
-
style: (text: string): string => text,
|
|
26
|
-
} as unknown as Theme;
|
|
22
|
+
const identityTheme = themeDouble();
|
|
27
23
|
|
|
28
24
|
/** A realistic two-list state: Work is the active list. */
|
|
29
25
|
const twoListState = (): TrackerState =>
|
|
30
|
-
|
|
26
|
+
TrackerState.make({
|
|
31
27
|
lists: [
|
|
32
|
-
|
|
28
|
+
TodoList.make({
|
|
33
29
|
id: 1,
|
|
34
30
|
name: "Work",
|
|
35
31
|
items: [
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
TodoItem.make({ title: "write plan", done: true }),
|
|
33
|
+
TodoItem.make({ title: "implement tracker", done: false }),
|
|
38
34
|
],
|
|
39
35
|
}),
|
|
40
|
-
|
|
36
|
+
TodoList.make({
|
|
41
37
|
id: 2,
|
|
42
38
|
name: "Home",
|
|
43
|
-
items: [
|
|
39
|
+
items: [TodoItem.make({ title: "water plants", done: false })],
|
|
44
40
|
}),
|
|
45
41
|
],
|
|
46
42
|
activeListId: 1,
|
|
@@ -61,13 +57,20 @@ interface OverlayHarness {
|
|
|
61
57
|
readonly actions: TrackerUiAction[];
|
|
62
58
|
}
|
|
63
59
|
|
|
60
|
+
/** Build a real `VimRouter` service gated on `enabled`. */
|
|
61
|
+
const vimRouter = (enabled: boolean): VimRouter["Service"] =>
|
|
62
|
+
Effect.service(VimRouter).pipe(Effect.provide(VimRouter.make(() => enabled)), Effect.runSync);
|
|
63
|
+
|
|
64
64
|
/**
|
|
65
65
|
* Build an overlay over a scripted state. `onAction` mirrors the real
|
|
66
66
|
* bridge's `set_active` handling (the only action the tests exercise), so
|
|
67
67
|
* the snapshot passed to `getState` follows the same object-identity rules
|
|
68
68
|
* as the live mirror in `src/index.ts`.
|
|
69
69
|
*/
|
|
70
|
-
const makeOverlay = (
|
|
70
|
+
const makeOverlay = (
|
|
71
|
+
initial: TrackerState,
|
|
72
|
+
vim?: { readonly router: VimRouter["Service"]; readonly enabled: boolean },
|
|
73
|
+
): OverlayHarness => {
|
|
71
74
|
let current = initial;
|
|
72
75
|
const actions: TrackerUiAction[] = [];
|
|
73
76
|
const overlay = makeTrackerOverlay({
|
|
@@ -77,31 +80,33 @@ const makeOverlay = (initial: TrackerState): OverlayHarness => {
|
|
|
77
80
|
onAction: async (action) => {
|
|
78
81
|
actions.push(action);
|
|
79
82
|
if (action.type === "setActive") {
|
|
80
|
-
current =
|
|
83
|
+
current = TrackerState.make({
|
|
84
|
+
lists: current.lists,
|
|
85
|
+
activeListId: action.listId,
|
|
86
|
+
nextListId: current.nextListId,
|
|
87
|
+
});
|
|
81
88
|
}
|
|
82
89
|
return null;
|
|
83
90
|
},
|
|
84
91
|
onClose: () => {},
|
|
92
|
+
...(vim === undefined ? {} : { vim }),
|
|
85
93
|
});
|
|
86
94
|
return { overlay, actions };
|
|
87
95
|
};
|
|
88
96
|
|
|
89
|
-
/** Flush the microtask queue so fire-and-forget `runAction` continuations land. */
|
|
90
|
-
const flushAsync = (): Promise<void> => new Promise((resolve) => setTimeout(resolve, 0));
|
|
91
|
-
|
|
92
97
|
// --------------------------------------------------------------------------
|
|
93
98
|
// Interactive overlay: items pane follows the focused list
|
|
94
99
|
// --------------------------------------------------------------------------
|
|
95
100
|
|
|
96
101
|
it("overlay renders a multi-line description as separate lines", () => {
|
|
97
|
-
const list =
|
|
102
|
+
const list = TodoList.make({
|
|
98
103
|
id: 1,
|
|
99
104
|
name: "Work",
|
|
100
105
|
items: [
|
|
101
|
-
|
|
106
|
+
TodoItem.make({ id: 1, title: "multi", description: "first line\nsecond line", done: false }),
|
|
102
107
|
],
|
|
103
108
|
});
|
|
104
|
-
const h = makeOverlay(
|
|
109
|
+
const h = makeOverlay(TrackerState.make({ lists: [list], activeListId: 1, nextListId: 2 }));
|
|
105
110
|
const lines = h.overlay.render(80);
|
|
106
111
|
assert.equal(
|
|
107
112
|
lines.some((line) => line.includes("\n")),
|
|
@@ -137,9 +142,10 @@ it("enter commits the focused list as active and opens its items", async () => {
|
|
|
137
142
|
const h = makeOverlay(twoListState());
|
|
138
143
|
h.overlay.handleInput("\x1b[B"); // focus Home
|
|
139
144
|
h.overlay.handleInput("\r"); // commit
|
|
140
|
-
await flushAsync();
|
|
141
145
|
|
|
142
|
-
|
|
146
|
+
await vi.waitFor(() => {
|
|
147
|
+
assert.deepStrictEqual(h.actions, [{ type: "setActive", listId: 2 }]);
|
|
148
|
+
});
|
|
143
149
|
const text = h.overlay.render(80).join("\n");
|
|
144
150
|
assert.match(text, /Items — Home/);
|
|
145
151
|
assert.match(text, /water plants/);
|
|
@@ -156,6 +162,57 @@ it("items pane follows the active list in items mode (preview is not a commit)",
|
|
|
156
162
|
assert.match(text, /write plan/);
|
|
157
163
|
});
|
|
158
164
|
|
|
165
|
+
// --------------------------------------------------------------------------
|
|
166
|
+
// Vim navigation (h/j/k/l) behind the vim toggle
|
|
167
|
+
// --------------------------------------------------------------------------
|
|
168
|
+
|
|
169
|
+
it("hjkl moves the list cursor and switches panes when vim is on", () => {
|
|
170
|
+
const h = makeOverlay(twoListState(), { router: vimRouter(true), enabled: true });
|
|
171
|
+
const text = () => h.overlay.render(80).join("\n");
|
|
172
|
+
|
|
173
|
+
// j previews the next list; k returns to the previous one.
|
|
174
|
+
h.overlay.handleInput("j");
|
|
175
|
+
assert.match(text(), /Items — Home/);
|
|
176
|
+
h.overlay.handleInput("k");
|
|
177
|
+
assert.match(text(), /Items — Work/);
|
|
178
|
+
|
|
179
|
+
// l opens the items pane; h returns to the lists pane.
|
|
180
|
+
h.overlay.handleInput("l");
|
|
181
|
+
assert.match(text(), /\[tab\] lists/);
|
|
182
|
+
h.overlay.handleInput("h");
|
|
183
|
+
assert.match(text(), /\[tab\] items/);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it("hjkl is inert when the vim toggle is off", () => {
|
|
187
|
+
const h = makeOverlay(twoListState(), { router: vimRouter(false), enabled: false });
|
|
188
|
+
const text = () => h.overlay.render(80).join("\n");
|
|
189
|
+
|
|
190
|
+
h.overlay.handleInput("j");
|
|
191
|
+
assert.match(text(), /Items — Work/);
|
|
192
|
+
h.overlay.handleInput("l");
|
|
193
|
+
assert.match(text(), /\[tab\] items/); // still lists mode
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it("arrow left and right switch panes", () => {
|
|
197
|
+
const h = makeOverlay(twoListState());
|
|
198
|
+
const text = () => h.overlay.render(80).join("\n");
|
|
199
|
+
|
|
200
|
+
h.overlay.handleInput("\x1b[C"); // right
|
|
201
|
+
assert.match(text(), /\[tab\] lists/);
|
|
202
|
+
h.overlay.handleInput("\x1b[D"); // left
|
|
203
|
+
assert.match(text(), /\[tab\] items/);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it("help shows hjkl only when vim is on", () => {
|
|
207
|
+
const off = makeOverlay(twoListState(), { router: vimRouter(false), enabled: false });
|
|
208
|
+
const offText = off.overlay.render(200).join("\n");
|
|
209
|
+
assert.match(offText, /\[↑↓←→\] move/);
|
|
210
|
+
assert.equal(offText.includes("hjkl"), false);
|
|
211
|
+
|
|
212
|
+
const on = makeOverlay(twoListState(), { router: vimRouter(true), enabled: true });
|
|
213
|
+
assert.match(on.overlay.render(200).join("\n"), /\[↑↓←→\/hjkl\] move/);
|
|
214
|
+
});
|
|
215
|
+
|
|
159
216
|
// --------------------------------------------------------------------------
|
|
160
217
|
// Render caching (tui.md "Performance" / "Invalidation and Theme Changes")
|
|
161
218
|
// --------------------------------------------------------------------------
|
|
@@ -207,18 +264,22 @@ it("widget renders the active list's items", () => {
|
|
|
207
264
|
});
|
|
208
265
|
|
|
209
266
|
it("widget renders nothing when no list is active (bridge hides it)", () => {
|
|
210
|
-
const state =
|
|
267
|
+
const state = TrackerState.make({
|
|
268
|
+
lists: twoListState().lists,
|
|
269
|
+
activeListId: null,
|
|
270
|
+
nextListId: twoListState().nextListId,
|
|
271
|
+
});
|
|
211
272
|
assert.deepStrictEqual(renderTrackerWidget(state, identityTheme, 40), []);
|
|
212
273
|
});
|
|
213
274
|
|
|
214
275
|
it("widget shows a dimmed description line truncated to the width", () => {
|
|
215
276
|
const description = "x".repeat(120);
|
|
216
|
-
const list =
|
|
277
|
+
const list = TodoList.make({
|
|
217
278
|
id: 1,
|
|
218
279
|
name: "Work",
|
|
219
|
-
items: [
|
|
280
|
+
items: [TodoItem.make({ id: 1, title: "long item", description, done: false })],
|
|
220
281
|
});
|
|
221
|
-
const state =
|
|
282
|
+
const state = TrackerState.make({ lists: [list], activeListId: 1, nextListId: 2 });
|
|
222
283
|
const width = 40;
|
|
223
284
|
const lines = renderTrackerWidget(state, identityTheme, width);
|
|
224
285
|
const text = lines.join("\n");
|
|
@@ -230,14 +291,14 @@ it("widget shows a dimmed description line truncated to the width", () => {
|
|
|
230
291
|
});
|
|
231
292
|
|
|
232
293
|
it("widget collapses a multi-line description into one line", () => {
|
|
233
|
-
const list =
|
|
294
|
+
const list = TodoList.make({
|
|
234
295
|
id: 1,
|
|
235
296
|
name: "Work",
|
|
236
297
|
items: [
|
|
237
|
-
|
|
298
|
+
TodoItem.make({ id: 1, title: "multi", description: "first line\nsecond line", done: false }),
|
|
238
299
|
],
|
|
239
300
|
});
|
|
240
|
-
const state =
|
|
301
|
+
const state = TrackerState.make({ lists: [list], activeListId: 1, nextListId: 2 });
|
|
241
302
|
const lines = renderTrackerWidget(state, identityTheme, 60);
|
|
242
303
|
assert.equal(
|
|
243
304
|
lines.some((line) => line.includes("\n")),
|
|
@@ -268,13 +329,12 @@ it("widget survives the setWidget bridge wrapper (render/invalidate handed off b
|
|
|
268
329
|
|
|
269
330
|
/** A list of `count` items; the first `done` items are done. */
|
|
270
331
|
const listOfCount = (count: number, done: number): TodoList =>
|
|
271
|
-
|
|
332
|
+
TodoList.make({
|
|
272
333
|
id: 1,
|
|
273
334
|
name: "Work",
|
|
274
335
|
nextItemId: count + 1,
|
|
275
|
-
items: Array.from(
|
|
276
|
-
{
|
|
277
|
-
(_, index) => new TodoItem({ id: index + 1, title: `item ${index + 1}`, done: index < done }),
|
|
336
|
+
items: Array.from({ length: count }, (_, index) =>
|
|
337
|
+
TodoItem.make({ id: index + 1, title: `item ${index + 1}`, done: index < done }),
|
|
278
338
|
),
|
|
279
339
|
});
|
|
280
340
|
|
|
@@ -286,23 +346,22 @@ const listWithDeps = (
|
|
|
286
346
|
deps: ReadonlyArray<readonly string[]>,
|
|
287
347
|
done: readonly number[] = [],
|
|
288
348
|
): TodoList =>
|
|
289
|
-
|
|
349
|
+
TodoList.make({
|
|
290
350
|
id: 1,
|
|
291
351
|
name: "Work",
|
|
292
352
|
nextItemId: deps.length + 1,
|
|
293
|
-
items: deps.map(
|
|
294
|
-
(
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
}),
|
|
353
|
+
items: deps.map((itemDeps, index) =>
|
|
354
|
+
TodoItem.make({
|
|
355
|
+
id: index + 1,
|
|
356
|
+
title: `item ${index + 1}`,
|
|
357
|
+
done: done.includes(index),
|
|
358
|
+
deps: itemDeps,
|
|
359
|
+
}),
|
|
301
360
|
),
|
|
302
361
|
});
|
|
303
362
|
|
|
304
363
|
const stateWith = (list: TodoList): TrackerState =>
|
|
305
|
-
|
|
364
|
+
TrackerState.make({ lists: [list], activeListId: list.id, nextListId: 2 });
|
|
306
365
|
|
|
307
366
|
const shownIndexes = (rows: readonly WidgetRow[]): number[] =>
|
|
308
367
|
rows.flatMap((row) => (row.kind === "item" ? [row.index] : []));
|
|
@@ -476,19 +535,17 @@ it("a dependency-free list renders exactly as before", () => {
|
|
|
476
535
|
it("planner anchors on the first ready item, not the first open item", () => {
|
|
477
536
|
// Item 1 is done; item 2 waits for item 30. The first open item is item 2
|
|
478
537
|
// and the first ready item is item 3.
|
|
479
|
-
const list =
|
|
538
|
+
const list = TodoList.make({
|
|
480
539
|
id: 1,
|
|
481
540
|
name: "Work",
|
|
482
541
|
nextItemId: 31,
|
|
483
|
-
items: Array.from(
|
|
484
|
-
{
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
deps: index === 1 ? ["Work:30"] : [],
|
|
491
|
-
}),
|
|
542
|
+
items: Array.from({ length: 30 }, (_, index) =>
|
|
543
|
+
TodoItem.make({
|
|
544
|
+
id: index + 1,
|
|
545
|
+
title: `item ${index + 1}`,
|
|
546
|
+
done: index === 0,
|
|
547
|
+
deps: index === 1 ? ["Work:30"] : [],
|
|
548
|
+
}),
|
|
492
549
|
),
|
|
493
550
|
});
|
|
494
551
|
// Item 2 sits last in the derived order, after everything it waits for.
|
|
@@ -524,11 +581,13 @@ it("annotates a done item whose dependency is open again in the overlay", () =>
|
|
|
524
581
|
it("paints the selected overlay row with the selection background", () => {
|
|
525
582
|
// Marker theme: `style()` records the background token so the test can see
|
|
526
583
|
// the selection paint without a real terminal theme.
|
|
527
|
-
const markerTheme = {
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
options.bg ===
|
|
531
|
-
|
|
584
|
+
const markerTheme = themeDouble({
|
|
585
|
+
style: (text, options) => {
|
|
586
|
+
// Only a background token is marked; a concrete terminal color is not.
|
|
587
|
+
const bg = typeof options.bg === "string" ? options.bg : undefined;
|
|
588
|
+
return bg === undefined ? text : `[${bg}]${text}[/${bg}]`;
|
|
589
|
+
},
|
|
590
|
+
});
|
|
532
591
|
const overlay = makeTrackerOverlay({
|
|
533
592
|
getState: () => twoListState(),
|
|
534
593
|
theme: markerTheme,
|
|
@@ -561,8 +620,9 @@ const makeCopyOverlay = (): { overlay: TrackerOverlayHandle; copied: string[] }
|
|
|
561
620
|
it("copies the selected list and reports it (c in the lists pane)", async () => {
|
|
562
621
|
const { overlay, copied } = makeCopyOverlay();
|
|
563
622
|
overlay.handleInput("c");
|
|
564
|
-
await
|
|
565
|
-
|
|
623
|
+
await vi.waitFor(() => {
|
|
624
|
+
assert.deepStrictEqual(copied, ["Work"]);
|
|
625
|
+
});
|
|
566
626
|
assert.ok(overlay.render(80).some((line) => line.includes("Copied")));
|
|
567
627
|
});
|
|
568
628
|
|
|
@@ -570,9 +630,10 @@ it("copies the selected item reference and text (c in the items pane)", async ()
|
|
|
570
630
|
const { overlay, copied } = makeCopyOverlay();
|
|
571
631
|
overlay.handleInput("\t"); // switch to the items pane
|
|
572
632
|
overlay.handleInput("c");
|
|
573
|
-
await
|
|
574
|
-
|
|
575
|
-
|
|
633
|
+
await vi.waitFor(() => {
|
|
634
|
+
assert.strictEqual(copied.length, 1);
|
|
635
|
+
assert.match(copied[0]!, /^Work:\d+ /);
|
|
636
|
+
});
|
|
576
637
|
});
|
|
577
638
|
|
|
578
639
|
it("moves the selection on wheel events", () => {
|
package/src/presentation/ui.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
visibleWidth,
|
|
8
8
|
type TuiMouseEvent,
|
|
9
9
|
} from "@earendil-works/pi-tui";
|
|
10
|
-
import { makeBorderedBox } from "@ftrdotdev/pi-tui";
|
|
10
|
+
import { makeBorderedBox, type NavigationIntent, type VimRouter } from "@ftrdotdev/pi-tui";
|
|
11
11
|
import {
|
|
12
12
|
firstReadyIndex,
|
|
13
13
|
orderedItems,
|
|
@@ -232,7 +232,7 @@ const widgetRows =
|
|
|
232
232
|
*/
|
|
233
233
|
export const makeTrackerWidget = (state: TrackerState, theme: Theme): Component => {
|
|
234
234
|
const list = activeList(state);
|
|
235
|
-
if (
|
|
235
|
+
if (list === undefined) {
|
|
236
236
|
// No list is active: render nothing. The bridge hides the widget in this
|
|
237
237
|
// case; an empty component keeps the seam safe regardless.
|
|
238
238
|
return { render: () => [], invalidate: () => {} };
|
|
@@ -250,8 +250,11 @@ export const makeTrackerWidget = (state: TrackerState, theme: Theme): Component
|
|
|
250
250
|
* Lines for the widget pane, or an empty array when no list is active — the
|
|
251
251
|
* bridge hides the widget in that case. Kept as a convenience for tests.
|
|
252
252
|
*/
|
|
253
|
-
export const renderTrackerWidget = (
|
|
254
|
-
|
|
253
|
+
export const renderTrackerWidget = (
|
|
254
|
+
state: TrackerState,
|
|
255
|
+
theme: Theme,
|
|
256
|
+
width: number,
|
|
257
|
+
): readonly string[] => makeTrackerWidget(state, theme).render(Math.max(4, width));
|
|
255
258
|
|
|
256
259
|
// --------------------------------------------------------------------------
|
|
257
260
|
// Interactive overlay (/tracker command)
|
|
@@ -286,6 +289,11 @@ export interface TrackerOverlayOptions {
|
|
|
286
289
|
readonly onClose: () => void;
|
|
287
290
|
/** Write text to the clipboard. Defaults to pi's `copyToClipboard`. */
|
|
288
291
|
readonly copyText?: (text: string) => Promise<void>;
|
|
292
|
+
/**
|
|
293
|
+
* The shared vim navigation router, gated on the `vim` toggle by the bridge.
|
|
294
|
+
* When omitted the overlay is arrow-only. `enabled` drives the help line.
|
|
295
|
+
*/
|
|
296
|
+
readonly vim?: { readonly router: VimRouter["Service"]; readonly enabled: boolean };
|
|
289
297
|
}
|
|
290
298
|
|
|
291
299
|
/** The interactive overlay surface: render + input + cache invalidation. */
|
|
@@ -325,7 +333,7 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
325
333
|
let cachedSignature: string | undefined;
|
|
326
334
|
|
|
327
335
|
const handleInput = (data: string): void => {
|
|
328
|
-
if (input) {
|
|
336
|
+
if (input !== null) {
|
|
329
337
|
handleInputMode(data);
|
|
330
338
|
return;
|
|
331
339
|
}
|
|
@@ -342,6 +350,14 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
342
350
|
return;
|
|
343
351
|
}
|
|
344
352
|
const state = options.getState();
|
|
353
|
+
const intent = options.vim?.router.decodeNavigation(data);
|
|
354
|
+
if (intent !== undefined) {
|
|
355
|
+
applyNavigation(intent, state);
|
|
356
|
+
error = null;
|
|
357
|
+
notice = null;
|
|
358
|
+
options.requestRender();
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
345
361
|
const handled = mode === "lists" ? handleListsKey(data, state) : handleItemsKey(data, state);
|
|
346
362
|
if (handled) {
|
|
347
363
|
error = null;
|
|
@@ -353,7 +369,7 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
353
369
|
const handleMouse = (event: TuiMouseEvent): { handled: boolean } | undefined => {
|
|
354
370
|
if (event.type !== "wheel") return undefined;
|
|
355
371
|
const delta = event.wheelDelta ?? 0;
|
|
356
|
-
if (delta === 0 || input) return { handled: delta !== 0 };
|
|
372
|
+
if (delta === 0 || input !== null) return { handled: delta !== 0 };
|
|
357
373
|
// pi normalizes wheel events to logical lines (the renderer applies
|
|
358
374
|
// `WheelScrollAccelerator`), so the delta is the step count directly.
|
|
359
375
|
const step = Math.abs(delta);
|
|
@@ -364,7 +380,7 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
364
380
|
if (count > 0) listIndex = wrap(listIndex + direction, count);
|
|
365
381
|
} else {
|
|
366
382
|
const list = activeList(state);
|
|
367
|
-
const count = list ? orderedItems(list).length : 0;
|
|
383
|
+
const count = list !== undefined ? orderedItems(list).length : 0;
|
|
368
384
|
if (count > 0) itemIndex = wrap(itemIndex + direction, count);
|
|
369
385
|
}
|
|
370
386
|
options.requestRender();
|
|
@@ -440,7 +456,7 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
440
456
|
});
|
|
441
457
|
lines.push(truncateToWidth(` ${itemsHeader}`, width));
|
|
442
458
|
|
|
443
|
-
if (
|
|
459
|
+
if (activeListFor === undefined) {
|
|
444
460
|
const hint =
|
|
445
461
|
state.lists.length === 0
|
|
446
462
|
? "No lists yet — press n to create one"
|
|
@@ -479,7 +495,7 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
479
495
|
}
|
|
480
496
|
|
|
481
497
|
// Input prompt / error line
|
|
482
|
-
if (input) {
|
|
498
|
+
if (input !== null) {
|
|
483
499
|
lines.push("");
|
|
484
500
|
const prompt =
|
|
485
501
|
input.kind === "newList"
|
|
@@ -489,20 +505,21 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
489
505
|
: "Edit item title";
|
|
490
506
|
lines.push(truncateToWidth(` ${theme.fg("accent", `${prompt}:`)} ${input.buffer}▌`, width));
|
|
491
507
|
lines.push(truncateToWidth(` ${theme.fg("dim", "enter confirm · esc cancel")}`, width));
|
|
492
|
-
} else if (error) {
|
|
508
|
+
} else if (error !== null && error !== "") {
|
|
493
509
|
lines.push("");
|
|
494
510
|
lines.push(truncateToWidth(` ${theme.fg("warning", `! ${error}`)}`, width));
|
|
495
|
-
} else if (notice) {
|
|
511
|
+
} else if (notice !== null && notice !== "") {
|
|
496
512
|
lines.push("");
|
|
497
513
|
lines.push(truncateToWidth(` ${theme.fg("success", `✓ ${notice}`)}`, width));
|
|
498
514
|
}
|
|
499
515
|
|
|
500
516
|
// Help
|
|
501
517
|
lines.push("");
|
|
518
|
+
const move = (options.vim?.enabled ?? false) ? "[↑↓←→/hjkl] move" : "[↑↓←→] move";
|
|
502
519
|
const help =
|
|
503
520
|
mode === "lists"
|
|
504
|
-
?
|
|
505
|
-
:
|
|
521
|
+
? `[tab] items · [n] new · [d] delete · [c] copy · [space] toggle · ${move} · [enter] active · [esc] close`
|
|
522
|
+
: `[tab] lists · [a] add · [x] toggle · [e] edit · [r] remove · [c] copy · ${move} · [esc] close`;
|
|
506
523
|
lines.push(truncateToWidth(` ${theme.fg("dim", help)}`, width));
|
|
507
524
|
|
|
508
525
|
cachedWidth = width;
|
|
@@ -552,6 +569,27 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
552
569
|
);
|
|
553
570
|
};
|
|
554
571
|
|
|
572
|
+
/**
|
|
573
|
+
* Apply a router movement intent. Up/down move the cursor of the focused
|
|
574
|
+
* pane; left/right switch panes, so h/l mirror Tab.
|
|
575
|
+
*/
|
|
576
|
+
const applyNavigation = (intent: NavigationIntent, state: TrackerState): void => {
|
|
577
|
+
if (intent.dir === "up" || intent.dir === "down") {
|
|
578
|
+
const step = intent.dir === "down" ? 1 : -1;
|
|
579
|
+
if (mode === "lists") {
|
|
580
|
+
const count = state.lists.length;
|
|
581
|
+
if (count > 0) listIndex = wrap(listIndex + step, count);
|
|
582
|
+
} else {
|
|
583
|
+
const list = activeList(state);
|
|
584
|
+
const count = list !== undefined ? orderedItems(list).length : 0;
|
|
585
|
+
if (count > 0) itemIndex = wrap(itemIndex + step, count);
|
|
586
|
+
}
|
|
587
|
+
return;
|
|
588
|
+
}
|
|
589
|
+
mode = intent.dir === "right" ? "items" : "lists";
|
|
590
|
+
syncCursors();
|
|
591
|
+
};
|
|
592
|
+
|
|
555
593
|
const handleListsKey = (data: string, state: TrackerState): boolean => {
|
|
556
594
|
const lists = state.lists;
|
|
557
595
|
if (lists.length === 0) {
|
|
@@ -569,6 +607,11 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
569
607
|
listIndex = (listIndex + 1) % lists.length;
|
|
570
608
|
return true;
|
|
571
609
|
}
|
|
610
|
+
if (matchesKey(data, Key.right)) {
|
|
611
|
+
mode = "items";
|
|
612
|
+
syncCursors();
|
|
613
|
+
return true;
|
|
614
|
+
}
|
|
572
615
|
if (matchesKey(data, Key.enter)) {
|
|
573
616
|
const list = lists[listIndex]!;
|
|
574
617
|
void runAction({ type: "setActive", listId: list.id }, () => {
|
|
@@ -604,7 +647,7 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
604
647
|
|
|
605
648
|
const handleItemsKey = (data: string, state: TrackerState): boolean => {
|
|
606
649
|
const list = activeList(state);
|
|
607
|
-
if (
|
|
650
|
+
if (list === undefined) {
|
|
608
651
|
if (data === "n") {
|
|
609
652
|
input = { kind: "newList", buffer: "" };
|
|
610
653
|
return true;
|
|
@@ -622,9 +665,14 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
622
665
|
if (items.length > 0) itemIndex = (itemIndex + 1) % items.length;
|
|
623
666
|
return true;
|
|
624
667
|
}
|
|
668
|
+
if (matchesKey(data, Key.left)) {
|
|
669
|
+
mode = "lists";
|
|
670
|
+
syncCursors();
|
|
671
|
+
return true;
|
|
672
|
+
}
|
|
625
673
|
if (matchesKey(data, Key.enter) || data === "x") {
|
|
626
674
|
const item = items[itemIndex];
|
|
627
|
-
if (
|
|
675
|
+
if (item === undefined) return true;
|
|
628
676
|
void runAction({
|
|
629
677
|
type: "updateItem",
|
|
630
678
|
itemId: `${list.name}:${item.id}`,
|
|
@@ -638,7 +686,7 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
638
686
|
}
|
|
639
687
|
if (data === "e") {
|
|
640
688
|
const item = items[itemIndex];
|
|
641
|
-
if (
|
|
689
|
+
if (item === undefined) return true;
|
|
642
690
|
input = {
|
|
643
691
|
kind: "editItem",
|
|
644
692
|
itemId: `${list.name}:${item.id}`,
|
|
@@ -648,7 +696,7 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
648
696
|
}
|
|
649
697
|
if (data === "r") {
|
|
650
698
|
const item = items[itemIndex];
|
|
651
|
-
if (
|
|
699
|
+
if (item === undefined) return true;
|
|
652
700
|
void runAction({ type: "removeItem", itemId: `${list.name}:${item.id}` });
|
|
653
701
|
return true;
|
|
654
702
|
}
|
|
@@ -658,7 +706,7 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
658
706
|
}
|
|
659
707
|
if (data === "c") {
|
|
660
708
|
const item = items[itemIndex];
|
|
661
|
-
if (
|
|
709
|
+
if (item === undefined) return true;
|
|
662
710
|
copyText(`${list.name}:${item.id} ${item.title}`, `item "${item.title}"`);
|
|
663
711
|
return true;
|
|
664
712
|
}
|
|
@@ -667,7 +715,7 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
667
715
|
|
|
668
716
|
const handleInputMode = (data: string): void => {
|
|
669
717
|
const current = input;
|
|
670
|
-
if (
|
|
718
|
+
if (current === null) return;
|
|
671
719
|
if (matchesKey(data, Key.escape)) {
|
|
672
720
|
input = null;
|
|
673
721
|
error = null;
|
|
@@ -695,7 +743,7 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
695
743
|
|
|
696
744
|
const runAction = async (action: TrackerUiAction, afterSuccess?: () => void): Promise<void> => {
|
|
697
745
|
const actionError = await options.onAction(action);
|
|
698
|
-
if (actionError) {
|
|
746
|
+
if (actionError !== null && actionError !== "") {
|
|
699
747
|
error = actionError;
|
|
700
748
|
} else {
|
|
701
749
|
error = null;
|