diff --git a/src/lib/interactive.ml b/src/lib/interactive.ml index a9b54c1..5f58231 100644 --- a/src/lib/interactive.ml +++ b/src/lib/interactive.ml @@ -65,6 +65,14 @@ module Make (S : Types.State) (E : Types.Exec) = struct | S_DIR -> completions path None | _ -> []) + (* For now a very simple, prefixed based history *) + + let h = ref [] + + let history prefix = + if prefix <> "" then List.filter (fun s -> String.starts_with ~prefix s) !h + else !h + let run ?(prompt = default_prompt) initial_ctx = Sys.set_signal Sys.sigttou Sys.Signal_ignore; Sys.set_signal Sys.sigttin Sys.Signal_ignore; @@ -75,16 +83,14 @@ module Make (S : Types.State) (E : Types.Exec) = struct |> Option.map Ast.word_components_to_string); let p = prompt ctx in Fmt.pr "%s\r%!" p; - match Bruit.bruit ~complete "" with + match Bruit.bruit ~history ~complete "" with | String None -> Fmt.pr "exit\n%!"; exit 0 | String (Some c) -> - (* Fmt.epr ">>> [%s]\n%!" c; *) let ast = Ast.of_string (String.trim c) in let ctx', _ast = Eval.run ctx ast in - (* TODO: Make better History abstraction *) - (* let _ : (unit, string) result = LNoise.history_add c in *) + h := c :: !h; loop ctx' | Ctrl_c -> let c = Exit.value ctx in