]> git.f4mnq.fr Git - cells.git/commitdiff
Gestion propre de la fermeture de fenêtre
authorAmélia Coutard-Sander <git@f4mnq.fr>
Wed, 7 Jan 2026 13:38:52 +0000 (14:38 +0100)
committerAmélia Coutard-Sander <git@f4mnq.fr>
Wed, 7 Jan 2026 13:53:53 +0000 (14:53 +0100)
bin/main.ml

index 33c8b0e33ad661bc1f15bb66e8f99b656486dbed..ee2c987da17114c938c014c6a8d1fdcc369478f7 100644 (file)
@@ -89,17 +89,20 @@ let pick f cs =
                 Graphics.draw_rect (x - 5) (y - 5) 200 20;
                 List.iteri (fun i -> draw_text (-i - 1)) (List.map f below);
                 Graphics.synchronize ();
-                match Graphics.read_key () with
-                | 'z' -> (
-                        match above with
-                        | [] -> aux [] curr below
-                        | c :: cs -> aux cs c (curr :: below))
-                | 's' -> (
-                        match below with
-                        | [] -> aux above curr []
-                        | c :: cs -> aux (curr :: above) c cs)
-                | ' ' -> curr
-                | _ -> aux above curr below
+                if Graphics.key_pressed ()
+                then
+                  match Graphics.read_key () with
+                  | 'z' -> (
+                          match above with
+                          | [] -> aux [] curr below
+                          | c :: cs -> aux cs c (curr :: below))
+                  | 's' -> (
+                          match below with
+                          | [] -> aux above curr []
+                          | c :: cs -> aux (curr :: above) c cs)
+                  | ' ' -> curr
+                  | _ -> aux above curr below
+                else aux above curr below
         in
         match cs with
         | c :: cs -> aux [] c cs
@@ -109,12 +112,14 @@ let () =
         Graphics.open_graph "";
         Graphics.set_window_title "Automaton";
         Graphics.auto_synchronize false;
-        let m =
-                pick
-                  (fun m ->
-                    let module M = (val m : Automata.Automaton) in
-                    M.name)
-                  Automata.automata
-        in
-        let module M = (val m) in
-        run (module M)
+        try
+          let m =
+                  pick
+                    (fun m ->
+                      let module M = (val m : Automata.Automaton) in
+                      M.name)
+                    Automata.automata
+          in
+          let module M = (val m) in
+          run (module M)
+        with Graphics.Graphic_failure _ -> ()