diff --git a/src/lib/interactive.ml b/src/lib/interactive.ml index 5f58231..dc1fdb2 100644 --- a/src/lib/interactive.ml +++ b/src/lib/interactive.ml @@ -69,6 +69,11 @@ module Make (S : Types.State) (E : Types.Exec) = struct let h = ref [] + let add_history c = + let c = String.trim c in + let new_h = List.filter (fun s -> not (String.equal c s)) !h in + h := c :: new_h + let history prefix = if prefix <> "" then List.filter (fun s -> String.starts_with ~prefix s) !h else !h @@ -90,7 +95,7 @@ module Make (S : Types.State) (E : Types.Exec) = struct | String (Some c) -> let ast = Ast.of_string (String.trim c) in let ctx', _ast = Eval.run ctx ast in - h := c :: !h; + add_history c; loop ctx' | Ctrl_c -> let c = Exit.value ctx in