Skip to main content

whycodes_core/
panel.rs

1//! Agent-writable side-panel updates.
2//!
3//! Tools push a [`PanelUpdate`] through [`PanelSink`]. The TUI maps that onto
4//! the sidebar Preview tab. No I/O here — just the payload.
5
6use std::sync::Arc;
7
8/// What the sidebar Preview tab should show.
9#[derive(Debug, Clone, PartialEq, Eq)]
10pub enum PanelUpdate {
11    /// Pin a file's contents.
12    File { path: String, text: String },
13    /// Pin a unified diff.
14    Diff { path: String, unified: String },
15    /// Pin mermaid source (TUI renders when the mermaid feature is on).
16    Mermaid { source: String },
17    /// Clear the preview.
18    Clear,
19}
20
21/// Callback the host (agent loop) installs so `panel` can reach the TUI.
22pub type PanelSink = Arc<dyn Fn(PanelUpdate) + Send + Sync>;
23
24#[cfg(test)]
25mod tests {
26    use super::*;
27
28    #[test]
29    fn panel_update_file_and_diff_variants() {
30        let file = PanelUpdate::File {
31            path: "a.rs".into(),
32            text: "fn main() {}".into(),
33        };
34        let diff = PanelUpdate::Diff {
35            path: "a.rs".into(),
36            unified: "--- a\n+++ b".into(),
37        };
38        assert_ne!(file, diff);
39        assert_eq!(PanelUpdate::Clear, PanelUpdate::Clear);
40        let mermaid = PanelUpdate::Mermaid {
41            source: "graph TD; A-->B".into(),
42        };
43        assert_ne!(file, mermaid);
44    }
45}