34
35:- module(pce_reporter, []). 36:- use_module(library(pce)). 37
38:- pce_begin_class(reporter, label,
39 ).
40
41variable(hor_stretch, int := 100, get, ).
42variable(hor_shrink, int := 100, get, ).
43variable(error_delay, int := 5, both, ).
44variable(warning_delay, int := 2, both, ).
45variable(delay_next_to, date*, get, ).
46
47initialise(R) :->
48 send_super(R, initialise, reporter, ''),
49 send(R, elevation, -1),
50 send(R, border, 2),
51 send(R, reference, point(0, R?height)).
52
53report(R, Status:name, Fmt:[char_array], Args:any ...) :->
54 ( get(R, delay_next_to, DelayTo),
55 DelayTo \== @nil,
56 get(DelayTo, difference, new(date), ToGo),
57 ToGo > 0,
58 ( vital(Status)
59 -> send(timer(ToGo), delay),
60 fail
61 ; true
62 )
63 -> true
64 ; Msg =.. [report, Status, Fmt | Args],
65 colour(Status, Colour),
66 send(R, colour, Colour),
67 delay(R, Status, Date),
68 send(R, slot, delay_next_to, Date),
69 send_super(R, Msg)
70 ).
71
72colour(error, red) :- !.
73colour(_, @default).
74
75delay(R, warning, Date) :-
76 get(R, warning_delay, Delay),
77 Delay > 0,
78 !,
79 new(Date, date),
80 send(Date, advance, Delay).
81delay(R, error, Date) :-
82 get(R, error_delay, Delay),
83 Delay > 0,
84 !,
85 new(Date, date),
86 send(Date, advance, Delay).
87delay(_, _, @nil).
88
89vital(warning).
90vital(error).
91vital(inform).
92
93:- pce_end_class.
94
95
96:- pce_begin_class(report_dialog, dialog,
97 ).
98
99variable(reporter, reporter, get, ).
100delegate_to(reporter).
101
102initialise(D) :->
103 send_super(D, initialise),
104 send(D, gap, size(0, 0)),
105 send(D, resize_message, message(D, layout, @arg2)),
106 send(D, append, new(R, reporter)),
107 send(D, slot, reporter, R).
108
109:- pce_end_class