OCaml port of Linenoise
at main 27 lines 661 B view raw
1let h = ref [] 2 3let history prefix = 4 if prefix <> "" then List.filter (fun s -> String.starts_with ~prefix s) !h 5 else !h 6 7let complete s = 8 match String.get s 0 with 9 | 'h' -> [ "hello"; "hello there" ] 10 | _ | (exception Invalid_argument _) -> [] 11 12let () = 13 Fmt_tty.setup_std_outputs (); 14 let rec loop sys_break = 15 let prompt = 16 if sys_break then "[\x1b[31m130\x1b[0m] \x1b[33m>>\x1b[0m " 17 else "\x1b[33m>>\x1b[0m " 18 in 19 match Bruit.bruit ~history ~complete prompt with 20 | String (Some s) -> 21 Fmt.pr "\n%s\n%!" s; 22 h := s :: !h; 23 loop false 24 | String None -> () 25 | Ctrl_c -> loop true 26 in 27 loop false