Skip to content

Commit 3df6a3e

Browse files
committed
Add user preference "ShortBanners"
If this option is set to <K>true</K>, package banners printed during loading will only show the name, version and description of a package.
1 parent 4e07232 commit 3df6a3e

File tree

3 files changed

+107
-59
lines changed

3 files changed

+107
-59
lines changed

doc/ref/user_pref_list.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,24 @@ Admissible values:
243243

244244
<P/>
245245

246+
Default: <K>false</K>.
247+
</Item>
248+
<Mark>
249+
<Index Key='ShortBanners'><C>ShortBanners</C></Index>
250+
<C>ShortBanners</C>
251+
</Mark>
252+
<Item>
253+
If this option is set to <K>true</K>, package banners printed during loading
254+
will only show the name, version and description of a package.
255+
256+
<P/>
257+
258+
Admissible values:
259+
<K>true</K>,
260+
<K>false</K>.
261+
262+
<P/>
263+
246264
Default: <K>false</K>.
247265
</Item>
248266
<Mark>

lib/package.gd

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,12 +532,15 @@ DeclareGlobalFunction( "IsPackageMarkedForLoading" );
532532
#F DefaultPackageBannerString( <inforec> )
533533
##
534534
## <ManSection>
535-
## <Func Name="DefaultPackageBannerString" Arg='inforec'/>
535+
## <Func Name="DefaultPackageBannerString" Arg='inforec[, useShortBanner]'/>
536536
##
537537
## <Description>
538538
## For a record <A>inforec</A> as stored in the <F>PackageInfo.g</F> file
539539
## of a &GAP; package,
540540
## this function returns a string denoting a banner for the package.
541+
## If the optional argument <A>useShortBanner</A> is set to <K>true</K>,
542+
## only the first line of the default banner (including the name, version and
543+
## description of the package) is returned.
541544
## </Description>
542545
## </ManSection>
543546
##

lib/package.gi

