@oh-my-pi/pi-natives 11.2.3 → 11.4.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/native/pi_natives.darwin-arm64.node +0 -0
- package/native/pi_natives.darwin-x64.node +0 -0
- package/native/pi_natives.linux-arm64.node +0 -0
- package/native/pi_natives.linux-x64.node +0 -0
- package/native/pi_natives.win32-x64.node +0 -0
- package/package.json +2 -2
- package/src/clipboard/index.ts +84 -1
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oh-my-pi/pi-natives",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.4.0",
|
|
4
4
|
"description": "Native Rust functionality via N-API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"directory": "packages/natives"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@oh-my-pi/pi-utils": "11.
|
|
35
|
+
"@oh-my-pi/pi-utils": "11.4.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/bun": "^1.3.8"
|
package/src/clipboard/index.ts
CHANGED
|
@@ -1,9 +1,92 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Clipboard helpers backed by native arboard bindings.
|
|
3
|
+
*
|
|
4
|
+
* Adds OSC 52 fallback for SSH/mosh, Termux support, and headless guards
|
|
5
|
+
* on top of the native arboard layer.
|
|
3
6
|
*/
|
|
4
7
|
|
|
8
|
+
import { execSync } from "node:child_process";
|
|
9
|
+
|
|
5
10
|
import { native } from "../native";
|
|
6
11
|
|
|
12
|
+
import type { ClipboardImage } from "./types";
|
|
13
|
+
|
|
7
14
|
export type { ClipboardImage } from "./types";
|
|
8
15
|
|
|
9
|
-
|
|
16
|
+
/** Whether a display server is available on Linux. */
|
|
17
|
+
const hasDisplay = process.platform !== "linux" || Boolean(process.env.DISPLAY || process.env.WAYLAND_DISPLAY);
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Copy text to the system clipboard.
|
|
21
|
+
*
|
|
22
|
+
* Emits OSC 52 first when running in a real terminal (works over SSH/mosh),
|
|
23
|
+
* then attempts native clipboard copy as best-effort for local sessions.
|
|
24
|
+
* On Termux, tries `termux-clipboard-set` before native.
|
|
25
|
+
*
|
|
26
|
+
* @param text - UTF-8 text to place on the clipboard.
|
|
27
|
+
*/
|
|
28
|
+
export async function copyToClipboard(text: string): Promise<void> {
|
|
29
|
+
if (process.stdout.isTTY) {
|
|
30
|
+
const encoded = Buffer.from(text).toString("base64");
|
|
31
|
+
const osc52 = `\x1b]52;c;${encoded}\x07`;
|
|
32
|
+
const onError = (err: unknown) => {
|
|
33
|
+
process.stdout.off("error", onError);
|
|
34
|
+
// Prevent unhandled 'error' from crashing the process when stdout is a closed pipe.
|
|
35
|
+
if ((err as NodeJS.ErrnoException | null | undefined)?.code === "EPIPE") {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
try {
|
|
40
|
+
process.stdout.on("error", onError);
|
|
41
|
+
process.stdout.write(osc52, err => {
|
|
42
|
+
process.stdout.off("error", onError);
|
|
43
|
+
// If stdout is closed (e.g. piped to a process that exits early),
|
|
44
|
+
// ignore EPIPE and proceed with native clipboard best-effort.
|
|
45
|
+
if ((err as NodeJS.ErrnoException | null | undefined)?.code === "EPIPE") {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
} catch (err) {
|
|
50
|
+
process.stdout.off("error", onError);
|
|
51
|
+
if ((err as NodeJS.ErrnoException | null | undefined)?.code !== "EPIPE") {
|
|
52
|
+
// Ignore all write failures (OSC 52 is best-effort).
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Also try native tools (best effort for local sessions)
|
|
58
|
+
try {
|
|
59
|
+
if (process.env.TERMUX_VERSION) {
|
|
60
|
+
try {
|
|
61
|
+
execSync("termux-clipboard-set", { input: text, timeout: 5000 });
|
|
62
|
+
return;
|
|
63
|
+
} catch {
|
|
64
|
+
// Fall through to native
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
await native.copyToClipboard(text);
|
|
69
|
+
} catch {
|
|
70
|
+
// Ignore — clipboard copy is best-effort
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Read an image from the system clipboard.
|
|
76
|
+
*
|
|
77
|
+
* Returns null on Termux (no image clipboard support) or when no display
|
|
78
|
+
* server is available (headless/SSH without forwarding).
|
|
79
|
+
*
|
|
80
|
+
* @returns PNG payload or null when no image is available.
|
|
81
|
+
*/
|
|
82
|
+
export async function readImageFromClipboard(): Promise<ClipboardImage | null> {
|
|
83
|
+
if (process.env.TERMUX_VERSION) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (!hasDisplay) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return native.readImageFromClipboard();
|
|
92
|
+
}
|