@ftrdotdev/pi-tui 0.2.0 → 0.2.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ftrdotdev/pi-tui",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "House TUI components and the pi interface extension: themed boxes, a pure box-frame model, and the header/footer/editor/settings/preview chrome",
5
5
  "keywords": [
6
6
  "components",
@@ -29,7 +29,6 @@ export { VimRouter, type NavigationIntent } from "../vim/vim-router.ts";
29
29
  // and `.configure` to inject/override the editor's border tint.
30
30
  export {
31
31
  EditorTintService,
32
- EditorTintServiceDefault,
33
32
  upsertBorderTintProvider,
34
33
  type BorderTintProvider,
35
34
  } from "../ui/editor-tint.ts";
package/src/index.ts CHANGED
@@ -19,9 +19,12 @@ import {
19
19
  } from "./state.ts";
20
20
 
21
21
  import { Effect, Layer } from "effect";
22
- import { NodeServices } from "@effect/platform-node";
22
+ import * as NodePath from "@effect/platform-node/NodePath";
23
+ import * as NodeFileSystem from "@effect/platform-node/NodeFileSystem";
24
+ import * as NodeChildProcessSpawner from "@effect/platform-node/NodeChildProcessSpawner";
25
+
23
26
  import { VimRouter } from "./vim/vim-router.ts";
24
- import { EditorTintService, EditorTintServiceDefault } from "./ui/editor-tint.ts";
27
+ import { EditorTintService } from "./ui/editor-tint.ts";
25
28
 
26
29
  function isInteractiveLaunch(): boolean {
27
30
  if (!process.stdout.isTTY) return false;
@@ -344,16 +347,25 @@ const main = Effect.fn("tui/main")(function* (pi: ExtensionAPI) {
344
347
  });
345
348
 
346
349
  export default function (pi: ExtensionAPI) {
347
- const program = main(pi).pipe(
348
- Effect.provide(
349
- Layer.mergeAll(
350
- TuiConfigService.layer,
351
- GitStatusService.layer,
352
- PreviewService.make(homedir),
353
- EditorTintServiceDefault,
354
- ).pipe(Layer.provideMerge(GitExecutionService.layer), Layer.provideMerge(NodeServices.layer)),
355
- ),
350
+ const nodeLayer = NodeChildProcessSpawner.layer.pipe(
351
+ Layer.provide(Layer.mergeAll(NodePath.layer, NodeFileSystem.layer)),
352
+ );
353
+ const gitExecLayer = GitExecutionService.layer.pipe(Layer.provide(nodeLayer));
354
+ const gitLayer = Layer.provide(GitStatusService.layer, gitExecLayer);
355
+ const previewLayer = PreviewService.make(homedir).pipe(
356
+ Layer.provide(Layer.merge(NodePath.layer, NodeFileSystem.layer)),
356
357
  );
358
+ const tuiLayer = TuiConfigService.layer.pipe(Layer.provide(NodeFileSystem.layer));
359
+
360
+ const allLayers = Layer.mergeAll(
361
+ tuiLayer,
362
+ EditorTintService.layer,
363
+ previewLayer,
364
+ gitExecLayer,
365
+ gitLayer,
366
+ );
367
+
368
+ const program = main(pi).pipe(Effect.provide(allLayers));
357
369
 
358
370
  Effect.runSync(program);
359
371
  }
@@ -3,20 +3,12 @@ import { Effect } from "effect";
3
3
  import type { ThemeColor } from "@earendil-works/pi-coding-agent";
4
4
  import {
5
5
  EditorTintService,
6
- EditorTintServiceDefault,
7
6
  type EditorTintServiceHandle,
8
- resetEditorTintProviders,
9
7
  upsertBorderTintProvider,
10
8
  } from "./editor-tint.ts";
11
9
 
12
10
  const resolveTint = (): EditorTintServiceHandle =>
13
- Effect.runSync(
14
- Effect.service(EditorTintService).pipe(Effect.provide(EditorTintServiceDefault)),
15
- );
16
-
17
- afterEach(() => {
18
- resetEditorTintProviders();
19
- });
11
+ Effect.runSync(Effect.service(EditorTintService).pipe(Effect.provide(EditorTintService.layer)));
20
12
 
21
13
  // ---------------------------------------------------------------------------
22
14
  // EditorTintService (configure / getTint)
@@ -28,9 +20,7 @@ it("returns undefined with no providers registered", () => {
28
20
 
29
21
  it("returns the registered provider's tint", () => {
30
22
  const tint = resolveTint();
31
- tint.configure((cur) =>
32
- upsertBorderTintProvider(cur, { id: "a", getTint: () => "success" }),
33
- );
23
+ tint.configure((cur) => upsertBorderTintProvider(cur, { id: "a", getTint: () => "success" }));
34
24
  assert.strictEqual(tint.getTint(), "success");
35
25
  });
36
26
 
@@ -44,9 +34,7 @@ it("the last provider with a defined tint wins (later .configure overrides)", ()
44
34
  it("providers whose tint is undefined fall through to earlier ones", () => {
45
35
  const tint = resolveTint();
46
36
  tint.configure((cur) => upsertBorderTintProvider(cur, { id: "base", getTint: () => "success" }));
47
- tint.configure((cur) =>
48
- upsertBorderTintProvider(cur, { id: "pass", getTint: () => undefined }),
49
- );
37
+ tint.configure((cur) => upsertBorderTintProvider(cur, { id: "pass", getTint: () => undefined }));
50
38
  // "pass" is last but undefined → falls through to "base"
51
39
  assert.strictEqual(tint.getTint(), "success");
52
40
  });
@@ -35,37 +35,29 @@ export class EditorTintService extends Context.Service<
35
35
  ) => void;
36
36
  readonly getTint: () => ThemeColor | undefined;
37
37
  }
38
- >()("tui/editor/EditorTintService") {}
38
+ >()("tui/editor/EditorTintService") {
39
+ static readonly layer = Layer.sync(EditorTintService, () => {
40
+ let providers: readonly BorderTintProvider[] = [];
41
+
42
+ const implementation = EditorTintService.of({
43
+ configure(update) {
44
+ providers = update(providers);
45
+ },
46
+ getTint() {
47
+ for (let i = providers.length - 1; i >= 0; i--) {
48
+ const tint = providers[i]?.getTint();
49
+ if (tint !== undefined) return tint;
50
+ }
51
+ return undefined;
52
+ },
53
+ });
54
+ return implementation;
55
+ });
56
+ }
39
57
 
40
58
  /** Resolved instance shape (what `Effect.service(EditorTintService)` returns). */
41
59
  export type EditorTintServiceHandle = EditorTintService["Service"];
42
60
 
43
- // Module-level registry shared by every provider of the default layer.
44
- let providers: readonly BorderTintProvider[] = [];
45
-
46
- const implementation = EditorTintService.of({
47
- configure(update) {
48
- providers = update(providers);
49
- },
50
- getTint() {
51
- for (let i = providers.length - 1; i >= 0; i--) {
52
- const tint = providers[i]?.getTint();
53
- if (tint !== undefined) return tint;
54
- }
55
- return undefined;
56
- },
57
- });
58
-
59
- /** Default layer exposing the shared registry; extensions may override it. */
60
- export const EditorTintServiceDefault = Layer.succeed(EditorTintService, implementation);
61
-
62
- /**
63
- * Reset the shared registry (test support).
64
- */
65
- export function resetEditorTintProviders(): void {
66
- providers = [];
67
- }
68
-
69
61
  /**
70
62
  * Upsert a provider by `id`: drop any existing provider with the same id,
71
63
  * then append `provider` so it takes precedence from now on.
@@ -17,9 +17,7 @@ import { TuiEditor, type TuiEditorOptions } from "../ui/editor.ts";
17
17
  import { vimModeGlyph, vimModeTint } from "./mode-indicator.ts";
18
18
  import {
19
19
  EditorTintService,
20
- EditorTintServiceDefault,
21
20
  type EditorTintServiceHandle,
22
- resetEditorTintProviders,
23
21
  upsertBorderTintProvider,
24
22
  } from "../ui/editor-tint.ts";
25
23
  import { closeAutocomplete } from "./editor-close-autocomplete.ts";
@@ -234,25 +232,27 @@ it("tracks a changing tint source across renders", () => {
234
232
  // ---------------------------------------------------------------------------
235
233
 
236
234
  const resolveTint = (): EditorTintServiceHandle =>
237
- Effect.runSync(
238
- Effect.service(EditorTintService).pipe(Effect.provide(EditorTintServiceDefault)),
239
- );
235
+ Effect.runSync(Effect.service(EditorTintService).pipe(Effect.provide(EditorTintService.layer)));
240
236
 
241
237
  /**
242
- * Mirror installEditor's wiring on a bare TuiEditor: ask the shared service
243
- * for the tint and register vim's provider reading the live modal state.
238
+ * Mirror installEditor's wiring on a bare TuiEditor. installEditor receives a
239
+ * single resolved service handle and uses it for both the editor's border
240
+ * getter and vim's provider registration; a per-test handle is passed in (or
241
+ * freshly resolved) so both closures see the same provider registry.
244
242
  */
245
- const makeVimTintEditor = (getVimEnabled: () => boolean): TuiEditor => {
246
- resetEditorTintProviders();
243
+ const makeVimTintEditor = (
244
+ getVimEnabled: () => boolean,
245
+ tint: EditorTintServiceHandle = resolveTint(),
246
+ ): TuiEditor => {
247
247
  const tui = { terminal: { rows: 24, write() {} }, requestRender() {} } as unknown as TUI;
248
248
  const kb = new TuiKeybindingsManager(TUI_KEYBINDINGS, {}) as unknown as KeybindingsManager;
249
249
  setKeybindings(kb);
250
250
  const editor = new TuiEditor(tui, fakeEditorTheme, kb, {
251
251
  getVimEnabled,
252
252
  tintPaint: (color, s) => `${color}:${s}`,
253
- getBorderTint: () => resolveTint().getTint(),
253
+ getBorderTint: () => tint.getTint(),
254
254
  });
255
- resolveTint().configure((current) =>
255
+ tint.configure((current) =>
256
256
  upsertBorderTintProvider(current, { id: "vim", getTint: () => vimModeTint(editor.vimState) }),
257
257
  );
258
258
  return editor;
@@ -279,11 +279,12 @@ it("vim stays untinted when the toggle is off", () => {
279
279
  });
280
280
 
281
281
  it("another extension can override vim's tint through configure", () => {
282
- const editor = makeVimTintEditor(() => true);
282
+ const tint = resolveTint();
283
+ const editor = makeVimTintEditor(() => true, tint);
283
284
  editor.handleInput("\x1b"); // normal → vim tints syntaxOperator
284
285
  assert.ok(topBorderOf(editor).includes("syntaxOperator:"));
285
286
  // A later .configure from a different extension takes precedence.
286
- resolveTint().configure((cur) =>
287
+ tint.configure((cur) =>
287
288
  upsertBorderTintProvider(cur, { id: "my-extension", getTint: () => "error" }),
288
289
  );
289
290
  assert.ok(topBorderOf(editor).includes("error:"));