I'm trying to make a simple timed menu in SWI-Prolog. The user should be able to hit a key to select an option, or if they press nothing it will automatically select the default option after a few seconds. I wrote this to test the character input:
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.
char_timein a catch that checks for the I/O error. - lurker?- catch(char_time, _, true)but I still got the same error. It seems as if interruptingget_single_char(X)may cause an error at the operating system level, which the interpreter "passes on" but can't prevent. I was running Ubuntu 14.04.5 LTS if that helps - Jamie