package linenoise

  1. Overview
  2. Docs
Lightweight readline alternative

Install

Dune Dependency

Authors

Maintainers

Sources

linenoise-1.5.1.tbz
sha256=eef172cb98282b7a8be182f3493f4687ed3a3f833d3c2707d07d188bf9dede37
sha512=b316b034ba712f13c8727a890c5356a52119d6f5e7040273259109bfac6813c383670295942d39441b9b9e792f3b53250400da000bbe0c6848df5643e27018ac

Description

Published: 21 Mar 2024

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 + C.

  5. Pretty cool hints feature, see the gif.

  6. Additional features compared to linenoise, such as history search

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 (2)

  1. ocaml >= "4.03.0"
  2. dune >= "1.1"

Dev Dependencies (1)

  1. odoc with-doc

Used by (12)

  1. alba >= "0.4.1"
  2. asli
  3. baguette_sharp
  4. bap-analyze
  5. beluga >= "1.0"
  6. gobba >= "0.4.2"
  7. links >= "0.7"
  8. ocamline >= "1.2"
  9. ogen = "0.1.2" | >= "0.1.4"
  10. ppx_interact
  11. sail
  12. tcalc

Conflicts

None