Skip to content

Commit

Permalink
prolog/metta_lang/metta_interp.pl
Browse files Browse the repository at this point in the history
  • Loading branch information
TeamSPoon committed Jan 4, 2025
1 parent d57ca28 commit 507a539
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions prolog/metta_lang/metta_interp.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1238,13 +1238,16 @@
type_value(warning_mode, 'default'). % Default warning handling mode

% Dynamically show all available options with descriptions in the required format, grouped and halt
show_help_options_no_halt :-
show_help_options_no_halt(Prefix) :-
findall([Name, DefaultValue, Type, Help, Group],
option_value_name_default_type_help(Name, DefaultValue, Type, Help, Group),
Options),
max_name_length(Options, MaxLen),
format(" First value is the default; if a brown value is listed, it is the Rust compatibility default:\n\n"),
group_options(Options, MaxLen),!.
group_options(Prefix, Options, MaxLen),!.

show_repl_help:- show_help_options_no_halt(" @").
show_help_options_no_halt:- show_help_options_no_halt(" --").

show_help_options:-
show_help_options_no_halt,
Expand All @@ -1256,23 +1259,23 @@
max_list(Lengths, MaxLen).

% Group the options by category and print them
group_options(Options, MaxLen) :-
group_options(Prefix, Options, MaxLen) :-
findall(Group, member([_, _, _, _, Group], Options), Groups),
list_to_set(Groups, SortedGroups),
print_groups(SortedGroups, Options, MaxLen).
print_groups(Prefix, SortedGroups, Options, MaxLen).


% Print options by group with clarification for defaults and Rust compatibility
print_groups([], _, _).
print_groups([Group | RestGroups], Options, MaxLen) :-
print_groups(_, [], _, _).
print_groups(Prefix, [Group | RestGroups], Options, MaxLen) :-
format(" ~w:\n", [Group]),
print_group_options(Group, Options, MaxLen),
print_group_options(Prefix, Group, Options, MaxLen),
format("\n"),
print_groups(RestGroups, Options, MaxLen).
print_groups(Prefix, RestGroups, Options, MaxLen).

% Print options in each group, aligned to the longest option name, mentioning Rust changes explicitly
print_group_options(_, [], _).
print_group_options(Group, [[Name, DefaultValue, Type, Help, Group] | Rest], MaxLen) :-
print_group_options(_, _, [], _).
print_group_options(Prefix, Group, [[Name, DefaultValue, Type, Help, Group] | Rest], MaxLen) :-
% Remove duplicates from the list of values
list_to_set(Type, UniqueValues),
list_to_set([DefaultValue|Type], [_,_|UniqueValues2]),
Expand All @@ -1282,23 +1285,23 @@
-> % Print default first, then other values, omit empty lists
(format_value_list(RestOfValues, CleanRest),
( (CleanRest \= '')
-> format(" --~w~*t=<\033[1;37m~w\033[0m|~w> \033[~dG ~w\n", [Name, MaxLen, DefaultValue, CleanRest, CommentColumn, Help])
; format(" --~w~*t=<\033[1;37m~w\033[0m> \033[~dG ~w\n", [Name, MaxLen, DefaultValue, CommentColumn, Help])
-> format("~w~w~*t=<\033[1;37m~w\033[0m|~w> \033[~dG ~w\n", [Prefix, Name, MaxLen, DefaultValue, CleanRest, CommentColumn, Help])
; format("~w~w~*t=<\033[1;37m~w\033[0m> \033[~dG ~w\n", [Prefix, Name, MaxLen, DefaultValue, CommentColumn, Help])
))
; % Case 2: If the default value is not first, list default first and mark the first value as Rust-specific
(UniqueValues = [RustSpecificValue | _RestOfValues],
DefaultValue \= RustSpecificValue)
-> % Print default first, mark the Rust value in brown, then other values, omit empty lists
(format_value_list(UniqueValues2, CleanRest),
( (CleanRest \= '')
-> format(" --~w~*t=<\033[1;37m~w\033[0m|\033[38;5;94m~w\033[0m|~w> \033[~dG ~w\n", [Name, MaxLen, DefaultValue, RustSpecificValue, CleanRest, CommentColumn, Help])
; format(" --~w~*t=<\033[1;37m~w\033[0m|\033[38;5;94m~w\033[0m> \033[~dG ~w\n", [Name, MaxLen, DefaultValue, RustSpecificValue, CommentColumn, Help])
-> format("~w~w~*t=<\033[1;37m~w\033[0m|\033[38;5;94m~w\033[0m|~w> \033[~dG ~w\n", [Prefix, Name, MaxLen, DefaultValue, RustSpecificValue, CleanRest, CommentColumn, Help])
; format("~w~w~*t=<\033[1;37m~w\033[0m|\033[38;5;94m~w\033[0m> \033[~dG ~w\n", [Prefix, Name, MaxLen, DefaultValue, RustSpecificValue, CommentColumn, Help])
))
),
print_group_options(Group, Rest, MaxLen).
print_group_options(Prefix, Group, Rest, MaxLen).

print_group_options(Group, [_ | Rest], MaxLen) :-
print_group_options(Group, Rest, MaxLen).
print_group_options(Prefix, Group, [_ | Rest], MaxLen) :-
print_group_options(Prefix, Group, Rest, MaxLen).

% Helper to print the list of values without square brackets
format_value_list([], '').
Expand Down

0 comments on commit 507a539

Please sign in to comment.