如何在没有返回键的情况下在OCaml中读取字符? [英] How to read a character in OCaml without a return key?
本文介绍了如何在没有返回键的情况下在OCaml中读取字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找类似input_char stdin
的东西,但没有等待返回键.我不会依赖lambda-term之类的大依赖项.
I'm looking for something like input_char stdin
but without waiting for a return key. I would not to depend on a big dependency like lambda-term.
推荐答案
全行输入很容易.一次处理一个字符在某种程度上取决于系统.如果您使用的是类似Unix的系统,则应该可以使用Unix
模块执行此操作:
Handling input in full lines is easy. Handling it a character at a time is a little bit system dependent. If you're on a Unix-like system you should be able to 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
这篇关于如何在没有返回键的情况下在OCaml中读取字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文