diff --git a/src/lib/uTop.ml b/src/lib/uTop.ml index 94ce8da..d401b8c 100644 --- a/src/lib/uTop.ml +++ b/src/lib/uTop.ml @@ -467,6 +467,8 @@ let default_prompt = let prompt = ref default_prompt +let edit_mode= ref LTerm_editor.Default + let () = Hashtbl.add Toploop.directive_table "utop_prompt_simple" (Toploop.Directive_none @@ -488,7 +490,17 @@ let () = (Toploop.Directive_none (fun () -> set_profile Dark; - prompt := default_prompt)) + prompt := default_prompt)); + + Hashtbl.add Toploop.directive_table "edit_mode_default" + (Toploop.Directive_none + (fun () -> + edit_mode:= LTerm_editor.Default)); + + Hashtbl.add Toploop.directive_table "edit_mode_vi" + (Toploop.Directive_none + (fun () -> + edit_mode:= LTerm_editor.Vi)) (* +-----------------------------------------------------------------+ | Help | diff --git a/src/lib/uTop.mli b/src/lib/uTop.mli index 1e183e3..edccf16 100644 --- a/src/lib/uTop.mli +++ b/src/lib/uTop.mli @@ -234,6 +234,11 @@ val time : float ref val prompt : LTerm_text.t React.signal ref (** The prompt. *) +(** {6 Edit mode configuration} *) + +val edit_mode : LTerm_editor.mode ref + (** The edit mode. *) + (** {6 Hooks} *) val new_command_hooks : (unit -> unit) LTerm_dlist.t diff --git a/src/lib/uTop_main.ml b/src/lib/uTop_main.ml index df979b9..ac05ef4 100644 --- a/src/lib/uTop_main.ml +++ b/src/lib/uTop_main.ml @@ -712,7 +712,12 @@ let execute_phrase = Toploop.execute_phrase let rec read_phrase term = Lwt.catch - (fun () -> (new read_phrase ~term)#run) + (fun () -> + let read_line= new read_phrase ~term in + (match !UTop.edit_mode with + | LTerm_editor.Default-> () + | LTerm_editor.Vi as mode-> read_line#set_editor_mode mode); + read_line#run) (function | Sys.Break -> LTerm.fprintl term "Interrupted." >>= fun () ->