es_fluent_cli/
app_state.rs

1use crate::core::{BuildOutcome, CrateInfo};
2use crossterm::event::KeyEvent;
3use std::{
4    collections::{HashMap, HashSet},
5    sync::{Arc, Mutex},
6    time::Instant,
7};
8
9#[derive(Debug)]
10pub enum AppEvent {
11    /// An input event from the user.
12    Input(KeyEvent),
13    /// A file change event.
14    FileChange(CrateInfo),
15    /// A tick event that occurs at a regular interval.
16    Tick,
17}
18
19pub struct AppState {
20    /// The crates that have been discovered.
21    pub crates: Vec<CrateInfo>,
22    /// The build statuses of the crates.
23    pub build_statuses: Arc<Mutex<HashMap<String, BuildOutcome>>>,
24    /// A debouncer for pending builds.
25    pub pending_builds_debouncer: HashMap<String, (CrateInfo, Instant)>,
26    /// The crates that are currently being built.
27    pub active_builds: Arc<Mutex<HashSet<String>>>,
28    /// Whether the application should quit.
29    pub should_quit: bool,
30}
31
32impl AppState {
33    /// Creates a new `AppState`.
34    pub fn new(
35        discovered_crates: Vec<CrateInfo>,
36        initial_statuses: HashMap<String, BuildOutcome>,
37    ) -> Self {
38        Self {
39            crates: discovered_crates,
40            build_statuses: Arc::new(Mutex::new(initial_statuses)),
41            pending_builds_debouncer: HashMap::new(),
42            active_builds: Arc::new(Mutex::new(HashSet::new())),
43            should_quit: false,
44        }
45    }
46}