linenoise

AuthorEdgar Aroutiounian <edgar.factorial@gmail.com>
LicenseBSD-3-clause
Homepagehttps://github.com/fxfactorial/ocaml-linenoise
Issue Trackerhttps://github.com/fxfactorial/ocaml-linenoise/issues
MaintainerEdgar Aroutiounian <edgar.factorial@gmail.com>
Dependencies
&oasis>= 0.4
ocamlfind
Availableocaml-version >= "4.03.0"
PublishedOct 26, 2016
Source [http] https://github.com/fxfactorial/ocaml-linenoise/archive/v1.0.0.tar.gz
ea88336d4231b02c1ae4ed142c66be2c
StatisticsInstalled 57 times last month.
Edithttps://github.com/ocaml/opam-repository/tree/master/packages/linenoise/linenoise.1.0.0/opam

Simple readline like functionality with nice hints feature.

These are self contained OCaml bindings to linenoise, no system libraries needed at all.

Here's a simple program:

let rec user_input prompt cb = match LNoise.linenoise prompt with | None -> () | Some v ->

cb v;
user_input prompt cb

let () = LNoise.set_hints_callback (fun line ->

  if line <> "git remote add " then None
  else Some (" <this is the remote name> <this is the remote URL>",
             LNoise.Yellow,
             true)
);

LNoise.history_load ~filename:"history.txt" |> ignore; LNoise.history_set ~max_length:100 |> ignore; LNoise.set_completion_callback begin fun line_so_far ln_completions ->

if line_so_far <> "" && line_so_far.[0] = 'h' then
  ["Hey"; "Howard"; "Hughes";"Hocus"]
  |> List.iter (LNoise.add_completion ln_completions);

end; ["These are OCaml bindings to linenoise"; "get tab completion with <TAB>, type h then hit <TAB>"; "type quit to exit gracefully"; "By Edgar Aroutiounian\n"] |> List.iter print_endline; (fun from_user ->

 if from_user = "quit" then exit 0;
 LNoise.history_add from_user |> ignore;
 LNoise.history_save ~filename:"history.txt" |> ignore;
 Printf.sprintf "Got: %s" from_user |> print_endline

) |> user_input "test_program> "

and compile with: $ ocamlfind ocamlopt ex.ml -package linenoise -linkpkg -o T

Necessary for
ogen
|&>= 0.1.2
0.1.3
>= 0.1.4