@oh-my-pi/pi-natives 9.6.1 → 9.6.4
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/grep/index.ts +3 -1
- package/src/index.ts +6 -1
- package/src/native.ts +9 -18
- package/src/text/index.ts +30 -10
|
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": "9.6.
|
|
3
|
+
"version": "9.6.4",
|
|
4
4
|
"description": "Native Rust functionality via N-API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"directory": "packages/natives"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@oh-my-pi/pi-utils": "9.6.
|
|
33
|
+
"@oh-my-pi/pi-utils": "9.6.4"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/node": "^25.0.10"
|
package/src/grep/index.ts
CHANGED
|
@@ -34,7 +34,9 @@ export type {
|
|
|
34
34
|
* Search files for a regex pattern with optional streaming callback.
|
|
35
35
|
*/
|
|
36
36
|
export async function grep(options: GrepOptions, onMatch?: (match: GrepMatch) => void): Promise<GrepResult> {
|
|
37
|
-
|
|
37
|
+
// napi-rs ThreadsafeFunction passes (error, value) - skip callback on error
|
|
38
|
+
const cb = onMatch ? (err: Error | null, m: GrepMatch) => !err && onMatch(m) : undefined;
|
|
39
|
+
return wrapRequestOptions(() => native.grep(options, cb), options);
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
/**
|
package/src/index.ts
CHANGED
|
@@ -42,6 +42,9 @@ export async function find(options: FindOptions, onMatch?: (match: FindMatch) =>
|
|
|
42
42
|
// Convert simple patterns to recursive globs if needed
|
|
43
43
|
const globPattern = pattern.includes("/") || pattern.startsWith("**") ? pattern : `**/${pattern}`;
|
|
44
44
|
|
|
45
|
+
// napi-rs ThreadsafeFunction passes (error, value) - skip callback on error
|
|
46
|
+
const cb = onMatch ? (err: Error | null, m: FindMatch) => !err && onMatch(m) : undefined;
|
|
47
|
+
|
|
45
48
|
return native.find(
|
|
46
49
|
{
|
|
47
50
|
...options,
|
|
@@ -50,7 +53,7 @@ export async function find(options: FindOptions, onMatch?: (match: FindMatch) =>
|
|
|
50
53
|
hidden: options.hidden ?? false,
|
|
51
54
|
gitignore: options.gitignore ?? true,
|
|
52
55
|
},
|
|
53
|
-
|
|
56
|
+
cb,
|
|
54
57
|
);
|
|
55
58
|
}
|
|
56
59
|
|
|
@@ -70,11 +73,13 @@ export {
|
|
|
70
73
|
// =============================================================================
|
|
71
74
|
|
|
72
75
|
export {
|
|
76
|
+
Ellipsis,
|
|
73
77
|
type ExtractSegmentsResult,
|
|
74
78
|
extractSegments,
|
|
75
79
|
type SliceWithWidthResult,
|
|
76
80
|
sliceWithWidth,
|
|
77
81
|
truncateToWidth,
|
|
82
|
+
visibleWidth,
|
|
78
83
|
} from "./text/index";
|
|
79
84
|
|
|
80
85
|
// =============================================================================
|
package/src/native.ts
CHANGED
|
@@ -11,7 +11,7 @@ import type {
|
|
|
11
11
|
} from "./grep/types";
|
|
12
12
|
import type { HighlightColors } from "./highlight/index";
|
|
13
13
|
import type { HtmlToMarkdownOptions } from "./html/types";
|
|
14
|
-
import type { ExtractSegmentsResult, SliceWithWidthResult
|
|
14
|
+
import type { ExtractSegmentsResult, SliceWithWidthResult } from "./text/index";
|
|
15
15
|
|
|
16
16
|
export interface NativePhotonImage {
|
|
17
17
|
getWidth(): number;
|
|
@@ -39,9 +39,9 @@ export interface NativeSamplingFilter {
|
|
|
39
39
|
import type { GrepMatch } from "./grep/types";
|
|
40
40
|
|
|
41
41
|
export interface NativeBindings {
|
|
42
|
-
find(options: FindOptions, onMatch?: (match: FindMatch) => void): Promise<FindResult>;
|
|
42
|
+
find(options: FindOptions, onMatch?: (error: Error | null, match: FindMatch) => void): Promise<FindResult>;
|
|
43
43
|
fuzzyFind(options: FuzzyFindOptions): Promise<FuzzyFindResult>;
|
|
44
|
-
grep(options: GrepOptions, onMatch?: (match: GrepMatch) => void): Promise<GrepResult>;
|
|
44
|
+
grep(options: GrepOptions, onMatch?: (error: Error | null, match: GrepMatch) => void): Promise<GrepResult>;
|
|
45
45
|
search(content: string | Uint8Array, options: SearchOptions): SearchResult;
|
|
46
46
|
hasMatch(
|
|
47
47
|
content: string | Uint8Array,
|
|
@@ -55,10 +55,11 @@ export interface NativeBindings {
|
|
|
55
55
|
getSupportedLanguages(): string[];
|
|
56
56
|
SamplingFilter: NativeSamplingFilter;
|
|
57
57
|
PhotonImage: NativePhotonImageConstructor;
|
|
58
|
-
truncateToWidth(text:
|
|
59
|
-
sliceWithWidth(line:
|
|
58
|
+
truncateToWidth(text: string, maxWidth: number, ellipsisKind: number, pad: boolean): string;
|
|
59
|
+
sliceWithWidth(line: string, startCol: number, length: number, strict: boolean): SliceWithWidthResult;
|
|
60
|
+
visibleWidth(text: string): number;
|
|
60
61
|
extractSegments(
|
|
61
|
-
line:
|
|
62
|
+
line: string,
|
|
62
63
|
beforeEnd: number,
|
|
63
64
|
afterStart: number,
|
|
64
65
|
afterLen: number,
|
|
@@ -76,12 +77,12 @@ const execDir = path.dirname(process.execPath);
|
|
|
76
77
|
const SUPPORTED_PLATFORMS = ["linux-x64", "linux-arm64", "darwin-x64", "darwin-arm64", "win32-x64"];
|
|
77
78
|
|
|
78
79
|
const candidates = [
|
|
80
|
+
path.join(repoRoot, "target", "release", "pi_natives.node"),
|
|
81
|
+
path.join(repoRoot, "crates", "pi-natives", "target", "release", "pi_natives.node"),
|
|
79
82
|
path.join(nativeDir, `pi_natives.${platformTag}.node`),
|
|
80
83
|
path.join(nativeDir, "pi_natives.node"),
|
|
81
84
|
path.join(execDir, `pi_natives.${platformTag}.node`),
|
|
82
85
|
path.join(execDir, "pi_natives.node"),
|
|
83
|
-
path.join(repoRoot, "target", "release", "pi_natives.node"),
|
|
84
|
-
path.join(repoRoot, "crates", "pi-natives", "target", "release", "pi_natives.node"),
|
|
85
86
|
];
|
|
86
87
|
|
|
87
88
|
function loadNative(): NativeBindings {
|
|
@@ -138,16 +139,6 @@ function validateNative(bindings: NativeBindings, source: string): void {
|
|
|
138
139
|
checkFn("extractSegments");
|
|
139
140
|
checkFn("matchesKittySequence");
|
|
140
141
|
|
|
141
|
-
if (!bindings.PhotonImage?.newFromByteslice) {
|
|
142
|
-
missing.push("PhotonImage.newFromByteslice");
|
|
143
|
-
}
|
|
144
|
-
if (!bindings.PhotonImage?.prototype?.resize) {
|
|
145
|
-
missing.push("PhotonImage.resize");
|
|
146
|
-
}
|
|
147
|
-
if (!bindings.SamplingFilter || typeof bindings.SamplingFilter.Lanczos3 !== "number") {
|
|
148
|
-
missing.push("SamplingFilter");
|
|
149
|
-
}
|
|
150
|
-
|
|
151
142
|
if (missing.length) {
|
|
152
143
|
throw new Error(
|
|
153
144
|
`Native addon missing exports (${source}). Missing: ${missing.join(", ")}. ` +
|
package/src/text/index.ts
CHANGED
|
@@ -16,24 +16,44 @@ export interface ExtractSegmentsResult {
|
|
|
16
16
|
afterWidth: number;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
export
|
|
19
|
+
export const enum Ellipsis {
|
|
20
|
+
Unicode = 0, // "…"
|
|
21
|
+
Ascii = 1, // "..."
|
|
22
|
+
Omit = 2, // ""
|
|
23
|
+
}
|
|
20
24
|
|
|
21
25
|
/**
|
|
22
|
-
* Truncate
|
|
26
|
+
* Truncate text to fit within a maximum visible width, adding ellipsis if needed.
|
|
27
|
+
* Optionally pad with spaces to reach exactly maxWidth.
|
|
28
|
+
* Properly handles ANSI escape codes (they don't count toward width).
|
|
29
|
+
*
|
|
30
|
+
* @param text - Text to truncate (may contain ANSI codes)
|
|
31
|
+
* @param maxWidth - Maximum visible width
|
|
32
|
+
* @param ellipsis - Ellipsis kind to append when truncating (default: Unicode "…")
|
|
33
|
+
* @param pad - If true, pad result with spaces to exactly maxWidth (default: false)
|
|
34
|
+
* @returns Truncated text, optionally padded to exactly maxWidth
|
|
23
35
|
*/
|
|
24
|
-
export function truncateToWidth(
|
|
36
|
+
export function truncateToWidth(
|
|
37
|
+
text: string,
|
|
38
|
+
maxWidth: number,
|
|
39
|
+
ellipsis: Ellipsis = Ellipsis.Unicode,
|
|
40
|
+
pad = false,
|
|
41
|
+
): string {
|
|
25
42
|
return native.truncateToWidth(text, maxWidth, ellipsis, pad);
|
|
26
43
|
}
|
|
27
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Measure the visible width of text (excluding ANSI codes).
|
|
47
|
+
*/
|
|
48
|
+
export function visibleWidth(text: string): number {
|
|
49
|
+
return native.visibleWidth(text);
|
|
50
|
+
}
|
|
51
|
+
|
|
28
52
|
/**
|
|
29
53
|
* Slice a range of visible columns from a line.
|
|
30
54
|
*/
|
|
31
|
-
export function sliceWithWidth(
|
|
32
|
-
|
|
33
|
-
startCol: number,
|
|
34
|
-
length: number,
|
|
35
|
-
strict = false,
|
|
36
|
-
): SliceWithWidthResult {
|
|
55
|
+
export function sliceWithWidth(line: string, startCol: number, length: number, strict = false): SliceWithWidthResult {
|
|
56
|
+
if (length <= 0) return { text: "", width: 0 };
|
|
37
57
|
return native.sliceWithWidth(line, startCol, length, strict);
|
|
38
58
|
}
|
|
39
59
|
|
|
@@ -41,7 +61,7 @@ export function sliceWithWidth(
|
|
|
41
61
|
* Extract before/after segments around an overlay region.
|
|
42
62
|
*/
|
|
43
63
|
export function extractSegments(
|
|
44
|
-
line:
|
|
64
|
+
line: string,
|
|
45
65
|
beforeEnd: number,
|
|
46
66
|
afterStart: number,
|
|
47
67
|
afterLen: number,
|