@narumitw/pi-btw 0.54.2 → 0.55.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@narumitw/pi-btw",
3
- "version": "0.54.2",
3
+ "version": "0.55.0",
4
4
  "description": "Pi extension that adds a /btw side-question command.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -34,11 +34,11 @@
34
34
  "prepack": "npm run build"
35
35
  },
36
36
  "devDependencies": {
37
- "@biomejs/biome": "2.5.8",
37
+ "@biomejs/biome": "2.5.9",
38
38
  "@earendil-works/pi-ai": "0.84.2",
39
39
  "@earendil-works/pi-coding-agent": "0.84.2",
40
40
  "@earendil-works/pi-tui": "0.84.2",
41
- "esbuild": "0.28.1",
41
+ "esbuild": "0.28.2",
42
42
  "typescript": "7.0.2"
43
43
  },
44
44
  "repository": {
@@ -1,8 +1,9 @@
1
1
  import { spawn } from "node:child_process";
2
- import type {
3
- ExtensionCommandContext,
4
- KeybindingsManager,
5
- Theme,
2
+ import {
3
+ copyToClipboard as copyToHostClipboard,
4
+ type ExtensionCommandContext,
5
+ type KeybindingsManager,
6
+ type Theme,
6
7
  } from "@earendil-works/pi-coding-agent";
7
8
  import {
8
9
  type Component,
@@ -30,11 +31,12 @@ export interface BtwFullscreenLayoutComponent extends Component {
30
31
  getFullscreenLayout(): Component;
31
32
  }
32
33
 
33
- export type BtwFullscreenTuiFactory = (parent: TUI) => BtwFullscreenTui;
34
+ export type BtwFullscreenTuiFactory = (parent: TUI, theme: Theme) => BtwFullscreenTui;
34
35
 
35
36
  export interface BtwFullscreenDependencies {
36
37
  createTui?: BtwFullscreenTuiFactory;
37
38
  openUrl?: (url: string) => void;
39
+ copyToClipboard?: (text: string) => Promise<void>;
38
40
  }
39
41
 
40
42
  export type RunBtwFullscreen = <T>(
@@ -58,7 +60,13 @@ export async function runBtwFullscreen<T>(
58
60
  ): Promise<T> {
59
61
  const createTui =
60
62
  dependencies.createTui ??
61
- ((parent: TUI) => createBtwFullscreenTui(parent, dependencies.openUrl ?? openUrlInBrowser));
63
+ ((parent: TUI, theme: Theme) =>
64
+ createBtwFullscreenTui(
65
+ parent,
66
+ theme,
67
+ dependencies.openUrl ?? openUrlInBrowser,
68
+ dependencies.copyToClipboard ?? copyToHostClipboard,
69
+ ));
62
70
  let liveEditorText = ctx.ui.getEditorText();
63
71
  let restoreEditor = false;
64
72
  const outcome = await ctx.ui.custom<FullscreenOutcome<T>>(
@@ -92,10 +100,27 @@ export async function runBtwFullscreen<T>(
92
100
  return outcome.value;
93
101
  }
94
102
 
95
- function createBtwFullscreenTui(parent: TUI, openUrl: (url: string) => void): BtwFullscreenTui {
103
+ function createBtwFullscreenTui(
104
+ parent: TUI,
105
+ theme: Theme,
106
+ openUrl: (url: string) => void,
107
+ copyToClipboard: (text: string) => Promise<void>,
108
+ ): BtwFullscreenTui {
109
+ const styleSearchMatch = (text: string) =>
110
+ theme.bg("searchMatchBg", theme.fg("searchMatchText", text));
96
111
  return new TuiAltScreen(parent.terminal, parent.getShowHardwareCursor(), undefined, {
97
112
  mouse: true,
113
+ searchMatchStyle: (text) => theme.underline(styleSearchMatch(text)),
114
+ searchCurrentMatchStyle: (text) => theme.bold(theme.inverse(styleSearchMatch(text))),
98
115
  openUrl,
116
+ copySelection: async (text) => {
117
+ try {
118
+ await copyToClipboard(text);
119
+ return true;
120
+ } catch {
121
+ return false;
122
+ }
123
+ },
99
124
  });
100
125
  }
101
126
 
@@ -154,7 +179,7 @@ class BtwFullscreenHost<T> implements Component {
154
179
  this.parent.stop({ preserveScreen: true });
155
180
  parentStopped = true;
156
181
  if (this.disposed) throw new FullscreenUiDisposedError();
157
- this.fullscreen = this.createTui(this.parent);
182
+ this.fullscreen = this.createTui(this.parent, this.theme);
158
183
  fullscreenCreated = true;
159
184
  this.fullscreen.start();
160
185
  outcome = { kind: "completed", value: await this.run(this.createContext()) };