How to read a character in OCaml without a return key?

I am looking for something like input_char stdin , but not expecting the key to return. I would not depend on a big addiction, such as a lambda term.

+6
source share
1 answer

Processing input in full lines is easy. Processing his character at a time is slightly dependent on the system. If you are using a Unix-like system, you can do this using the Unix module:

 let get1char () = let termio = Unix.tcgetattr Unix.stdin in let () = Unix.tcsetattr Unix.stdin Unix.TCSADRAIN { termio with Unix.c_icanon = false } in let res = input_char stdin in Unix.tcsetattr Unix.stdin Unix.TCSADRAIN termio; res 
+8
source

All Articles