Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ocaml-community/ocaml-linenoise
Self-contained OCaml bindings to linenoise, easy high level readline functionality in OCaml
https://github.com/ocaml-community/ocaml-linenoise
c-bindings linenoise ocaml readline standalone
Last synced: about 2 months ago
JSON representation
Self-contained OCaml bindings to linenoise, easy high level readline functionality in OCaml
- Host: GitHub
- URL: https://github.com/ocaml-community/ocaml-linenoise
- Owner: ocaml-community
- Created: 2016-03-10T04:50:15.000Z (almost 9 years ago)
- Default Branch: main
- Last Pushed: 2024-07-29T18:06:49.000Z (6 months ago)
- Last Synced: 2024-12-08T01:12:38.732Z (2 months ago)
- Topics: c-bindings, linenoise, ocaml, readline, standalone
- Language: C
- Homepage: http://ocaml-community.github.io/ocaml-linenoise/
- Size: 266 KB
- Stars: 51
- Watchers: 9
- Forks: 9
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
Linenoise in OCaml
--------------------[![build](https://github.com/ocaml-community/ocaml-linenoise/actions/workflows/main.yml/badge.svg)](https://github.com/ocaml-community/ocaml-linenoise/actions/workflows/main.yml)
# 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`
```shell
$ opam install linenoise
```See the pretty
documentation [here](https://ocaml-community.github.io/ocaml-linenoise/)# Example code
This example is also included in the repo under examples:
```ocaml
let rec user_input prompt cb =
match LNoise.linenoise prompt with
| None -> ()
| Some v ->
cb v;
user_input prompt cblet () =
(* LNoise.set_multiline true; *)
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> "
```