mermaid_cli/tui/state/
generation.rs1use std::time::Instant;
6
7use crate::agents::AgentAction;
8
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11pub enum GenerationStatus {
12 Idle,
14 Sending,
16 Initializing,
18 Thinking,
20 Streaming,
22}
23
24impl GenerationStatus {
25 pub fn display_text(&self) -> &str {
26 match self {
27 GenerationStatus::Idle => "Idle",
28 GenerationStatus::Sending => "Sending",
29 GenerationStatus::Initializing => "Initializing",
30 GenerationStatus::Thinking => "Thinking",
31 GenerationStatus::Streaming => "Streaming",
32 }
33 }
34}
35
36#[derive(Debug, Clone)]
39pub enum AppState {
40 Idle,
42
43 Generating {
45 status: GenerationStatus,
46 start_time: Instant,
47 tokens_received: usize,
48 abort_handle: Option<tokio::task::AbortHandle>,
49 },
50
51 ExecutingAction {
53 action: AgentAction,
54 start_time: Instant,
55 },
56
57 ReadingFileFeedback {
59 intent: Option<String>,
60 started_at: Instant,
61 },
62}
63
64impl AppState {
65 pub fn generation_status(&self) -> Option<GenerationStatus> {
67 match self {
68 AppState::Generating { status, .. } => Some(*status),
69 _ => None,
70 }
71 }
72
73 pub fn is_generating(&self) -> bool {
75 matches!(self, AppState::Generating { .. })
76 }
77
78 pub fn is_idle(&self) -> bool {
80 matches!(self, AppState::Idle)
81 }
82
83 pub fn generation_start_time(&self) -> Option<Instant> {
85 match self {
86 AppState::Generating { start_time, .. } => Some(*start_time),
87 _ => None,
88 }
89 }
90
91 pub fn tokens_received(&self) -> Option<usize> {
93 match self {
94 AppState::Generating { tokens_received, .. } => Some(*tokens_received),
95 _ => None,
96 }
97 }
98
99 pub fn abort_handle(&self) -> Option<&tokio::task::AbortHandle> {
101 match self {
102 AppState::Generating { abort_handle, .. } => abort_handle.as_ref(),
103 _ => None,
104 }
105 }
106
107 pub fn is_reading_file_feedback(&self) -> bool {
109 matches!(self, AppState::ReadingFileFeedback { .. })
110 }
111
112 pub fn action_start_time(&self) -> Option<Instant> {
114 match self {
115 AppState::ExecutingAction { start_time, .. } => Some(*start_time),
116 _ => None,
117 }
118 }
119}