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_line;
15
16pub use approval::ApprovalModalWidget;
17pub use attachment::AttachmentWidget;
18pub use chat::{ChatState, ChatWidget, ImageClickTarget};
19pub use conversation_list::ConversationListWidget;
20pub use input::{InputState, InputWidget};
21pub use slash_palette::SlashPaletteWidget;
22pub use status::StatusWidget;
23pub use status_line::build_status_lines;
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    RunningTools,
36    Compacting,
37    Cancelling,
38}
39
40impl GenerationStatus {
41    pub fn display_text(&self) -> &str {
42        match self {
43            GenerationStatus::Idle => "Idle",
44            GenerationStatus::Sending => "Sending",
45            GenerationStatus::Thinking => "Thinking",
46            GenerationStatus::Streaming => "Streaming",
47            GenerationStatus::RunningTools => "Running tools",
48            GenerationStatus::Compacting => "Compacting",
49            GenerationStatus::Cancelling => "Cancelling",
50        }
51    }
52
53    /// Convert from the reducer's typed turn state. `TurnState::Idle`
54    /// maps to `Idle`; `Generating.phase` maps 1:1; every other
55    /// active variant maps to `Streaming` (the status-line widget
56    /// doesn't distinguish beyond the basic upstream/downstream
57    /// arrow).
58    pub fn from_turn(turn: &crate::domain::TurnState) -> Self {
59        use crate::domain::{GenPhase, TurnState};
60        match turn {
61            TurnState::Idle => GenerationStatus::Idle,
62            TurnState::Generating { phase, .. } => match phase {
63                GenPhase::Sending => GenerationStatus::Sending,
64                GenPhase::Thinking => GenerationStatus::Thinking,
65                GenPhase::Streaming => GenerationStatus::Streaming,
66            },
67            TurnState::ExecutingTools { .. } => GenerationStatus::RunningTools,
68            TurnState::Compacting { .. } => GenerationStatus::Compacting,
69            TurnState::Cancelling { .. } => GenerationStatus::Cancelling,
70        }
71    }
72}