[PR #746] [CLOSED] Add Rust native core implementation with C ABI FFI bindings #753

Closed
opened 2026-03-02 23:47:58 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/anomalyco/opentui/pull/746
Author: @bgub
Created: 2/27/2026
Status: Closed

Base: mainHead: claude/zig-to-rust-deno-XSmm4


📝 Commits (1)

  • c8a734c Rewrite native core from Zig to Rust with Deno FFI support

📊 Changes

24 files changed (+6405 additions, -0 deletions)

View changed files

📝 packages/core/package.json (+3 -0)
packages/core/src/rust/.gitignore (+2 -0)
packages/core/src/rust/Cargo.lock (+23 -0)
packages/core/src/rust/Cargo.toml (+20 -0)
packages/core/src/rust/build.sh (+120 -0)
packages/core/src/rust/deno_ffi.ts (+141 -0)
packages/core/src/rust/src/ansi.rs (+148 -0)
packages/core/src/rust/src/buffer.rs (+710 -0)
packages/core/src/rust/src/edit_buffer.rs (+501 -0)
packages/core/src/rust/src/editor_view.rs (+248 -0)
packages/core/src/rust/src/event_bus.rs (+21 -0)
packages/core/src/rust/src/ffi.rs (+1621 -0)
packages/core/src/rust/src/grapheme.rs (+220 -0)
packages/core/src/rust/src/lib.rs (+24 -0)
packages/core/src/rust/src/link.rs (+110 -0)
packages/core/src/rust/src/logger.rs (+37 -0)
packages/core/src/rust/src/renderer.rs (+532 -0)
packages/core/src/rust/src/rope.rs (+314 -0)
packages/core/src/rust/src/syntax_style.rs (+113 -0)
packages/core/src/rust/src/terminal.rs (+384 -0)

...and 4 more files

📄 Description

Summary

This PR introduces a complete Rust implementation of the OpenTUI native core, replacing the Zig backend while maintaining full C ABI compatibility with the existing TypeScript FFI bindings. The implementation provides a high-performance terminal UI library with double-buffered rendering, text editing, and advanced terminal capabilities.

Key Changes

  • Core FFI Module (ffi.rs): Comprehensive C ABI exports matching the original Zig lib.zig interface, enabling seamless integration with Deno via Deno.dlopen() without modifying existing TypeScript bindings

  • Renderer System (renderer.rs): Double-buffered terminal renderer with hit grid support for mouse event dispatch, render statistics tracking, and debug overlay capabilities

  • Text Editing (edit_buffer.rs, text_buffer.rs, rope.rs): Full-featured text editing with:

    • Persistent rope data structure for efficient string operations
    • Undo/redo history support
    • Memory registry for reusing large byte slices
    • Syntax highlighting infrastructure
  • Text Display (text_buffer_view.rs, editor_view.rs): Viewport-based text rendering with:

    • Multiple wrap modes (None, Char, Word)
    • Text selection support
    • Line caching for performance
    • Visual and logical cursor tracking
  • Buffer Management (buffer.rs): Structure-of-arrays optimized buffer layout for cache-friendly rendering with scissor rect and opacity stack support

  • Terminal Abstraction (terminal.rs): Terminal capability detection and control including:

    • Kitty keyboard/graphics protocol support
    • Sixel and SGR pixel graphics
    • OSC 52 clipboard operations
    • Mouse and focus tracking
    • Cursor styling and positioning
  • Supporting Infrastructure:

    • utf8.rs: UTF-8 handling with multiple width calculation methods
    • grapheme.rs: Grapheme cluster pooling for multi-byte characters
    • ansi.rs: ANSI escape sequence constants
    • link.rs: Hyperlink URL pooling
    • syntax_style.rs: Syntax highlighting style registry
    • logger.rs, event_bus.rs: Callback-based logging and event dispatch
    • utils.rs: Color blending and utility functions
  • Build System (Cargo.toml, build.sh):

    • Cargo configuration for building as a dynamic library (cdylib)
    • Cross-compilation support for Linux, macOS, and Windows targets
    • Bash build script matching original Zig build conventions
  • Deno Integration (deno_ffi.ts): TypeScript FFI bindings for loading and using the compiled native library with Deno

  • Package Configuration: Added build:rust npm script for building the Rust native core

Notable Implementation Details

  • All exported C functions use #[no_mangle] pub unsafe extern "C" to maintain symbol table compatibility with existing TypeScript bindings
  • Grapheme clusters and hyperlinks use pooling with reference counting for memory efficiency
  • Text storage uses a persistent rope structure enabling efficient undo/redo without copying
  • Terminal capabilities are detected and cached for optimal performance
  • The renderer maintains separate hit grids for mouse event dispatch with scissor rect support
  • Color blending uses perceptual alpha blending for visual accuracy

https://claude.ai/code/session_01YTxVJjcA1ZQzz7t26u62iJ


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/anomalyco/opentui/pull/746 **Author:** [@bgub](https://github.com/bgub) **Created:** 2/27/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `claude/zig-to-rust-deno-XSmm4` --- ### 📝 Commits (1) - [`c8a734c`](https://github.com/anomalyco/opentui/commit/c8a734cd3e26986db67d2144d04247a0a5cd1ab5) Rewrite native core from Zig to Rust with Deno FFI support ### 📊 Changes **24 files changed** (+6405 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `packages/core/package.json` (+3 -0) ➕ `packages/core/src/rust/.gitignore` (+2 -0) ➕ `packages/core/src/rust/Cargo.lock` (+23 -0) ➕ `packages/core/src/rust/Cargo.toml` (+20 -0) ➕ `packages/core/src/rust/build.sh` (+120 -0) ➕ `packages/core/src/rust/deno_ffi.ts` (+141 -0) ➕ `packages/core/src/rust/src/ansi.rs` (+148 -0) ➕ `packages/core/src/rust/src/buffer.rs` (+710 -0) ➕ `packages/core/src/rust/src/edit_buffer.rs` (+501 -0) ➕ `packages/core/src/rust/src/editor_view.rs` (+248 -0) ➕ `packages/core/src/rust/src/event_bus.rs` (+21 -0) ➕ `packages/core/src/rust/src/ffi.rs` (+1621 -0) ➕ `packages/core/src/rust/src/grapheme.rs` (+220 -0) ➕ `packages/core/src/rust/src/lib.rs` (+24 -0) ➕ `packages/core/src/rust/src/link.rs` (+110 -0) ➕ `packages/core/src/rust/src/logger.rs` (+37 -0) ➕ `packages/core/src/rust/src/renderer.rs` (+532 -0) ➕ `packages/core/src/rust/src/rope.rs` (+314 -0) ➕ `packages/core/src/rust/src/syntax_style.rs` (+113 -0) ➕ `packages/core/src/rust/src/terminal.rs` (+384 -0) _...and 4 more files_ </details> ### 📄 Description ## Summary This PR introduces a complete Rust implementation of the OpenTUI native core, replacing the Zig backend while maintaining full C ABI compatibility with the existing TypeScript FFI bindings. The implementation provides a high-performance terminal UI library with double-buffered rendering, text editing, and advanced terminal capabilities. ## Key Changes - **Core FFI Module** (`ffi.rs`): Comprehensive C ABI exports matching the original Zig `lib.zig` interface, enabling seamless integration with Deno via `Deno.dlopen()` without modifying existing TypeScript bindings - **Renderer System** (`renderer.rs`): Double-buffered terminal renderer with hit grid support for mouse event dispatch, render statistics tracking, and debug overlay capabilities - **Text Editing** (`edit_buffer.rs`, `text_buffer.rs`, `rope.rs`): Full-featured text editing with: - Persistent rope data structure for efficient string operations - Undo/redo history support - Memory registry for reusing large byte slices - Syntax highlighting infrastructure - **Text Display** (`text_buffer_view.rs`, `editor_view.rs`): Viewport-based text rendering with: - Multiple wrap modes (None, Char, Word) - Text selection support - Line caching for performance - Visual and logical cursor tracking - **Buffer Management** (`buffer.rs`): Structure-of-arrays optimized buffer layout for cache-friendly rendering with scissor rect and opacity stack support - **Terminal Abstraction** (`terminal.rs`): Terminal capability detection and control including: - Kitty keyboard/graphics protocol support - Sixel and SGR pixel graphics - OSC 52 clipboard operations - Mouse and focus tracking - Cursor styling and positioning - **Supporting Infrastructure**: - `utf8.rs`: UTF-8 handling with multiple width calculation methods - `grapheme.rs`: Grapheme cluster pooling for multi-byte characters - `ansi.rs`: ANSI escape sequence constants - `link.rs`: Hyperlink URL pooling - `syntax_style.rs`: Syntax highlighting style registry - `logger.rs`, `event_bus.rs`: Callback-based logging and event dispatch - `utils.rs`: Color blending and utility functions - **Build System** (`Cargo.toml`, `build.sh`): - Cargo configuration for building as a dynamic library (cdylib) - Cross-compilation support for Linux, macOS, and Windows targets - Bash build script matching original Zig build conventions - **Deno Integration** (`deno_ffi.ts`): TypeScript FFI bindings for loading and using the compiled native library with Deno - **Package Configuration**: Added `build:rust` npm script for building the Rust native core ## Notable Implementation Details - All exported C functions use `#[no_mangle] pub unsafe extern "C"` to maintain symbol table compatibility with existing TypeScript bindings - Grapheme clusters and hyperlinks use pooling with reference counting for memory efficiency - Text storage uses a persistent rope structure enabling efficient undo/redo without copying - Terminal capabilities are detected and cached for optimal performance - The renderer maintains separate hit grids for mouse event dispatch with scissor rect support - Color blending uses perceptual alpha blending for visual accuracy https://claude.ai/code/session_01YTxVJjcA1ZQzz7t26u62iJ --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-02 23:47:58 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/opentui#753
No description provided.