rigspark_cli/
dialog_smoke.rs1use std::io;
2
3#[derive(Debug, PartialEq, Eq)]
4pub enum Action {
5 Cancel,
6 Select,
7}
8
9#[derive(Default)]
10pub struct Progress {
11 dialogs: usize,
12 passed: bool,
13}
14
15impl Progress {
16 pub fn observe(&mut self, line: &str) -> io::Result<Option<Action>> {
17 if line.len() > 4096 {
18 return Err(io::Error::other("desktop smoke line exceeds bound"));
19 }
20 if line.contains("R22 directory picker requested") {
21 if self.passed || self.dialogs >= 2 {
22 return Err(io::Error::other("unexpected extra native dialog"));
23 }
24 self.dialogs += 1;
25 return Ok(Some(if self.dialogs == 1 {
26 Action::Cancel
27 } else {
28 Action::Select
29 }));
30 }
31 if line.contains("smoke: passed") {
32 if self.dialogs != 2 || self.passed {
33 return Err(io::Error::other("unexpected desktop success marker"));
34 }
35 self.passed = true;
36 }
37 Ok(None)
38 }
39
40 pub fn complete(&self, success: bool) -> bool {
41 success && self.dialogs == 2 && self.passed
42 }
43}