Skip to main content

vtcode_commons/ui_protocol/
loading.rs

1//! Renderer-independent aggregation of live loading signals.
2
3/// Loading is suppressed when a turn is blocked, regardless of other signals.
4#[derive(Clone, Copy, Debug, Default)]
5pub struct LoadingActivity {
6    pub blocked: bool,
7    pub turn: bool,
8    pub thinking: bool,
9    pub progress: bool,
10    pub background: bool,
11}
12
13impl LoadingActivity {
14    #[must_use]
15    pub fn is_active(self) -> bool {
16        !self.blocked && (self.turn || self.thinking || self.progress || self.background)
17    }
18}
19
20#[cfg(test)]
21mod tests {
22    use super::LoadingActivity;
23
24    #[test]
25    fn each_signal_activates_loading_and_blocked_suppresses_it() {
26        let idle = LoadingActivity::default();
27        assert!(!idle.is_active());
28        for signal in [
29            LoadingActivity { turn: true, ..idle },
30            LoadingActivity { thinking: true, ..idle },
31            LoadingActivity { progress: true, ..idle },
32            LoadingActivity { background: true, ..idle },
33        ] {
34            assert!(signal.is_active());
35            assert!(!LoadingActivity { blocked: true, ..signal }.is_active());
36        }
37    }
38}