From 330bbfe0fe9b3175f14ab9c11eeca0c57e767915 Mon Sep 17 00:00:00 2001 From: Fabian Zickgraf Date: Mon, 5 Feb 2024 23:17:06 +0100 Subject: [PATCH] Add user preference "ShortBanners" (#5407) If this option is set to true, package banners printed during loading will only show the name, version and description of a package. --- doc/ref/gappkg.xml | 2 +- doc/ref/user_pref_list.xml | 18 +++++ lib/package.gd | 5 +- lib/package.gi | 145 +++++++++++++++++++++--------------- tst/testinstall/package.tst | 18 ++--- 5 files changed, 118 insertions(+), 70 deletions(-) diff --git a/doc/ref/gappkg.xml b/doc/ref/gappkg.xml index d0bad836f8..8c7bdebca5 100644 --- a/doc/ref/gappkg.xml +++ b/doc/ref/gappkg.xml @@ -1104,7 +1104,7 @@ it may produce the output looking like this: ShowPackageVariables("example"); ---------------------------------------------------------------- -Loading Example 3.3 (Example/Template of a GAP Package) +Loading Example 3.3 (Example/Template of a GAP Package) by Werner Nickel (http://www.mathematik.tu-darmstadt.de/~nickel), Greg Gamble (http://www.math.rwth-aachen.de/~Greg.Gamble), and Alexander Konovalov (http://www.cs.st-andrews.ac.uk/~alexk/). diff --git a/doc/ref/user_pref_list.xml b/doc/ref/user_pref_list.xml index 8cb5a08141..c03ae38f4b 100644 --- a/doc/ref/user_pref_list.xml +++ b/doc/ref/user_pref_list.xml @@ -243,6 +243,24 @@ Admissible values:

+Default: false. + + +ShortBanners +ShortBanners + + +If this option is set to true, package banners printed during loading +will only show the name, version and description of a package. + +

+ +Admissible values: +true, +false. + +

+ Default: false. diff --git a/lib/package.gd b/lib/package.gd index a0cd5217c9..178624c024 100644 --- a/lib/package.gd +++ b/lib/package.gd @@ -532,12 +532,15 @@ DeclareGlobalFunction( "IsPackageMarkedForLoading" ); #F DefaultPackageBannerString( ) ## ## -## +## ## ## ## For a record inforec as stored in the PackageInfo.g file ## of a &GAP; package, ## this function returns a string denoting a banner for the package. +## If the optional argument useShortBanner is set to true, +## only the first line of the default banner (including the name, version and +## description of the package) is returned. ## ## ## diff --git a/lib/package.gi b/lib/package.gi index 982af8d04b..c24c89cf2b 100644 --- a/lib/package.gi +++ b/lib/package.gi @@ -1099,9 +1099,30 @@ InstallGlobalFunction( IsPackageMarkedForLoading, function( name, version ) ## #F DefaultPackageBannerString( ) ## -InstallGlobalFunction( DefaultPackageBannerString, function( inforec ) + +DeclareUserPreference( rec( + name:= "ShortBanners", + description:= [ + "If this option is set to true, package banners printed during \ +loading will only show the name, version and description of a package." + ], + 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 @@ -1124,7 +1145,7 @@ InstallGlobalFunction( DefaultPackageBannerString, function( inforec ) # Add package name and version number. if IsBound( inforec.PackageName ) and IsBound( inforec.Version ) then Append( str, Concatenation( - "Loading ", inforec.PackageName, " ", inforec.Version ) ); + "Loading ", inforec.PackageName, " ", inforec.Version ) ); fi; # Add the long title. @@ -1136,69 +1157,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, "ä", RecodeForCurrentTerminal("ä") ); str:= ReplacedString( str, "ö", RecodeForCurrentTerminal("ö") ); str:= ReplacedString( str, "ü", RecodeForCurrentTerminal("ü") ); @@ -1424,7 +1449,9 @@ BindGlobal( "LoadPackage_ReadImplementationParts", # If the component `BannerString' is bound in `info' then we print # this string, otherwise we print the default banner string. - if IsBound( info.BannerFunction ) then + if UserPreference( "ShortBanners" ) then + bannerstring:= DefaultPackageBannerString( info, true ); + elif IsBound( info.BannerFunction ) then bannerstring:= RecodeForCurrentTerminal(info.BannerFunction(info)); elif IsBound( info.BannerString ) then bannerstring:= RecodeForCurrentTerminal(info.BannerString); diff --git a/tst/testinstall/package.tst b/tst/testinstall/package.tst index 8290445211..3c59fe26bf 100644 --- a/tst/testinstall/package.tst +++ b/tst/testinstall/package.tst @@ -68,7 +68,7 @@ gap> pkginfo := rec( # just one author & maintainer gap> Display(DefaultPackageBannerString(pkginfo)); ----------------------------------------------------------------------------- -Loading TestPkg 1.0 (A test package) +Loading TestPkg 1.0 (A test package) by Lord Vader (https://www.gap-system.org/~darth). Homepage: https://www.gap-system.org ----------------------------------------------------------------------------- @@ -80,7 +80,7 @@ gap> Add(pkginfo.Persons, rec( IsAuthor := false, IsMaintainer := true, > Email := "luke.skywalker@gap-system.org" )); gap> Display(DefaultPackageBannerString(pkginfo)); ----------------------------------------------------------------------------- -Loading TestPkg 1.0 (A test package) +Loading TestPkg 1.0 (A test package) by Lord Vader (https://www.gap-system.org/~darth). maintained by: Lord Vader (https://www.gap-system.org/~darth) and @@ -94,7 +94,7 @@ gap> Add(pkginfo.Persons, rec( IsAuthor := true, IsMaintainer := false, > FirstNames := "Leia", LastName := "Organa" )); gap> Display(DefaultPackageBannerString(pkginfo)); ----------------------------------------------------------------------------- -Loading TestPkg 1.0 (A test package) +Loading TestPkg 1.0 (A test package) by Lord Vader (https://www.gap-system.org/~darth) and Leia Organa. maintained by: @@ -110,7 +110,7 @@ gap> Add(pkginfo.Persons, rec( IsAuthor := false, IsMaintainer := false, > WWWHome := "https://www.gap-system.org/~yoda")); gap> Display(DefaultPackageBannerString(pkginfo)); ----------------------------------------------------------------------------- -Loading TestPkg 1.0 (A test package) +Loading TestPkg 1.0 (A test package) by Lord Vader (https://www.gap-system.org/~darth) and Leia Organa. with contributions by: @@ -126,7 +126,7 @@ Homepage: https://www.gap-system.org gap> for p in pkginfo.Persons do p.IsAuthor:=true; p.IsMaintainer:=true; od; gap> Display(DefaultPackageBannerString(pkginfo)); ----------------------------------------------------------------------------- -Loading TestPkg 1.0 (A test package) +Loading TestPkg 1.0 (A test package) by Lord Vader (https://www.gap-system.org/~darth), Luke Skywalker (luke.skywalker@gap-system.org), Leia Organa, and @@ -139,7 +139,7 @@ Homepage: https://www.gap-system.org gap> for p in pkginfo.Persons do p.IsAuthor:=true; p.IsMaintainer:=false; od; gap> Display(DefaultPackageBannerString(pkginfo)); ----------------------------------------------------------------------------- -Loading TestPkg 1.0 (A test package) +Loading TestPkg 1.0 (A test package) by Lord Vader (https://www.gap-system.org/~darth), Luke Skywalker (luke.skywalker@gap-system.org), Leia Organa, and @@ -152,7 +152,7 @@ Homepage: https://www.gap-system.org gap> for p in pkginfo.Persons do p.IsAuthor:=false; p.IsMaintainer:=true; od; gap> Display(DefaultPackageBannerString(pkginfo)); ----------------------------------------------------------------------------- -Loading TestPkg 1.0 (A test package) +Loading TestPkg 1.0 (A test package) maintained by: Lord Vader (https://www.gap-system.org/~darth), Luke Skywalker (luke.skywalker@gap-system.org), @@ -166,7 +166,7 @@ Homepage: https://www.gap-system.org gap> for p in pkginfo.Persons do p.IsAuthor:=false; p.IsMaintainer:=false; od; gap> Display(DefaultPackageBannerString(pkginfo)); ----------------------------------------------------------------------------- -Loading TestPkg 1.0 (A test package) +Loading TestPkg 1.0 (A test package) with contributions by: Lord Vader (https://www.gap-system.org/~darth), Luke Skywalker (luke.skywalker@gap-system.org), @@ -180,7 +180,7 @@ Homepage: https://www.gap-system.org gap> pkginfo.IssueTrackerURL := "https://issues.gap-system.org/";; gap> Display(DefaultPackageBannerString(pkginfo)); ----------------------------------------------------------------------------- -Loading TestPkg 1.0 (A test package) +Loading TestPkg 1.0 (A test package) with contributions by: Lord Vader (https://www.gap-system.org/~darth), Luke Skywalker (luke.skywalker@gap-system.org),