diff options
author | Xavier Leroy <xavier.leroy@inria.fr> | 2004-05-15 09:59:37 +0000 |
---|---|---|
committer | Xavier Leroy <xavier.leroy@inria.fr> | 2004-05-15 09:59:37 +0000 |
commit | 759292a43c82ed96f32218901f7c8f2c72c462c2 (patch) | |
tree | deb4c9c7b33bcaf4e12ce0367d7c10dc2851edc6 /toplevel | |
parent | a85d839fa0d083b61c310bdc575ffdb82fe24087 (diff) | |
download | ocaml-759292a43c82ed96f32218901f7c8f2c72c462c2.tar.gz |
Introduction d'un hook pour la lecture des entrees interactives
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@6297 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'toplevel')
-rw-r--r-- | toplevel/toploop.ml | 43 | ||||
-rw-r--r-- | toplevel/toploop.mli | 4 |
2 files changed, 31 insertions, 16 deletions
diff --git a/toplevel/toploop.ml b/toplevel/toploop.ml index 5fadff2f95..784ec4cc05 100644 --- a/toplevel/toploop.ml +++ b/toplevel/toploop.ml @@ -316,6 +316,26 @@ let use_silently ppf name = let first_line = ref true let got_eof = ref false;; +let read_input_default prompt buffer len = + output_string stdout prompt; flush stdout; + let i = ref 0 in + try + while true do + if !i >= len then raise Exit; + let c = input_char stdin in + buffer.[!i] <- c; + incr i; + if c = '\n' then raise Exit; + done; + (!i, false) + with + | End_of_file -> + (!i, true) + | Exit -> + (!i, false) + +let read_interactive_input = ref read_input_default + let refill_lexbuf buffer len = if !got_eof then (got_eof := false; 0) else begin let prompt = @@ -323,23 +343,14 @@ let refill_lexbuf buffer len = else if Lexer.in_comment () then "* " else " " in - output_string stdout prompt; flush stdout; first_line := false; - let i = ref 0 in - try - while true do - if !i >= len then raise Exit; - let c = input_char stdin in - buffer.[!i] <- c; - incr i; - if c = '\n' then raise Exit; - done; - !i - with - | End_of_file -> - Location.echo_eof (); - if !i > 0 then (got_eof := true; !i) else 0 - | Exit -> !i + let (len, eof) = !read_interactive_input prompt buffer len in + if eof then begin + Location.echo_eof (); + if len > 0 then got_eof := true; + len + end else + len end (* Toplevel initialization. Performed here instead of at the diff --git a/toplevel/toploop.mli b/toplevel/toploop.mli index 18372c6bda..6b25941c83 100644 --- a/toplevel/toploop.mli +++ b/toplevel/toploop.mli @@ -98,6 +98,10 @@ val print_out_signature : val print_out_phrase : (formatter -> Outcometree.out_phrase -> unit) ref +(* Hooks for external line editor *) + +val read_interactive_input : (string -> string -> int -> int * bool) ref + (* Hooks for initialization *) val toplevel_startup_hook : (unit -> unit) ref |