@oh-my-pi/pi-natives 9.6.1 → 9.6.3

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.
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.1",
3
+ "version": "9.6.3",
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.1"
33
+ "@oh-my-pi/pi-utils": "9.6.3"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/node": "^25.0.10"
package/src/index.ts CHANGED
@@ -70,11 +70,13 @@ export {
70
70
  // =============================================================================
71
71
 
72
72
  export {
73
+ Ellipsis,
73
74
  type ExtractSegmentsResult,
74
75
  extractSegments,
75
76
  type SliceWithWidthResult,
76
77
  sliceWithWidth,
77
78
  truncateToWidth,
79
+ visibleWidth,
78
80
  } from "./text/index";
79
81
 
80
82
  // =============================================================================
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, TextInput } from "./text/index";
14
+ import type { ExtractSegmentsResult, SliceWithWidthResult } from "./text/index";
15
15
 
16
16
  export interface NativePhotonImage {
17
17
  getWidth(): number;
@@ -55,10 +55,11 @@ export interface NativeBindings {
55
55
  getSupportedLanguages(): string[];
56
56
  SamplingFilter: NativeSamplingFilter;
57
57
  PhotonImage: NativePhotonImageConstructor;
58
- truncateToWidth(text: TextInput, maxWidth: number, ellipsis: TextInput, pad: boolean): string;
59
- sliceWithWidth(line: TextInput, startCol: number, length: number, strict: boolean): SliceWithWidthResult;
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: TextInput,
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 type TextInput = string | Uint8Array;
19
+ export const enum Ellipsis {
20
+ Unicode = 0, // "…"
21
+ Ascii = 1, // "..."
22
+ Omit = 2, // ""
23
+ }
20
24
 
21
25
  /**
22
- * Truncate a string to a visible width, preserving ANSI codes.
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(text: TextInput, maxWidth: number, ellipsis: TextInput = "…", pad = false): string {
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
- line: TextInput,
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: TextInput,
64
+ line: string,
45
65
  beforeEnd: number,
46
66
  afterStart: number,
47
67
  afterLen: number,