@oh-my-pi/pi-natives 9.6.0 → 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.0",
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.0"
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,6 +70,7 @@ export {
70
70
  // =============================================================================
71
71
 
72
72
  export {
73
+ Ellipsis,
73
74
  type ExtractSegmentsResult,
74
75
  extractSegments,
75
76
  type SliceWithWidthResult,
@@ -89,6 +90,12 @@ export {
89
90
  supportsLanguage,
90
91
  } from "./highlight/index";
91
92
 
93
+ // =============================================================================
94
+ // Keyboard sequence helpers
95
+ // =============================================================================
96
+
97
+ export { matchesKittySequence } from "./keys/index";
98
+
92
99
  // =============================================================================
93
100
  // HTML to Markdown
94
101
  // =============================================================================
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Keyboard sequence utilities powered by native bindings.
3
+ */
4
+
5
+ import { native } from "../native";
6
+
7
+ /** Match Kitty protocol sequences for codepoint and modifier. */
8
+ export function matchesKittySequence(data: string, expectedCodepoint: number, expectedModifier: number): boolean {
9
+ return native.matchesKittySequence(data, expectedCodepoint, expectedModifier);
10
+ }
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,16 +55,17 @@ export interface NativeBindings {
55
55
  getSupportedLanguages(): string[];
56
56
  SamplingFilter: NativeSamplingFilter;
57
57
  PhotonImage: NativePhotonImageConstructor;
58
- visibleWidth(text: TextInput): number;
59
- truncateToWidth(text: TextInput, maxWidth: number, ellipsis: TextInput, pad: boolean): string;
60
- 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;
61
61
  extractSegments(
62
- line: TextInput,
62
+ line: string,
63
63
  beforeEnd: number,
64
64
  afterStart: number,
65
65
  afterLen: number,
66
66
  strictAfter: boolean,
67
67
  ): ExtractSegmentsResult;
68
+ matchesKittySequence(data: string, expectedCodepoint: number, expectedModifier: number): boolean;
68
69
  }
69
70
 
70
71
  const require = createRequire(import.meta.url);
@@ -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 {
@@ -133,20 +134,10 @@ function validateNative(bindings: NativeBindings, source: string): void {
133
134
  checkFn("highlightCode");
134
135
  checkFn("supportsLanguage");
135
136
  checkFn("getSupportedLanguages");
136
- checkFn("visibleWidth");
137
137
  checkFn("truncateToWidth");
138
138
  checkFn("sliceWithWidth");
139
139
  checkFn("extractSegments");
140
-
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
- }
140
+ checkFn("matchesKittySequence");
150
141
 
151
142
  if (missing.length) {
152
143
  throw new Error(
package/src/text/index.ts CHANGED
@@ -16,29 +16,44 @@ export interface ExtractSegmentsResult {
16
16
  afterWidth: number;
17
17
  }
18
18
 
19
- export type TextInput = string | Uint8Array;
20
-
21
- /** Compute the visible width of a string, ignoring ANSI codes. */
22
- export function visibleWidth(text: TextInput): number {
23
- return native.visibleWidth(text);
19
+ export const enum Ellipsis {
20
+ Unicode = 0, // "…"
21
+ Ascii = 1, // "..."
22
+ Omit = 2, // ""
24
23
  }
25
24
 
26
25
  /**
27
- * 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
28
35
  */
29
- 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 {
30
42
  return native.truncateToWidth(text, maxWidth, ellipsis, pad);
31
43
  }
32
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
+
33
52
  /**
34
53
  * Slice a range of visible columns from a line.
35
54
  */
36
- export function sliceWithWidth(
37
- line: TextInput,
38
- startCol: number,
39
- length: number,
40
- strict = false,
41
- ): SliceWithWidthResult {
55
+ export function sliceWithWidth(line: string, startCol: number, length: number, strict = false): SliceWithWidthResult {
56
+ if (length <= 0) return { text: "", width: 0 };
42
57
  return native.sliceWithWidth(line, startCol, length, strict);
43
58
  }
44
59
 
@@ -46,7 +61,7 @@ export function sliceWithWidth(
46
61
  * Extract before/after segments around an overlay region.
47
62
  */
48
63
  export function extractSegments(
49
- line: TextInput,
64
+ line: string,
50
65
  beforeEnd: number,
51
66
  afterStart: number,
52
67
  afterLen: number,