@oh-my-pi/pi-natives 13.1.1 → 13.2.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.
Binary file
Binary file
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@oh-my-pi/pi-natives",
4
- "version": "13.1.1",
4
+ "version": "13.2.0",
5
5
  "description": "Native Rust bindings for grep, clipboard, image processing, syntax highlighting, PTY, and shell operations via N-API",
6
6
  "homepage": "https://github.com/can1357/oh-my-pi",
7
7
  "author": "Can Boluk",
@@ -38,7 +38,7 @@
38
38
  "bench": "bun bench/grep.ts"
39
39
  },
40
40
  "dependencies": {
41
- "@oh-my-pi/pi-utils": "13.1.1"
41
+ "@oh-my-pi/pi-utils": "13.2.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/bun": "^1.3"
package/src/text/index.ts CHANGED
@@ -2,7 +2,8 @@
2
2
  * ANSI-aware text utilities powered by native bindings.
3
3
  */
4
4
 
5
- import { Ellipsis, type SliceWithWidthResult } from "@oh-my-pi/pi-natives";
5
+ import { Ellipsis, type ExtractSegmentsResult, type SliceWithWidthResult } from "@oh-my-pi/pi-natives";
6
+ import { getDefaultTabWidth } from "@oh-my-pi/pi-utils";
6
7
  import { native } from "../native";
7
8
 
8
9
  export type { ExtractSegmentsResult, SliceWithWidthResult } from "./types";
@@ -24,8 +25,9 @@ export function truncateToWidth(
24
25
  maxWidth: number,
25
26
  ellipsis: Ellipsis = Ellipsis.Unicode,
26
27
  pad = false,
28
+ tabWidth = getDefaultTabWidth(),
27
29
  ): string {
28
- return native.truncateToWidth(text, maxWidth, ellipsis, pad);
30
+ return native.truncateToWidth(text, maxWidth, ellipsis, pad, tabWidth);
29
31
  }
30
32
 
31
33
  /**
@@ -36,9 +38,60 @@ export function truncateToWidth(
36
38
  * @param strict - Whether to strictly enforce the length
37
39
  * @returns The sliced line
38
40
  */
39
- export function sliceWithWidth(line: string, startCol: number, length: number, strict = false): SliceWithWidthResult {
41
+ export function sliceWithWidth(
42
+ line: string,
43
+ startCol: number,
44
+ length: number,
45
+ strict = false,
46
+ tabWidth = getDefaultTabWidth(),
47
+ ): SliceWithWidthResult {
40
48
  if (length <= 0) return { text: "", width: 0 };
41
- return native.sliceWithWidth(line, startCol, length, strict);
49
+ return native.sliceWithWidth(line, startCol, length, strict, tabWidth);
42
50
  }
43
51
 
44
- export const { wrapTextWithAnsi, visibleWidth, extractSegments, sanitizeText } = native;
52
+ /**
53
+ * Wrap text to a visible width while preserving ANSI color/style sequences.
54
+ *
55
+ * @param text - Input text, optionally containing ANSI escape codes
56
+ * @param width - Maximum visible width per output line
57
+ * @param tabWidth - Width used when measuring tab characters (default: configured tab width)
58
+ * @returns Wrapped lines with ANSI state preserved across breaks
59
+ */
60
+ export function wrapTextWithAnsi(text: string, width: number, tabWidth = getDefaultTabWidth()): string[] {
61
+ return native.wrapTextWithAnsi(text, width, tabWidth);
62
+ }
63
+
64
+ /**
65
+ * Measure visible terminal width of text, excluding ANSI escape sequences.
66
+ *
67
+ * @param text - Input text, optionally containing ANSI escape codes
68
+ * @param tabWidth - Width used when measuring tab characters (default: configured tab width)
69
+ * @returns Visible width in terminal cells
70
+ */
71
+ export function visibleWidth(text: string, tabWidth = getDefaultTabWidth()): number {
72
+ return native.visibleWidth(text, tabWidth);
73
+ }
74
+
75
+ /**
76
+ * Extract before/after segments around an overlay range using visible-column boundaries.
77
+ *
78
+ * @param line - Input line, optionally containing ANSI escape codes
79
+ * @param beforeEnd - Visible column where the `before` segment ends
80
+ * @param afterStart - Visible column where the `after` segment starts
81
+ * @param afterLen - Visible width to include in the `after` segment
82
+ * @param strictAfter - When true, graphemes that overflow `afterLen` are dropped
83
+ * @param tabWidth - Width used when measuring tab characters (default: configured tab width)
84
+ * @returns Visible-width-aware before/after segments
85
+ */
86
+ export function extractSegments(
87
+ line: string,
88
+ beforeEnd: number,
89
+ afterStart: number,
90
+ afterLen: number,
91
+ strictAfter: boolean,
92
+ tabWidth = getDefaultTabWidth(),
93
+ ): ExtractSegmentsResult {
94
+ return native.extractSegments(line, beforeEnd, afterStart, afterLen, strictAfter, tabWidth);
95
+ }
96
+
97
+ export const { sanitizeText } = native;
package/src/text/types.ts CHANGED
@@ -41,7 +41,7 @@ declare module "../bindings" {
41
41
  * @param ellipsisKind Ellipsis strategy (see {@link Ellipsis}).
42
42
  * @param pad Whether to pad the output to `maxWidth`.
43
43
  */
44
- truncateToWidth(text: string, maxWidth: number, ellipsisKind: number, pad: boolean): string;
44
+ truncateToWidth(text: string, maxWidth: number, ellipsisKind: number, pad: boolean, tabWidth?: number): string;
45
45
  /**
46
46
  * Sanitize text output: strip ANSI codes, remove binary garbage, normalize line endings.
47
47
  */
@@ -52,7 +52,7 @@ declare module "../bindings" {
52
52
  * @param text UTF-16 input text with optional ANSI escapes.
53
53
  * @param width Maximum visible width per line.
54
54
  */
55
- wrapTextWithAnsi(text: string, width: number): string[];
55
+ wrapTextWithAnsi(text: string, width: number, tabWidth?: number): string[];
56
56
  /**
57
57
  * Slice a range of visible columns from a line.
58
58
  * @param line UTF-16 input line with optional ANSI escapes.
@@ -60,12 +60,18 @@ declare module "../bindings" {
60
60
  * @param length Number of visible cells to include.
61
61
  * @param strict Whether to drop graphemes that overflow the range.
62
62
  */
63
- sliceWithWidth(line: string, startCol: number, length: number, strict: boolean): SliceWithWidthResult;
63
+ sliceWithWidth(
64
+ line: string,
65
+ startCol: number,
66
+ length: number,
67
+ strict: boolean,
68
+ tabWidth?: number,
69
+ ): SliceWithWidthResult;
64
70
  /**
65
71
  * Measure the visible width of text (excluding ANSI codes).
66
72
  * @param text UTF-16 input text with optional ANSI escapes.
67
73
  */
68
- visibleWidth(text: string): number;
74
+ visibleWidth(text: string, tabWidth?: number): number;
69
75
  /** Extract before/after segments around an overlay region.
70
76
  * @param line UTF-16 input line with optional ANSI escapes.
71
77
  * @param beforeEnd Column where the "before" segment ends.
@@ -79,6 +85,7 @@ declare module "../bindings" {
79
85
  afterStart: number,
80
86
  afterLen: number,
81
87
  strictAfter: boolean,
88
+ tabWidth?: number,
82
89
  ): ExtractSegmentsResult;
83
90
  }
84
91
  }