package linenoise

  1. Overview
  2. Docs
Simple readline like functionality with nice hints feature.

Install

Dune Dependency

Authors

Maintainers

Sources

v1.1.0.tar.gz
sha256=0ae814442c7ac68b7989bc2b18bb7e426823ba85a386d0e304b58d285c3ec5af
md5=0d47ce859602ce719fd4372b79255d58

Description

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 (" ", 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 , type h then hit "; "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

Published: 05 May 2018

README

Linenoise in OCaml

Benefits

  1. BSD licensed.

  2. No system dependencies, no need for readline on your machine.

  3. Related to 2, these bindings are self-contained, the source for linenoise is in this repo and compiled all together with the OCaml.

  4. Written in OCaml.

  5. Pretty cool hints feature, see the gif.

Installation

It is easy with opam

$ opam install linenoise

See the pretty documentation here

Example code

This example is also included in the repo under examples:

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

let () =
  (* LNoise.set_multiline true; *)
  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> "

Dependencies (3)

  1. result
  2. jbuilder >= "1.0+beta7"
  3. ocaml < "4.09"

Dev Dependencies

None

Used by (8)

  1. alba >= "0.4.1"
  2. asli
  3. bap-analyze
  4. beluga = "1.0"
  5. links >= "0.7"
  6. ocamline >= "1.2"
  7. ogen = "0.1.2" | >= "0.1.4"
  8. sail

Conflicts

None

OCaml

Innovation. Community. Security.