Skip to main content

mermaid_cli/render/widgets/
mod.rs

1//! Stateless TUI widgets.
2//!
3//! Each widget takes explicit props; the compose function in
4//! `render::mod` pulls those props from `State` per frame. No widget
5//! holds a reference to any god-object.
6
7mod attachment;
8mod chat;
9mod conversation_list;
10mod input;
11mod slash_palette;
12mod status;
13mod status_banner;
14mod status_line;
15
16pub use attachment::AttachmentWidget;
17pub use chat::{ChatState, ChatWidget, ImageClickTarget};
18pub use conversation_list::ConversationListWidget;
19pub use input::{InputState, InputWidget};
20pub use slash_palette::SlashPaletteWidget;
21pub use status::StatusWidget;
22pub use status_banner::StatusBannerWidget;
23pub use status_line::StatusLineWidget;
24
25/// Local-to-render-layer generation phase enum. The compose function
26/// converts from `domain::TurnState` + `domain::GenPhase` into one of
27/// these four states; widgets render off this local view so they
28/// don't need to pattern-match the full domain enum.
29#[derive(Debug, Clone, Copy, PartialEq, Eq)]
30pub enum GenerationStatus {
31    Idle,
32    Sending,
33    Thinking,
34    Streaming,
35}
36
37impl GenerationStatus {
38    pub fn display_text(&self) -> &str {
39        match self {
40            GenerationStatus::Idle => "Idle",
41            GenerationStatus::Sending => "Sending",
42            GenerationStatus::Thinking => "Thinking",
43            GenerationStatus::Streaming => "Streaming",
44        }
45    }
46
47    /// Convert from the reducer's typed turn state. `TurnState::Idle`
48    /// maps to `Idle`; `Generating.phase` maps 1:1; every other
49    /// active variant maps to `Streaming` (the status-line widget
50    /// doesn't distinguish beyond the basic upstream/downstream
51    /// arrow).
52    pub fn from_turn(turn: &crate::domain::TurnState) -> Self {
53        use crate::domain::{GenPhase, TurnState};
54        match turn {
55            TurnState::Idle => GenerationStatus::Idle,
56            TurnState::Generating { phase, .. } => match phase {
57                GenPhase::Sending => GenerationStatus::Sending,
58                GenPhase::Thinking => GenerationStatus::Thinking,
59                GenPhase::Streaming => GenerationStatus::Streaming,
60            },
61            TurnState::ExecutingTools { .. }
62            | TurnState::Compacting { .. }
63            | TurnState::Cancelling { .. } => GenerationStatus::Streaming,
64        }
65    }
66}