Shells in OCaml
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

Readd new history callback

+10 -4
+10 -4
src/lib/interactive.ml
··· 65 65 | S_DIR -> completions path None 66 66 | _ -> []) 67 67 68 + (* For now a very simple, prefixed based history *) 69 + 70 + let h = ref [] 71 + 72 + let history prefix = 73 + if prefix <> "" then List.filter (fun s -> String.starts_with ~prefix s) !h 74 + else !h 75 + 68 76 let run ?(prompt = default_prompt) initial_ctx = 69 77 Sys.set_signal Sys.sigttou Sys.Signal_ignore; 70 78 Sys.set_signal Sys.sigttin Sys.Signal_ignore; ··· 75 83 |> Option.map Ast.word_components_to_string); 76 84 let p = prompt ctx in 77 85 Fmt.pr "%s\r%!" p; 78 - match Bruit.bruit ~complete "" with 86 + match Bruit.bruit ~history ~complete "" with 79 87 | String None -> 80 88 Fmt.pr "exit\n%!"; 81 89 exit 0 82 90 | String (Some c) -> 83 - (* Fmt.epr ">>> [%s]\n%!" c; *) 84 91 let ast = Ast.of_string (String.trim c) in 85 92 let ctx', _ast = Eval.run ctx ast in 86 - (* TODO: Make better History abstraction *) 87 - (* let _ : (unit, string) result = LNoise.history_add c in *) 93 + h := c :: !h; 88 94 loop ctx' 89 95 | Ctrl_c -> 90 96 let c = Exit.value ctx in