Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

our_ansi_format/3 will no longer raise an exception when called nondet. #13

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 32 additions & 7 deletions prolog/metta_lang/metta_testing.pl
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,38 @@
% @example
% % Apply color formatting directly:
% ?- our_ansi_format(green, 'Success: ~w', ['All tests passed']).
our_ansi_format(C, Fmt, Args) :-
% If Color is not an atom, apply ansi_format directly.
\+ atom(C), % set_stream(current_output,encoding(utf8)),
ansi_format(C, Fmt, Args).
our_ansi_format(C, Fmt, Args) :-
% If Color is atomic, set the foreground color and format the output.
our_ansi_format([fg(C)], Fmt, Args).
%
our_ansi_format(C, Fmt, Args):-
% This better be a list of ansi_format/3 attributes because we're not
% checking that. Those can be compound fg, bg etc terms, or single atoms
% denoting not font style, e.g. bold (but not colour!).
is_list(C),
!,
ansi_format(C,Fmt,Args).
% ansi_format/3 accepts as its first argument a single compound term
% denoting a colour attribute, as well as a list thereof. The following
% clause deals with single, arity-1 compounds. Acceptable attribute
% terms are found in the SWI-Prolog documentation.
our_ansi_format(CT, Fmt, Args):-
compound(CT),
CT =.. [Attr,_C],
memberchk(Attr,[fg,bg,hfg,hbg,fg8,bg8]),
!,
ansi_format(CT,Fmt,Args).
% The Attribute term may be an arity-3 compound with arguments for R, G
% and B values.
our_ansi_format(CT, Fmt, Args):-
compound(CT),
CT =.. [Attr,_R,_G,_B],
memberchk(Attr,[fg,bg]),
!,
ansi_format(CT,Fmt,Args).
% If the colour term is a single atom, then it's probably our shortcut
% for "use this colour in the forergound".
our_ansi_format(C, Fmt, Args):-
atom(C),
ansi_format([fg(C)],Fmt,Args).


%! print_current_test is det.
%
Expand Down
Loading