Skip to content

Instantly share code, notes, and snippets.

@jlturner
Created January 1, 2015 22:26
Show Gist options
  • Save jlturner/bdbde0b0de2a411703ca to your computer and use it in GitHub Desktop.
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
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