let h = ref [] let history prefix = if prefix <> "" then List.filter (fun s -> String.starts_with ~prefix s) !h else !h let complete s = match String.get s 0 with | 'h' -> [ "hello"; "hello there"; "heya" ] | _ | (exception Invalid_argument _) -> [] let hint s = if s = "" then None else if String.starts_with ~prefix:s "hello" then let len = String.length s in Some (String.sub "hello" len (5 - len), `Fg `Cyan) else None let () = Fmt_tty.setup_std_outputs (); let ctx = Bruit_unix.stdctx ~hint () in let rec loop sys_break = let prompt = if sys_break then "[\x1b[31m130\x1b[0m] \x1b[33m>>\x1b[0m " else "\x1b[33m>>\x1b[0m " in match Bruit.run ~history ~hint ~complete ctx prompt with | String (Some s) -> let _ : int = Unix.write_substring Unix.stdout s 0 (String.length s) in let _ : int = Unix.write_substring Unix.stdout "\n" 0 1 in h := s :: !h; loop false | String None -> () | Ctrl_c -> loop true in loop false