Shells in OCaml
3
fork

Configure Feed

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

Raw mode IO for interactive sessions

We disable all the necessary flags (and restore them) for entering
raw mode!

+38 -1
+38 -1
src/lib/interactive.ml
··· 3 3 4 4 let default_prompt _ = Fmt.str "%s >\t%!" (Unix.getcwd ()) 5 5 6 + let with_stdin_in_raw_mode fn = 7 + let saved_tio = Unix.tcgetattr Unix.stdin in 8 + let tio = 9 + { 10 + saved_tio with 11 + (* input modes *) 12 + c_ignpar = true; 13 + c_istrip = false; 14 + c_inlcr = false; 15 + c_igncr = false; 16 + c_ixon = false; 17 + (* c_ixany = false; *) 18 + (* c_iuclc = false; *) 19 + c_ixoff = false; 20 + (* output modes *) 21 + c_opost = true; 22 + (* control modes *) 23 + c_isig = false; 24 + c_icanon = false; 25 + c_echo = false; 26 + c_echoe = false; 27 + c_echok = false; 28 + c_echonl = false; 29 + (* c_iexten = false; *) 30 + 31 + (* special characters *) 32 + c_vmin = 1; 33 + c_vtime = 0; 34 + } 35 + in 36 + Unix.tcsetattr Unix.stdin TCSADRAIN tio; 37 + Fun.protect 38 + ~finally:(fun () -> Unix.tcsetattr Unix.stdin TCSADRAIN saved_tio) 39 + fn 40 + 6 41 let run ?(prompt = default_prompt) initial_ctx = 7 42 let rec loop (ctx : Eval.ctx) = 8 43 let p = prompt ctx.state in ··· 10 45 | None -> loop ctx 11 46 | Some c -> 12 47 let ast = Ast.of_string c in 13 - let ctx', _ast = Eval.run ctx ast in 48 + let ctx', _ast = 49 + with_stdin_in_raw_mode @@ fun () -> Eval.run ctx ast 50 + in 14 51 loop ctx' 15 52 in 16 53 loop initial_ctx