Lines changed: 85 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,9 +1099,30 @@ InstallGlobalFunction( IsPackageMarkedForLoading, function( name, version )
10991099
##
11001100
#F DefaultPackageBannerString( <inforec> )
11011101
##
1102-
InstallGlobalFunction( DefaultPackageBannerString, function( inforec )
1102+
1103+
DeclareUserPreference( rec(
1104+
name:= "ShortBanners",
1105+
description:= [
1106+
"If this option is set to <K>true</K>, package banners printed during \
1107+
loading will only show the name, version and description of a package."
1108+
],
1109+
default:= false,
1110+
values:= [ true, false ],
1111+
multi:= false,
1112+
) );
1113+
1114+
InstallGlobalFunction( DefaultPackageBannerString,
1115+
function( inforec, useShortBanner... )
11031116
local len, sep, i, str, authors, maintainers, contributors, printPersons;
11041117

1118+
if Length( useShortBanner ) = 0 then
1119+
useShortBanner := false;
1120+
elif Length( useShortBanner ) = 1 then
1121+
useShortBanner := useShortBanner[1];
1122+
else
1123+
Error( "DefaultPackageBannerString must be called with at most two arguments" );
1124+
fi;
1125+
11051126
# Start with a row of `-' signs.
11061127
len:= SizeScreen()[1] - 3;
11071128
if GAPInfo.TermEncoding = "UTF-8" then
@@ -1136,69 +1157,73 @@ InstallGlobalFunction( DefaultPackageBannerString, function( inforec )
11361157
fi;
11371158
Add( str, '\n' );
11381159

1139-
# Add info about the authors and/or maintainers
1140-
printPersons := function( role, persons )
1141-
local fill, person;
1142-
fill:= ListWithIdenticalEntries( Length(role), ' ' );
1143-
Append( str, role );
1144-
for i in [ 1 .. Length( persons ) ] do
1145-
person:= persons[i];
1146-
Append( str, person.FirstNames );
1147-
Append( str, " " );
1148-
Append( str, person.LastName );
1149-
if IsBound( person.WWWHome ) then
1150-
Append( str, Concatenation( " (", person.WWWHome, ")" ) );
1151-
elif IsBound( person.Email ) then
1152-
Append( str, Concatenation( " (", person.Email, ")" ) );
1153-
fi;
1154-
if i = Length( persons ) then
1155-
Append( str, ".\n" );
1156-
elif i = Length( persons )-1 then
1157-
if i = 1 then
1158-
Append( str, " and\n" );
1159-
else
1160-
Append( str, ", and\n" );
1160+
if not useShortBanner then
1161+
# Add info about the authors and/or maintainers
1162+
printPersons := function( role, persons )
1163+
local fill, person;
1164+
fill:= ListWithIdenticalEntries( Length(role), ' ' );
1165+
Append( str, role );
1166+
for i in [ 1 .. Length( persons ) ] do
1167+
person:= persons[i];
1168+
Append( str, person.FirstNames );
1169+
Append( str, " " );
1170+
Append( str, person.LastName );
1171+
if IsBound( person.WWWHome ) then
1172+
Append( str, Concatenation( " (", person.WWWHome, ")" ) );
1173+
elif IsBound( person.Email ) then
1174+
Append( str, Concatenation( " (", person.Email, ")" ) );
1175+
fi;
1176+
if i = Length( persons ) then
1177+
Append( str, ".\n" );
1178+
elif i = Length( persons )-1 then
1179+
if i = 1 then
1180+
Append( str, " and\n" );
1181+
else
1182+
Append( str, ", and\n" );
1183+
fi;
1184+
Append( str, fill );
1185+
else
1186+
Append( str, ",\n" );
1187+
Append( str, fill );
1188+
fi;
1189+
od;
1190+
end;
1191+
if IsBound( inforec.Persons ) then
1192+
authors:= Filtered( inforec.Persons, x -> x.IsAuthor );
1193+
if not IsEmpty( authors ) then
1194+
printPersons( "by ", authors );
1195+
fi;
1196+
contributors:= Filtered( inforec.Persons, x -> not x.IsAuthor and not x.IsMaintainer );
1197+
if not IsEmpty( contributors ) then
1198+
Append( str, "with contributions by:\n");
1199+
printPersons( " ", contributors );
1200+
fi;
1201+
maintainers:= Filtered( inforec.Persons, x -> x.IsMaintainer );
1202+
if not IsEmpty( maintainers ) and authors <> maintainers then
1203+
Append( str, "maintained by:\n");
1204+
printPersons( " ", maintainers );
11611205
fi;
1162-
Append( str, fill );
1163-
else
1164-
Append( str, ",\n" );
1165-
Append( str, fill );
11661206
fi;
1167-
od;
1168-
end;
1169-
if IsBound( inforec.Persons ) then
1170-
authors:= Filtered( inforec.Persons, x -> x.IsAuthor );
1171-
if not IsEmpty( authors ) then
1172-
printPersons( "by ", authors );
1173-
fi;
1174-
contributors:= Filtered( inforec.Persons, x -> not x.IsAuthor and not x.IsMaintainer );
1175-
if not IsEmpty( contributors ) then
1176-
Append( str, "with contributions by:\n");
1177-
printPersons( " ", contributors );
1178-
fi;
1179-
maintainers:= Filtered( inforec.Persons, x -> x.IsMaintainer );
1180-
if not IsEmpty( maintainers ) and authors <> maintainers then
1181-
Append( str, "maintained by:\n");
1182-
printPersons( " ", maintainers );
1183-
fi;
1184-
fi;
11851207

1186-
# Add info about the home page of the package.
1187-
if IsBound( inforec.PackageWWWHome ) then
1188-
Append( str, "Homepage: " );
1189-
Append( str, inforec.PackageWWWHome );
1190-
Append( str, "\n" );
1191-
fi;
1208+
# Add info about the home page of the package.
1209+
if IsBound( inforec.PackageWWWHome ) then
1210+
Append( str, "Homepage: " );
1211+
Append( str, inforec.PackageWWWHome );
1212+
Append( str, "\n" );
1213+
fi;
1214+
1215+
# Add info about the issue tracker of the package.
1216+
if IsBound( inforec.IssueTrackerURL ) then
1217+
Append( str, "Report issues at " );
1218+
Append( str, inforec.IssueTrackerURL );
1219+
Append( str, "\n" );
1220+
fi;
11921221

1193-
# Add info about the issue tracker of the package.
1194-
if IsBound( inforec.IssueTrackerURL ) then
1195-
Append( str, "Report issues at " );
1196-
Append( str, inforec.IssueTrackerURL );
1197-
Append( str, "\n" );
1222+
str := Concatenation(sep, str, sep);
11981223
fi;
11991224

12001225
# temporary hack, in some package names with umlauts are in HTML encoding
1201-
str := Concatenation(sep, RecodeForCurrentTerminal(str), sep);
1226+
str := RecodeForCurrentTerminal(str);
12021227
str:= ReplacedString( str, "&auml;", RecodeForCurrentTerminal("ä") );
12031228
str:= ReplacedString( str, "&ouml;", RecodeForCurrentTerminal("ö") );
12041229
str:= ReplacedString( str, "&uuml;", RecodeForCurrentTerminal("ü") );
@@ -1424,7 +1449,9 @@ BindGlobal( "LoadPackage_ReadImplementationParts",
14241449

14251450
# If the component `BannerString' is bound in `info' then we print
14261451
# this string, otherwise we print the default banner string.
1427-
if IsBound( info.BannerFunction ) then
1452+
if UserPreference( "ShortBanners" ) then
1453+
bannerstring:= DefaultPackageBannerString( info, true );
1454+
elif IsBound( info.BannerFunction ) then
14281455
bannerstring:= RecodeForCurrentTerminal(info.BannerFunction(info));
14291456
elif IsBound( info.BannerString ) then
14301457
bannerstring:= RecodeForCurrentTerminal(info.BannerString);

0 commit comments

Comments
 (0)