char_time:- catch(call_with_time_limit(5, get_single_char(X)), time_limit_exceeded, writeln('Too late!')),
(ground(X) -> (char_code(Y, X), write('You picked '), writeln(Y)); true).
When I call ?- char_time.
and enter a character, it behaves as expected. If I don't enter a character, it prints "Too late!" and returns true as it should, but then I get the error message:
ERROR: '$raw_read'/2: I/O error in read on stream user_input (Interrupted system call)
ERROR: I/O error in read on stream user_input (Interrupted system call)
ERROR: In:
ERROR: [7] throw(error(io_error(read,user_input),context(...,'Interrupted system call')))
Is there any way around this problem? I thought of replacing get_single_char/1
with something else, but most other predicates similar to it wait for you to press Enter, and I'd prefer the menu to be operated with a single key press. I also tried enclosing the whole thing in an additional catch/3
predicate, leaving the second argument as _ so it should theoretically catch any error, but that didn't solve the problem.