1:- module(pager, [with_pager/1]).
10:- meta_predicate with_pager(0). 11with_pager(Goal) :-
12 stream_property(current_output,tty(true)),
13 !,
14 setup_call_cleanup(
15 with_pager_setup(PagerIn,Pid),
16 with_output_to(PagerIn,Goal),
17 with_pager_cleanup(PagerIn,Pid)
18 ).
19with_pager(Goal) :-
20 call(Goal).
21
22
(PagerIn,Pid) :-
25 once( getenv('PAGER',Pager)
26 ; Pager=less
27 ),
28 process_create(
29 path(Pager),
30 [],
31 [
32 stdin(pipe(PagerIn)),
33 stdout(std),
34 process(Pid)
35 ]
36 ).
37
(PagerIn,Pid) :-
40 close(PagerIn),
41 process_wait(Pid,_Status)