Skip to content

Commit

Permalink
Add user preference "ShortBanners"
Browse files Browse the repository at this point in the history
If this option is set to <K>true</K>, only the first line of each package
banner (including the name, version and description of the package) is
printed for packages using the default banner.
  • Loading branch information
zickgraf committed Mar 13, 2023
1 parent 4e07232 commit 1aec53e
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 59 deletions.
19 changes: 19 additions & 0 deletions doc/ref/user_pref_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,25 @@ Admissible values:

<P/>

Default: <K>false</K>.
</Item>
<Mark>
<Index Key='ShortBanners'><C>ShortBanners</C></Index>
<C>ShortBanners</C>
</Mark>
<Item>
If this option is set to <K>true</K>, only the first line of each package
banner (including the name, version and description of the package) is
displayed.

<P/>

Admissible values:
<K>true</K>,
<K>false</K>.

<P/>

Default: <K>false</K>.
</Item>
<Mark>
Expand Down
5 changes: 4 additions & 1 deletion lib/package.gd
Original file line number Diff line number Diff line change
Expand Up @@ -532,12 +532,15 @@ DeclareGlobalFunction( "IsPackageMarkedForLoading" );
#F DefaultPackageBannerString( <inforec> )
##
## <ManSection>
## <Func Name="DefaultPackageBannerString" Arg='inforec'/>
## <Func Name="DefaultPackageBannerString" Arg='inforec[, useShortBanner]'/>
##
## <Description>
## For a record <A>inforec</A> as stored in the <F>PackageInfo.g</F> file
## of a &GAP; package,
## this function returns a string denoting a banner for the package.
## If the optional argument <A>useShortBanner</A> is set to <K>true</K>,
## only the first line of the default banner (including the name, version and
## description of the package) is returned.
## </Description>
## </ManSection>
##
Expand Down
143 changes: 85 additions & 58 deletions lib/package.gi
Original file line number Diff line number Diff line change
Expand Up @@ -1099,9 +1099,31 @@ InstallGlobalFunction( IsPackageMarkedForLoading, function( name, version )
##
#F DefaultPackageBannerString( <inforec> )
##
InstallGlobalFunction( DefaultPackageBannerString, function( inforec )

DeclareUserPreference( rec(
name:= "ShortBanners",
description:= [
"If this option is set to <K>true</K>, only the first line of each \
package banner (including the name, version and description of the package) \
is printed for packages using the default banner."
],
default:= false,
values:= [ true, false ],
multi:= false,
) );

InstallGlobalFunction( DefaultPackageBannerString,
function( inforec, useShortBanner... )
local len, sep, i, str, authors, maintainers, contributors, printPersons;

if Length( useShortBanner ) = 0 then
useShortBanner := false;
elif Length( useShortBanner ) = 1 then
useShortBanner := useShortBanner[1];
else
Error( "DefaultPackageBannerString must be called with at most two arguments" );
fi;

# Start with a row of `-' signs.
len:= SizeScreen()[1] - 3;
if GAPInfo.TermEncoding = "UTF-8" then
Expand Down Expand Up @@ -1136,69 +1158,73 @@ InstallGlobalFunction( DefaultPackageBannerString, function( inforec )
fi;
Add( str, '\n' );

# Add info about the authors and/or maintainers
printPersons := function( role, persons )
local fill, person;
fill:= ListWithIdenticalEntries( Length(role), ' ' );
Append( str, role );
for i in [ 1 .. Length( persons ) ] do
person:= persons[i];
Append( str, person.FirstNames );
Append( str, " " );
Append( str, person.LastName );
if IsBound( person.WWWHome ) then
Append( str, Concatenation( " (", person.WWWHome, ")" ) );
elif IsBound( person.Email ) then
Append( str, Concatenation( " (", person.Email, ")" ) );
fi;
if i = Length( persons ) then
Append( str, ".\n" );
elif i = Length( persons )-1 then
if i = 1 then
Append( str, " and\n" );
else
Append( str, ", and\n" );
if not useShortBanner then
# Add info about the authors and/or maintainers
printPersons := function( role, persons )
local fill, person;
fill:= ListWithIdenticalEntries( Length(role), ' ' );
Append( str, role );
for i in [ 1 .. Length( persons ) ] do
person:= persons[i];
Append( str, person.FirstNames );
Append( str, " " );
Append( str, person.LastName );
if IsBound( person.WWWHome ) then
Append( str, Concatenation( " (", person.WWWHome, ")" ) );
elif IsBound( person.Email ) then
Append( str, Concatenation( " (", person.Email, ")" ) );
fi;
if i = Length( persons ) then
Append( str, ".\n" );
elif i = Length( persons )-1 then
if i = 1 then
Append( str, " and\n" );
else
Append( str, ", and\n" );
fi;
Append( str, fill );
else
Append( str, ",\n" );
Append( str, fill );
fi;
od;
end;
if IsBound( inforec.Persons ) then
authors:= Filtered( inforec.Persons, x -> x.IsAuthor );
if not IsEmpty( authors ) then
printPersons( "by ", authors );
fi;
contributors:= Filtered( inforec.Persons, x -> not x.IsAuthor and not x.IsMaintainer );
if not IsEmpty( contributors ) then
Append( str, "with contributions by:\n");
printPersons( " ", contributors );
fi;
maintainers:= Filtered( inforec.Persons, x -> x.IsMaintainer );
if not IsEmpty( maintainers ) and authors <> maintainers then
Append( str, "maintained by:\n");
printPersons( " ", maintainers );
fi;
Append( str, fill );
else
Append( str, ",\n" );
Append( str, fill );
fi;
od;
end;
if IsBound( inforec.Persons ) then
authors:= Filtered( inforec.Persons, x -> x.IsAuthor );
if not IsEmpty( authors ) then
printPersons( "by ", authors );
fi;
contributors:= Filtered( inforec.Persons, x -> not x.IsAuthor and not x.IsMaintainer );
if not IsEmpty( contributors ) then
Append( str, "with contributions by:\n");
printPersons( " ", contributors );
fi;
maintainers:= Filtered( inforec.Persons, x -> x.IsMaintainer );
if not IsEmpty( maintainers ) and authors <> maintainers then
Append( str, "maintained by:\n");
printPersons( " ", maintainers );
fi;
fi;

# Add info about the home page of the package.
if IsBound( inforec.PackageWWWHome ) then
Append( str, "Homepage: " );
Append( str, inforec.PackageWWWHome );
Append( str, "\n" );
fi;
# Add info about the home page of the package.
if IsBound( inforec.PackageWWWHome ) then
Append( str, "Homepage: " );
Append( str, inforec.PackageWWWHome );
Append( str, "\n" );
fi;

# Add info about the issue tracker of the package.
if IsBound( inforec.IssueTrackerURL ) then
Append( str, "Report issues at " );
Append( str, inforec.IssueTrackerURL );
Append( str, "\n" );
fi;

# Add info about the issue tracker of the package.
if IsBound( inforec.IssueTrackerURL ) then
Append( str, "Report issues at " );
Append( str, inforec.IssueTrackerURL );
Append( str, "\n" );
str := Concatenation(sep, str, sep);
fi;

# temporary hack, in some package names with umlauts are in HTML encoding
str := Concatenation(sep, RecodeForCurrentTerminal(str), sep);
str := RecodeForCurrentTerminal(str);
str:= ReplacedString( str, "&auml;", RecodeForCurrentTerminal("ä") );
str:= ReplacedString( str, "&ouml;", RecodeForCurrentTerminal("ö") );
str:= ReplacedString( str, "&uuml;", RecodeForCurrentTerminal("ü") );
Expand Down Expand Up @@ -1429,7 +1455,8 @@ BindGlobal( "LoadPackage_ReadImplementationParts",
elif IsBound( info.BannerString ) then
bannerstring:= RecodeForCurrentTerminal(info.BannerString);
else
bannerstring:= DefaultPackageBannerString( info );
bannerstring:= DefaultPackageBannerString( info,
UserPreference( "ShortBanners" ) );
fi;

# Suppress output formatting to avoid troubles with umlauts,
Expand Down

0 comments on commit 1aec53e

Please sign in to comment.