1 % (c) 2009-2022 Lehrstuhl fuer Softwaretechnik und Programmiersprachen,
2 % Heinrich Heine Universitaet Duesseldorf
3 % This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html)
4
5 :- module(user_interrupts,[interruptable_call/1, interruptable_call/2,
6 catch_interrupt_assertion_call/1,
7 process_interrupted_error_message/0]).
8
9 :- use_module(module_information).
10
11 :- module_info(group,infrastructure).
12 :- module_info(description,'This module allows to call predicates which can be interrupted by cntrl-c.').
13
14 :- use_module(error_manager).
15
16 %:- use_module(extension('user_signal/user_signal'), [get_user_signal_ref/1]).
17 :- meta_predicate catch_interrupt_assertion_call(0).
18 catch_interrupt_assertion_call(Call) :-
19 ? catch(Call,
20 error(forced_interrupt_error('User has interrupted the current execution'),_),
21 (process_interrupted_error_message,fail)).
22
23 process_interrupted_error_message :-
24 add_error(probcli,'User has interrupted current execution.').
25
26
27 :- use_module(extension('user_signal/user_signal'), [user_interruptable_call_det/2]).
28 :- meta_predicate interruptable_call(0).
29 interruptable_call(Call) :-
30 user_interruptable_call_det(catch_interrupt_assertion_call(Call),InterruptResult),
31 (InterruptResult=interrupted -> print(' **KeyboardInterrupt**'),nl,fail ; true).
32
33 :- meta_predicate interruptable_call(0,-).
34 interruptable_call(Call,InterruptResult) :-
35 user_interruptable_call_det(catch_interrupt_assertion_call(Call),InterruptResult),
36 (InterruptResult=interrupted -> print(' **KeyboardInterrupt**'),nl ; true),
37 print(interruptable_call(Call,InterruptResult)),nl.
38