Something went wrong. Try again.
OCaml port of Linenoise
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667{0 Bruit}{! Bruit} is a pure OCaml port of {{: https://github.com/antirez/linenoise} linenoise}, whichis itself a:{%html: <blockquote> A minimal, zero-config, BSD licensed, readline replacement used in Redis, MongoDB, Android and many other projects. </blockquote>%}Other line editing tools exist such as {{: https://ocaml.org/p/ledit/latest} [ledit]}.{1:user_guides User guides}{ul{- Try the {{!quick_start} quick start} guide to get up and running quickly.}{- See the {{!manual} manual} for more complex examples.}}{1:library_bruit Library [bruit]}{!modules: Bruit}{1:library_unix Library [bruit.unix]}{!modules: Bruit_unix}{1:library_brr Library [bruit.brr]}{!modules: Bruit_brr}{1:quick_start Quick start}The following simple example first creates a portable line editing tool called[line_editor] and then passes a configuration to the {! Bruit_unix} backend forrunning the command line editor.It adds a simple completion to any string starting with ["hel"].{[let prompt = "> " let line_editor ctx = let complete s = if String.starts_with ~prefix:"hel" s then [ "hello"; "hello, world!" ] else [] in Bruit.run ~complete ctx promptlet () = let ctx = Bruit_unix.stdctx () in let rec loop () = match line_editor ctx with | String (Some s) -> Fmt.pr "%s\n%!" s; loop () | String None -> () | Ctrl_c -> Fmt.pr "\n%!"; loop () in loop ()]}