putzen_cli/caches/tui/effect.rs
1//! IO descriptions yielded by `update`. The runtime's `EffectRunner` is the
2//! only place these are realised; each variant fixes which `Msg` is emitted
3//! back into the loop on completion.
4
5use super::Msg;
6use std::path::PathBuf;
7use std::time::Duration;
8
9#[derive(Debug, Clone)]
10pub enum Effect {
11 /// Enumerate cache subdirectories. On completion: `Msg::ScanCompleted`.
12 SpawnScan {
13 parent_label: String,
14 parent_path: PathBuf,
15 },
16
17 /// Re-stat a single cache directory. On completion: `Msg::RefreshCompleted`.
18 SpawnRefresh { path: PathBuf },
19
20 /// Delete the given items (real or dry-run). On completion: `Msg::DeleteCompleted`.
21 SpawnDelete {
22 items: Vec<(usize, PathBuf, u64)>,
23 dry_run: bool,
24 },
25
26 /// Wait `dur`, then dispatch `msg` into the loop.
27 EmitAfter { dur: Duration, msg: Msg },
28
29 /// Run the top-level seed scan that populates the initial cache list.
30 /// On completion: `Msg::SeedsLoaded`. Dispatched once at startup so the
31 /// TUI is already drawn (with a spinner) while this work happens.
32 LoadSeeds { seeds: Vec<PathBuf> },
33}
34
35#[cfg(test)]
36mod tests {
37 use super::*;
38
39 #[test]
40 fn variants_construct() {
41 let _ = Effect::SpawnScan {
42 parent_label: "x".into(),
43 parent_path: PathBuf::from("/x"),
44 };
45 let _ = Effect::SpawnRefresh {
46 path: PathBuf::from("/x"),
47 };
48 let _ = Effect::SpawnDelete {
49 items: vec![],
50 dry_run: true,
51 };
52 let _ = Effect::EmitAfter {
53 dur: Duration::from_millis(0),
54 msg: Msg::Tick,
55 };
56 }
57}