Files
oh-my-pi/packages/natives
can1357 8ef11355e7 perf(tui,natives): added native text utilities with JS fast path for short strings
- Added native text utilities in pi-natives (visible width, truncation, slicing, segment extraction)
- Wired pi-tui to use native implementations with short-string JS fast path
- Optimized key matching via cached parsed key ids
- Refactored visual truncation to reuse Text instances
- Reduced theme color lookups by switching from Map to plain records
- Regenerated WASM artifacts

Benchmarks (after vs before, lower is better):
- truncateToWidth/ansi: 20.37ms vs 38.13ms (2000 iters)
- sliceWithWidth/ansi: 5.12ms vs 20.39ms
- extractSegments/ansi: 8.92ms vs 27.60ms
- truncateToVisualLines: 3.51ms vs 411.55ms (500 iters)
- visibleWidth/ansi: 0.24ms vs 0.31ms
2026-01-29 10:47:55 +01:00
..
2026-01-29 09:49:52 +01:00

@oh-my-pi/pi-natives

Native Rust functionality compiled to WebAssembly via wasm-bindgen.

What's Inside

  • Grep: Regex-based search powered by ripgrep's engine (WASM handles matching, JS handles I/O + gitignore-aware file walking)
  • Find: Glob-based file/directory discovery with gitignore support (pure TypeScript via globPaths)
  • Image: Image processing via photon-rs (resize, format conversion)

Usage

import { grep, find, PhotonImage, resize, SamplingFilter } from "@oh-my-pi/pi-natives";

// Grep for a pattern
const results = await grep({
	pattern: "TODO",
	path: "/path/to/project",
	glob: "*.ts",
	context: 2,
});

// Find files
const files = await find({
	pattern: "*.rs",
	path: "/path/to/project",
	fileType: "file",
});

// Image processing
using image = await PhotonImage.new_from_byteslice(bytes);
using resized = await resize(image, 800, 600, SamplingFilter.Lanczos3);
const pngBytes = await resized.get_bytes();

Building

# Build WASM from workspace root (requires Rust + wasm-pack)
bun run build:wasm

# Type check
bun run check

Architecture

crates/pi-natives/       # Rust source (workspace member)
  src/lib.rs             # Grep/search + wasm-bindgen bindings
  src/image.rs           # Image processing (photon-rs)
  Cargo.toml             # Rust dependencies
wasm/                    # Generated WASM output
  pi_natives.wasm        # Compiled WASM module
  pi_natives.js          # wasm-bindgen generated JS glue
  pi_natives.d.ts        # TypeScript definitions
src/                     # TypeScript wrappers
  index.ts               # Public API
  grep/                  # Grep with worker pool
  image/                 # Async image processing via worker
  pool.ts                # Generic worker pool infrastructure