mermaid_cli/tui/state/
generation.rs1use std::time::Instant;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum GenerationStatus {
10 Idle,
12 Sending,
14 Thinking,
16 Streaming,
18}
19
20impl GenerationStatus {
21 pub fn display_text(&self) -> &str {
22 match self {
23 GenerationStatus::Idle => "Idle",
24 GenerationStatus::Sending => "Sending",
25 GenerationStatus::Thinking => "Thinking",
26 GenerationStatus::Streaming => "Streaming",
27 }
28 }
29}
30
31#[derive(Debug, Clone)]
34pub enum AppState {
35 Idle,
37
38 Generating {
40 status: GenerationStatus,
41 start_time: Instant,
42 tokens_received: usize,
43 abort_handle: Option<tokio::task::AbortHandle>,
44 response_buffer: String,
46 response_truncated: bool,
50 },
51}
52
53impl AppState {
54 pub fn generation_status(&self) -> Option<GenerationStatus> {
56 match self {
57 AppState::Generating { status, .. } => Some(*status),
58 _ => None,
59 }
60 }
61
62 pub fn is_generating(&self) -> bool {
64 matches!(self, AppState::Generating { .. })
65 }
66
67 pub fn is_idle(&self) -> bool {
69 matches!(self, AppState::Idle)
70 }
71
72 pub fn generation_start_time(&self) -> Option<Instant> {
74 match self {
75 AppState::Generating { start_time, .. } => Some(*start_time),
76 _ => None,
77 }
78 }
79
80 pub fn tokens_received(&self) -> Option<usize> {
82 match self {
83 AppState::Generating {
84 tokens_received, ..
85 } => Some(*tokens_received),
86 _ => None,
87 }
88 }
89
90 pub fn abort_handle(&self) -> Option<&tokio::task::AbortHandle> {
92 match self {
93 AppState::Generating { abort_handle, .. } => abort_handle.as_ref(),
94 _ => None,
95 }
96 }
97}