Graphics.moveto 10 8;
Graphics.draw_string (":" ^ cmd)
- let run_cmd estate cmd =
+ let run_cmd (EditorState (m, st) as estate) cmd =
+ let module M = (val m) in
match cmd with
| "quit" ->
Graphics.close_graph ();
- (estate, Either.right (ModeAux.ModeAndState ((module Normal), Normal.initial ())))
+ (estate, Either.left "")
| "select" -> (estate, Either.right (ModeAux.ModeAndState ((module AutoSelector), AutoSelector.initial ())))
+ | cmd when String.starts_with ~prefix:"write " cmd ->
+ Out_channel.with_open_text
+ (String.sub cmd 6 (String.length cmd - 6))
+ (Automata.serialise (module M) st.board);
+ (EditorState (m, st), Either.right (ModeAux.ModeAndState ((module Normal), Normal.initial ())))
+ | cmd when String.starts_with ~prefix:"read " cmd ->
+ ( EditorState
+ ( m,
+ {
+ st with
+ board =
+ In_channel.with_open_text
+ (String.sub cmd 5 (String.length cmd - 5))
+ (Automata.deserialise (module M));
+ } ),
+ Either.right (ModeAux.ModeAndState ((module Normal), Normal.initial ())) )
| _ ->
Printf.fprintf stderr "Unknown cmd: `%s'\n%!" cmd;
(estate, Either.right (ModeAux.ModeAndState ((module Normal), Normal.initial ())))
| 'l' -> (EditorState (m, ntimes n (chpos 1 0) st), Either.left { n = None })
| 'i' -> (EditorState (m, ntimes n (chsize 1) st), Either.left { n = None })
| 'o' -> (EditorState (m, ntimes n (chsize (-1)) st), Either.left { n = None })
- | 'w' ->
- Out_channel.with_open_text "test.auto" (Automata.serialise (module M) st.board);
- (EditorState (m, st), Either.left { n = None })
- | 'r' ->
- ( EditorState
- (m, { st with board = In_channel.with_open_text "test.auto" (Automata.deserialise (module M)) }),
- Either.left { n = None } )
| _ -> (EditorState (m, st), Either.left { n = None })
end