Skip to main content

oxi/tui/
v2_bridge.rs

1//! Bridge module for the new oxi-tui v2 pipeline.
2//! Re-exports key types for incremental migration from legacy.
3//! Once migration is complete, this module is removed and oxi-cli
4//! uses oxi-tui directly.
5
6use ratatui::Frame;
7use ratatui::layout::Rect;
8
9/// Temporary adapter that wraps a legacy render closure as a [`Renderable`].
10///
11/// The content hash changes every frame because legacy rendering is not
12/// memoizable. Remove this adapter once the legacy widgets have migrated to
13/// native `Renderable` implementations.
14pub struct ClosureRoot {
15    render_fn: Box<dyn FnMut(&mut Frame<'_>)>,
16    frame_counter: u64,
17}
18
19impl ClosureRoot {
20    /// Creates an adapter around a legacy frame-rendering closure.
21    pub fn new<F>(render_fn: F) -> Self
22    where
23        F: FnMut(&mut Frame<'_>) + 'static,
24    {
25        Self {
26            render_fn: Box::new(render_fn),
27            frame_counter: 0,
28        }
29    }
30}
31
32impl oxi_tui::widget::Renderable for ClosureRoot {
33    fn content_hash(&self) -> u64 {
34        self.frame_counter.wrapping_add(1)
35    }
36
37    fn height_for(&self, _width: u16, _ctx: &oxi_tui::widget::RenderCtx<'_, '_>) -> u16 {
38        24
39    }
40
41    fn render(&mut self, _area: Rect, ctx: &mut oxi_tui::widget::RenderCtx<'_, '_>) {
42        self.frame_counter = self.frame_counter.wrapping_add(1);
43        ctx.with_frame(|frame| (self.render_fn)(frame));
44    }
45}
46#[allow(unused_imports)] // re-exported for downstream consumers; not used in this crate yet
47pub use oxi_tui::content::{ChatLog, ChatMessage, ContentBlock, MessageRole, StreamingState};
48#[allow(unused_imports)] // re-exported for downstream consumers; not used in this crate yet
49pub use oxi_tui::pipeline::{CursorState, FrameOutcome, draw_frame};
50#[allow(unused_imports)] // re-exported for downstream consumers; not used in this crate yet
51pub use oxi_tui::theme::{TerminalCaps, Theme as V2Theme};
52#[allow(unused_imports)] // re-exported for downstream consumers; not used in this crate yet
53pub use oxi_tui::widget::chat::ChatView;
54#[allow(unused_imports)] // re-exported for downstream consumers; not used in this crate yet
55pub use oxi_tui::widget::panel::Footer;
56#[allow(unused_imports)] // re-exported for downstream consumers; not used in this crate yet
57pub use oxi_tui::widget::{FocusTarget, RenderCtx, Renderable, RetainedChild, RetainedTree};