-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.pl
100 lines (85 loc) · 2.05 KB
/
ui.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
% USER INTERFACE
:- module(ui,[select_mult_list/3,select_one_list/3,
display_list/1, display_listq/1, display_list/2, display_listq/2,
enter_a_number/2,
gdisplay_term/1,
notify/2]).
% :- use_module(library(gvterm)).
% :- use_module(library(graphml_ugraph)).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% User Interface
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Primitive actions
%
% select_mult_list
% select_one_list
% display_list
% enter_a_number
select_mult_list(List,Mark,Selection) :-
writeln('Select one or more from;'),
display_list(List,Mark),
write('Enter selection as list [...]. : '),
read(Selection).
select_one_list(List,Mark,Selection) :-
writeln('Select one from;'),
display_list(List,Mark),
write('Enter selection as Item #. : '),
read(Selection).
gdisplay_term(_L) :-
% dotty_term(L),
true.
display_list([]).
display_list([T|L]) :-
writeln(T),
display_list(L).
display_list([],_).
display_list([Item|Items],N) :- number(N), !,
format('~t~d)~4| ', N), % keep column up to 999
write(Item), nl,
N1 is N + 1,
display_list(Items,N1).
display_list([Item|Items],Mark) :- atom(Mark), !,
format(' ~a ',Mark),
write(Item), nl,
display_list(Items,Mark).
display_listq([]).
display_listq([T|L]) :-
writeq(T), nl,
display_listq(L).
display_listq([],_).
display_listq([Item|Items],N) :- number(N), !,
format('~t~d)~4| ', N), % keep column up to 999
writeq(Item), nl,
N1 is N + 1,
display_listq(Items,N1).
display_listq([Item|Items],Mark) :- atom(Mark), !,
format(' ~a ',Mark),
writeq(Item), nl,
display_listq(Items,Mark).
portray(T) :- writeq(T).
enter_a_number(N,Message) :-
format('~a~nEnter a number...~n',Message),
readln(L),
( L=[N], number(N)
-> true
; enter_a_number(N,Message)
).
notify(warning,M) :- !,
( atom(M)
-> format('Warning: ~a~n',[M])
; true
).
notify(notice,M) :- !,
( atom(M)
-> format('Notice: ~a~n',[M])
; true
).
notify(Kind,M) :- !,
( atom(Kind), atom(M)
-> format('~a: ~a~n',[Kind,M])
; true
).
notify(_,_).