Skip to content

Commit

Permalink
Merge pull request #13 from stassa/master
Browse files Browse the repository at this point in the history
our_ansi_format/3 will no longer raise an exception when called nondet.
  • Loading branch information
TeamSPoon authored Dec 17, 2024
2 parents 1cbc3b7 + 1a928c2 commit 790c8a9
Showing 1 changed file with 32 additions and 7 deletions.
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

0 comments on commit 790c8a9

Please sign in to comment.