From f2b7f436a9d4d64ec667669cb5a8df70b1484e41 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 14 Mar 2021 20:33:25 +0000 Subject: [PATCH] wdt: Break out retrieve_log Signed-off-by: Ian Jackson --- wdriver/wdriver.rs | 20 ++++++++++++++++++++ wdriver/wdt-simple.rs | 11 +---------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/wdriver/wdriver.rs b/wdriver/wdriver.rs index d71024a7..f1f23708 100644 --- a/wdriver/wdriver.rs +++ b/wdriver/wdriver.rs @@ -292,6 +292,26 @@ impl<'g> WindowGuard<'g> { })() .context("convert game position to web page coordinates")? } + + #[throws(AE)] + pub fn retrieve_log( + &self, + wanted_pred: &mut dyn FnMut(&str) -> bool) + -> Vec + { + let log = self.find_elements(By::ClassName("logmsg"))?; + let log = log.iter() + .rev() + .map(|e| e.inner_html()) + .take_while(|h| { + h.as_ref().ok() + .map(|s: &String| wanted_pred(s)) + != Some(true) + }) + .collect::,_>>()?; + log + } + } pub type WebCoord = i32; diff --git a/wdriver/wdt-simple.rs b/wdriver/wdt-simple.rs index 922e64cb..6f38cd53 100644 --- a/wdriver/wdt-simple.rs +++ b/wdriver/wdt-simple.rs @@ -245,17 +245,8 @@ impl Ctx { w.synch()?; let p = w.find_piece(pc)?; let now = p.posg()?; - let log = w.find_elements(By::ClassName("logmsg"))?; - let log = log.iter() - .rev() - .map(|e| e.inner_html()) - .take_while(|h| { - h.as_ref().ok() - .map(|s| s.contains("black knight")) - != Some(true) - }) - .collect::,_>>()?; + let log = w.retrieve_log(&mut |s| s.contains("black knight"))?; let held = w.piece_held(&pc)?; let client = w.client()?; let yes = held.as_ref() == Some(&client); -- 2.30.2