diff options
| author | Federico Igne <undyamon@disroot.org> | 2024-01-11 19:31:31 +0100 |
|---|---|---|
| committer | Federico Igne <undyamon@disroot.org> | 2024-01-11 19:31:31 +0100 |
| commit | 055c743c55bde27f4475d3434c26d8383c0c3ea1 (patch) | |
| tree | aabf2173a9995f5795da86d5676181b62fee0e9e /lib/modes.ml | |
| parent | 416c56656af65d656f637dc8c8fdb62d0ba03e29 (diff) | |
| download | sandy-055c743c55bde27f4475d3434c26d8383c0c3ea1.tar.gz sandy-055c743c55bde27f4475d3434c26d8383c0c3ea1.zip | |
bulk: add PoC of vim-like modular editor
Diffstat (limited to 'lib/modes.ml')
| -rw-r--r-- | lib/modes.ml | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/modes.ml b/lib/modes.ml new file mode 100644 index 0000000..3d0e354 --- /dev/null +++ b/lib/modes.ml | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | type mode = Normal | Insert | ||
| 2 | type t = mode | ||
| 3 | type state = int | ||
| 4 | type 'a state_monad = state -> 'a * state | ||
| 5 | |||
| 6 | let run (f : 'a state_monad) (s : state) : 'a = f s |> fst | ||
| 7 | let return (a : 'a) : 'a state_monad = fun s -> (a, s) | ||
| 8 | |||
| 9 | let ( >>= ) (f : 'a state_monad) (g : 'a -> 'b state_monad) : 'b state_monad = | ||
| 10 | fun s -> | ||
| 11 | let a, s' = f s in | ||
| 12 | g a s' | ||
| 13 | |||
| 14 | let draw () : unit state_monad = return () | ||
| 15 | let get_keypress () : char state_monad = return 'a' | ||
| 16 | let handle_key (_ : char) : unit state_monad = return () | ||
| 17 | let rec loop () = () |> draw >>= get_keypress >>= handle_key >>= loop | ||
| 18 | let test = run (loop ()) 0 | ||
