marionette: Add a callback arguments to wait-for-screen-text.
authorMaxim Cournoyer <maxim.cournoyer@gmail.com>
Fri, 23 Sep 2022 04:23:47 +0000 (00:23 -0400)
committerMaxim Cournoyer <maxim.cournoyer@gmail.com>
Fri, 7 Oct 2022 14:11:12 +0000 (10:11 -0400)
* gnu/build/marionette.scm (wait-for-screen-text): New 'pre-action' and
'post-action' arguments.  Update doc.  Call the procedures before and after
the OCR occurs, respectively.

gnu/build/marionette.scm

index 6f373f8..f4b219e 100644 (file)
@@ -331,11 +331,15 @@ if it is not needed."
 (define* (wait-for-screen-text marionette predicate
                                #:key
                                (ocr "ocrad")
-                               (timeout 30))
+                               (timeout 30)
+                               pre-action
+                               post-action)
   "Wait for TIMEOUT seconds or until the screen text on MARIONETTE matches
 PREDICATE, whichever comes first.  Raise an error when TIMEOUT is exceeded.
 The error contains the recognized text along the preserved file name of the
-screen dump, which is relative to the current working directory."
+screen dump, which is relative to the current working directory.  If
+PRE-ACTION is provided, it should be a thunk to call before each OCR attempt.
+Likewise for POST-ACTION, except it runs at the end of a successful OCR."
   (define start
     (car (gettimeofday)))
 
@@ -353,7 +357,9 @@ screen dump, which is relative to the current working directory."
           (error "'wait-for-screen-text' timeout"
                  'ocr-text: last-text
                  'screendump: screendump-backup))
-        (let* ((text screendump (marionette-screen-text marionette #:ocr ocr))
+        (let* ((_ (and (procedure? pre-action) (pre-action)))
+               (text screendump (marionette-screen-text marionette #:ocr ocr))
+               (_ (and (procedure? post-action) (post-action)))
                (result (predicate text)))
           (cond (result
                  (delete-file screendump)