| Crates.io | fusabi-tui-scarab |
| lib.rs | fusabi-tui-scarab |
| version | 0.2.0 |
| created_at | 2025-12-15 03:22:48.729368+00 |
| updated_at | 2025-12-29 16:53:52.764715+00 |
| description | Scarab shared memory backend for Fusabi TUI |
| homepage | |
| repository | https://github.com/fusabi-lang/fusabi-tui-runtime |
| max_upload_size | |
| id | 1985478 |
| size | 72,116 |
Scarab shared memory backend for Fusabi TUI framework.
This crate provides zero-copy integration between the Fusabi TUI framework and the Scarab terminal emulator's shared memory protocol.
Scarab uses a split-process architecture:
This crate enables TUI applications to render directly to Scarab's shared memory buffer.
use fusabi_tui_scarab::prelude::*;
// Connect to Scarab's shared memory
let mut renderer = ScarabRenderer::connect(None)?;
// Create a buffer and draw to it
let size = renderer.size()?;
let mut buffer = Buffer::new(size);
let style = Style::new().fg(Color::Green);
buffer.set_string(0, 0, "Hello, Scarab!", style);
// Render to shared memory
renderer.draw(&buffer)?;
renderer.flush()?;
use fusabi_tui_scarab::prelude::*;
struct MyPlugin {
counter: u32,
}
impl TuiPlugin for MyPlugin {
fn on_init(&mut self, ctx: &PluginContext) -> Result<()> {
println!("Plugin initialized!");
Ok(())
}
fn on_render(&mut self, ctx: &RenderContext) -> Result<Buffer> {
let mut buffer = Buffer::new(ctx.size);
let style = Style::new().fg(Color::Cyan);
let text = format!("Frame: {}", ctx.frame);
buffer.set_string(0, 0, &text, style);
Ok(buffer)
}
fn on_input(&mut self, event: InputEvent) -> Result<Action> {
self.counter += 1;
Ok(Action::Redraw)
}
}
The shared memory region contains:
All structures use #[repr(C)] and bytemuck::Pod for zero-copy safety.
Each cell is exactly 16 bytes:
#[repr(C)]
pub struct SharedCell {
pub char_codepoint: u32, // UTF-32 character
pub fg: u32, // ARGB foreground color
pub bg: u32, // ARGB background color
pub flags: u8, // Text attributes (bold, italic, etc.)
pub _padding: [u8; 3], // Alignment padding
}
The renderer uses lock-free synchronization:
plugin: Enables plugin system with JSON serialization (optional)See examples/scarab_plugin.rs for a complete interactive plugin example.
Run with:
cargo run --example scarab_plugin --features plugin
Run the test suite:
cargo test -p fusabi-tui-scarab
This crate matches the exact memory layout of scarab-protocol:
ScarabRenderer is Send but not Sync. Each renderer instance should be owned by a single thread, though multiple instances can connect to different shared memory regions.
MIT OR Apache-2.0