-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathread_keyword.ml
48 lines (39 loc) · 1.12 KB
/
read_keyword.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
(*
* read_keyword.ml
* ----------------
* Copyright : (c) 2022, Shiwei Weng <[email protected]>
* Licence : BSD3
*
* This file is a part of Lambda-Term.
*)
(* Read a keyword and display it. *)
open Lwt_react
let ( >>= ) = Lwt.( >>= )
type move = Play | Pause
class read_keyword term = object(self)
inherit [move] LTerm_read_line.read_keyword () as super
inherit [move LTerm_read_line.read_keyword_result] LTerm_read_line.term term
method! send_action = function
| LTerm_read_line.Break ->
(* Ignore Ctrl+C *)
()
| action ->
super#send_action action
method! keywords = [
Zed_string.of_utf8 "play", Play;
Zed_string.of_utf8 "pause", Pause
]
initializer
self#set_prompt (S.const (LTerm_text.of_utf8 "Type a read_keyword: "))
end
let main () =
LTerm_inputrc.load ()
>>= fun () ->
Lazy.force LTerm.stdout
>>= fun term ->
(new read_keyword term)#run
>>= function
| Rk_value Play -> Lwt_io.printlf "You played it"
| Rk_value Pause -> Lwt_io.printlf "You paused it"
| Rk_error _ -> Lwt_io.printlf "You didn't type a keyword"
let () = Lwt_main.run (main ())