Skip to content

Commit

Permalink
fix tables without headers
Browse files Browse the repository at this point in the history
  • Loading branch information
mosteo committed Sep 14, 2024
1 parent 4d48e0f commit 9a4ec0d
Show file tree
Hide file tree
Showing 11 changed files with 159 additions and 131 deletions.
2 changes: 1 addition & 1 deletion deps/aaa
2 changes: 1 addition & 1 deletion deps/ansi
Submodule ansi updated 2 files
+1 −1 alire.toml
+32 −0 src/ansiada.ads
4 changes: 3 additions & 1 deletion src/alire/alire-index-search.adb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ package body Alire.Index.Search is
Busy : Simple_Logging.Ongoing :=
Simple_Logging.Activity ("Searching");
begin
Table.Header ("NAME").Header ("DESCRIPTION");

for Crate of Alire.Index.All_Crates.all loop
if Lookup = "" or else
Contains (To_Lower_Case (+Crate.Name), Lookup) or else
Expand All @@ -37,7 +39,7 @@ package body Alire.Index.Search is
Busy.Step;
end loop;

if Found = 0 then
if Found = 0 and then not Utils.Tables.Structured_Output then
Trace.Always ("No hits");
else
Table.Print (Always, Separator => " ");
Expand Down
2 changes: 1 addition & 1 deletion src/alire/alire-solutions-diffs.adb
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ package body Alire.Solutions.Diffs is
end loop;

if Changed then
Table.Print (Level);
Table.Print (Level, Structured => False);

Warn_Toolchain_Download;
Warn_Unsatisfiable_GNAT_External;
Expand Down
8 changes: 7 additions & 1 deletion src/alire/alire-solutions.adb
Original file line number Diff line number Diff line change
Expand Up @@ -923,8 +923,14 @@ package body Alire.Solutions is
Table : Utils.Tables.Table;
begin
if This.Links.Is_Empty and then Dependency_Map'(This.Pins).Is_Empty then
Trace.Always ("There are no pins");
if Utils.Tables.Structured_Output then
Table.Print (Always);
else
Trace.Always ("There are no pins");
end if;
else
Table.Header ("Crate").Header ("Target").Header ("Origin").New_Row;

for Dep of This.Dependencies loop
if Dep.Is_Linked then
Table
Expand Down
26 changes: 18 additions & 8 deletions src/alire/alire-utils-tables.adb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ package body Alire.Utils.Tables is

overriding
procedure Header (T : in out Table; Cell : String) is
Text : constant String :=
(if Structured_Output
then AAA.Strings.To_Lower_Case (Cell)
else TTY.Emph (AAA.Strings.To_Upper_Case (Cell)));
begin
Parent (T).Header (TTY.Emph (AAA.Strings.To_Upper_Case (Cell)));
Parent (T).Header (Text);
end Header;

------------
Expand All @@ -30,10 +34,11 @@ package body Alire.Utils.Tables is
-- Print --
-----------

procedure Print (T : Table;
Level : Trace.Levels := Info;
Separator : String := " ";
Align : AAA.Table_IO.Alignments := (1 .. 0 => <>))
procedure Print (T : Table;
Level : Trace.Levels := Info;
Separator : String := " ";
Align : AAA.Table_IO.Alignments := (1 .. 0 => <>);
Structured : Boolean := Structured_Output)
is

procedure Print (Line : String) is
Expand All @@ -44,9 +49,14 @@ package body Alire.Utils.Tables is
end Print;

