term_wm_render/lib.rs
1/// Opaque render backend trait with downcasting capability.
2/// Core crate defines this trait; UI crates downcast to concrete implementations.
3/// This enables true backend independence — core compiles without Ratatui.
4pub trait RenderBackend: std::any::Any {
5 /// Downcast to concrete backend type.
6 fn as_any_mut(&mut self) -> &mut dyn std::any::Any;
7
8 /// Returns a zero-initialized persistent mask slice sized to the current buffer.
9 /// The mask is a flat `Vec<u8>` that decouples conditional string checks from
10 /// bitwise buffer mutation — enabling SIMD-friendly two-pass rendering.
11 /// Allocates only when the buffer grows; zero allocations in steady state.
12 fn acquire_mask(&mut self) -> &mut [u8];
13}
14
15/// Abstraction over the terminal output backend.
16/// Uses trait objects (dyn) at the compositor boundary for runtime flexibility.
17/// Performance: vtable indirection is dispatched once per frame/window, not per cell.
18pub trait RenderTarget {
19 fn enter(&mut self) -> std::io::Result<()>;
20 fn exit(&mut self) -> std::io::Result<()>;
21 fn draw<F>(&mut self, f: F) -> std::io::Result<()>
22 where
23 F: FnOnce(&mut dyn RenderBackend);
24 fn repair(&mut self) -> std::io::Result<()> {
25 self.exit()?;
26 self.enter()
27 }
28}