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