begin
T.Print (Separator => Separator,
Align => Align,
Put_Line => Print'Access);
if Structured then
T.Print (Structured_Output_Format,
Put_Line => Print'Access);
else
T.Print (Separator => Separator,
Align => Align,
Put_Line => Print'Access);
end if;
end Print;

end Alire.Utils.Tables;
14 changes: 8 additions & 6 deletions src/alire/alire-utils-tables.ads
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ with AAA.Table_IO;

with LML;

package Alire.Utils.Tables with Preelaborate is
package Alire.Utils.Tables is

subtype Formats is LML.Formats;

Expand All @@ -22,10 +22,12 @@ package Alire.Utils.Tables with Preelaborate is
Cell : String)
return AAA.Table_IO.Reference;

procedure Print (T : Table;
Level : Trace.Levels := Info;
Separator : String := " ";
Align : AAA.Table_IO.Alignments := (1 .. 0 => <>));
-- Hook so tables use the default output facilities of Alire
procedure Print (T : Table;
Level : Trace.Levels := Info;
Separator : String := " ";
Align : AAA.Table_IO.Alignments := (1 .. 0 => <>);
Structured : Boolean := Structured_Output);
-- Hook so tables use the default output facilities of Alire. When
-- Structured_Output is enabled, formatting information is ignored.

end Alire.Utils.Tables;
16 changes: 7 additions & 9 deletions src/alr/alr-commands-index.adb
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
with AAA.Table_IO;

with Alire.Settings.Edit;
with Alire.Index;
with Alire.Index_On_Disk.Loading;
with Alire.Index_On_Disk.Updates;
with Alire.Utils;
with Alire.Utils.Tables;

package body Alr.Commands.Index is

Expand Down Expand Up @@ -155,18 +153,18 @@ package body Alr.Commands.Index is
Index_Load.Find_All
(Alire.Settings.Edit.Indexes_Directory, Result);

Table : AAA.Table_IO.Table;
Table : Alire.Utils.Tables.Table;
Count : Natural := 0;
begin
if not Result.Success then
Reportaise_Command_Failed (Alire.Message (Result));
end if;

Table
.Append (TTY.Emph ("#"))
.Append (TTY.Emph ("NAME"))
.Append (TTY.Emph ("URL"))
.Append (TTY.Emph ("PATH"));
.Header ("#")
.Header ("NAME")
.Header ("URL")
.Header ("PATH");

if Alire.Log_Level = Alire.Trace.Debug then
Table.Append (TTY.Emph ("PRIORITY"));
Expand All @@ -187,7 +185,7 @@ package body Alr.Commands.Index is
end loop;

if Count > 0 then
Table.Print;
Table.Print (Always);
else
Trace.Info ("No index configured.");
end if;
Expand Down
12 changes: 6 additions & 6 deletions src/alr/alr-commands-search.adb
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@ package body Alr.Commands.Search is
-- End of option verification, start of search. First load the index,
-- required to look at its entries.

Tab.Append (TTY.Bold ("NAME"));
Tab.Append (TTY.Bold ("STATUS"));
Tab.Append (TTY.Bold ("VERSION"));
Tab.Append (TTY.Bold ("DESCRIPTION"));
Tab.Append (TTY.Bold ("NOTES"));
Tab.Append (TTY.Bold ("MATCHES"));
Tab.Header ("NAME");
Tab.Header ("STATUS");
Tab.Header ("VERSION");
Tab.Header ("DESCRIPTION");
Tab.Header ("NOTES");
Tab.Header ("MATCHES");

declare
Busy : Simple_Logging.Ongoing :=
Expand Down
18 changes: 9 additions & 9 deletions src/alr/alr-commands-toolchain.adb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

with AAA.Table_IO;

with Alire.Settings.Edit;
with Alire.Containers;
with Alire.Dependencies;
Expand All @@ -10,14 +8,16 @@ with Alire.Origins.Deployers;
with Alire.Releases.Containers;
with Alire.Solver;
with Alire.Toolchains;
with Alire.Utils; use Alire.Utils;
with Alire.Utils.Tables;
with Alire.Utils.TTY;
with Alire.Warnings;

with Semantic_Versioning.Extended;

package body Alr.Commands.Toolchain is

use Alire.Utils;

package Name_Sets renames Alire.Containers.Crate_Name_Sets;

--------------------
Expand Down Expand Up @@ -268,7 +268,7 @@ package body Alr.Commands.Toolchain is
pragma Unreferenced (Cmd);
use Alire;
use type Dependencies.Dependency;
Table : AAA.Table_IO.Table;
Table : Tables.Table;
begin
Alire.Toolchains.Detect_Externals;
-- Even if we have selected a non-external toolchain, in this case we
Expand All @@ -281,10 +281,10 @@ package body Alr.Commands.Toolchain is
end if;

Table
.Append (TTY.Emph ("CRATE"))
.Append (TTY.Emph ("VERSION"))
.Append (TTY.Emph ("STATUS"))
.Append (TTY.Emph ("NOTES"))
.Header ("CRATE")
.Header ("VERSION")
.Header ("STATUS")
.Header ("NOTES")
.New_Row;

for Dep of Alire.Toolchains.Available loop
Expand All @@ -311,7 +311,7 @@ package body Alr.Commands.Toolchain is
end if;
end loop;

Table.Print;
Table.Print (Always);
end List;

-------------
Expand Down
Loading

0 comments on commit 9a4ec0d

Please sign in to comment.