This repository has been archived by the owner on Jul 18, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Use readline inside repl task.
WIP: doesn't track done messages properly.
- Loading branch information
1 parent
8851eb5
commit c9c4ad1
Showing
6 changed files
with
63 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
true:package(core),package(async),thread,annot,debugging | ||
true:package(core),package(async),package(ctypes.foreign),thread,annot,debugging |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
open Ctypes | ||
open Foreign | ||
|
||
let libreadline = Dl.(dlopen ~filename:"libreadline.so" ~flags:[RTLD_NOW]) | ||
|
||
let readline = foreign "readline" (string @-> returning (ptr_opt char)) | ||
~from:libreadline | ||
|
||
let add_history = foreign "add_history" (string @-> returning void) | ||
~from:libreadline | ||
|
||
let read prompt = | ||
let rec strlen p n = | ||
match !@(p +@ n) with | ||
| '\000' -> n | ||
| _ -> strlen p (n + 1) in | ||
|
||
(* Ctypes needs help for some reason to convert char ptr to string *) | ||
let string_of_char_ptr charp = | ||
let length = strlen charp 0 in | ||
let s = String.create length in | ||
for i = 0 to length - 1 do | ||
s.[i] <- !@ (charp +@ i) | ||
done; | ||
s in | ||
|
||
(* TODO: teach readline that C-a shouldn't always go to BOL *) | ||
match readline prompt with | ||
| Some s -> let input = string_of_char_ptr s in | ||
add_history input; Some input | ||
| None -> None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
open Core.Std | ||
|
||
let repl_message input session = | ||
([("session", session); | ||
("op", "eval"); | ||
("id", "repl-init"); | ||
("ns", "user"); | ||
("code", input)], | ||
Nrepl.print_all) | ||
|
||
let rec main port = | ||
match Readline.read "> " with | ||
| Some input -> let _ = Client.eval port [repl_message input] in main port | ||
| None -> exit 0 | ||
|
||
|