Created
January 1, 2015 22:26
-
-
Save jlturner/bdbde0b0de2a411703ca to your computer and use it in GitHub Desktop.
Infinite non-blocking curses input loop in OCaml, reading input from the keyboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let win = Curses.initscr ();; | |
Curses.nodelay win true;; | |
Curses.noecho ();; | |
let rec run () = | |
let inputCharCode = Curses.getch () in | |
let input = if inputCharCode >= 0 && inputCharCode <= 255 | |
then Some (Char.chr inputCharCode) | |
else None in | |
let couldWrite = match input with | |
| Some char -> Curses.mvaddstr 0 0 (Char.escaped char) | |
| None -> false | |
in run ();; | |
let _ = run ();; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment