Table justification
This commit is contained in:
+32
-4
@@ -1,4 +1,6 @@
|
|||||||
with Ada.Containers;
|
with Ada.Containers;
|
||||||
|
with Ada.Strings.Fixed;
|
||||||
|
|
||||||
with GNAT.IO;
|
with GNAT.IO;
|
||||||
|
|
||||||
package body Table_IO is
|
package body Table_IO is
|
||||||
@@ -36,17 +38,43 @@ package body Table_IO is
|
|||||||
T.Rows.Append (String_Vectors.Empty_Vector);
|
T.Rows.Append (String_Vectors.Empty_Vector);
|
||||||
end New_Row;
|
end New_Row;
|
||||||
|
|
||||||
|
----------------
|
||||||
|
-- Put_Padded --
|
||||||
|
----------------
|
||||||
|
|
||||||
|
procedure Put_Padded (T : Table;
|
||||||
|
Col : Positive;
|
||||||
|
Text : String;
|
||||||
|
Align : Ada.Strings.Alignment)
|
||||||
|
is
|
||||||
|
Field : String (1 .. T.Max_Widths (Col));
|
||||||
|
begin
|
||||||
|
Ada.Strings.Fixed.Move (Text,
|
||||||
|
Field,
|
||||||
|
Drop => Ada.Strings.Error,
|
||||||
|
Justify => Align);
|
||||||
|
GNAT.IO.Put (Field);
|
||||||
|
end Put_Padded;
|
||||||
|
|
||||||
-----------
|
-----------
|
||||||
-- Print --
|
-- Print --
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
procedure Print (T : Table; Separator : String := " ") is
|
procedure Print (T : Table;
|
||||||
use Gnat.IO;
|
Separator : String := " ";
|
||||||
|
Align : Alignments := (1 .. 0 => <>))
|
||||||
|
is
|
||||||
|
use GNAT.IO;
|
||||||
begin
|
begin
|
||||||
for Row of T.Rows loop
|
for Row of T.Rows loop
|
||||||
for I in 1 .. Natural (Row.Length) loop
|
for I in 1 .. Natural (Row.Length) loop
|
||||||
Put (Row (I));
|
Put_Padded (T,
|
||||||
Put (String'(1 .. T.Max_Widths (I) - String'(Row (I))'Length => ' '));
|
I,
|
||||||
|
Row (I),
|
||||||
|
(if Align'Length >= I
|
||||||
|
then Align (I)
|
||||||
|
else Ada.Strings.Left));
|
||||||
|
|
||||||
if I < Natural (Row.Length) then
|
if I < Natural (Row.Length) then
|
||||||
Put (Separator);
|
Put (Separator);
|
||||||
else
|
else
|
||||||
|
|||||||
+7
-1
@@ -1,6 +1,8 @@
|
|||||||
with Ada.Containers.Indefinite_Vectors;
|
with Ada.Containers.Indefinite_Vectors;
|
||||||
with Ada.Containers.Vectors;
|
with Ada.Containers.Vectors;
|
||||||
|
|
||||||
|
with Ada.Strings;
|
||||||
|
|
||||||
package Table_IO with Preelaborate is
|
package Table_IO with Preelaborate is
|
||||||
|
|
||||||
type Table is tagged private;
|
type Table is tagged private;
|
||||||
@@ -9,7 +11,11 @@ package Table_IO with Preelaborate is
|
|||||||
|
|
||||||
procedure New_Row (T : in out Table);
|
procedure New_Row (T : in out Table);
|
||||||
|
|
||||||
procedure Print (T : Table; Separator : String := " ");
|
type Alignments is array (Positive range <>) of Ada.Strings.Alignment;
|
||||||
|
|
||||||
|
procedure Print (T : Table;
|
||||||
|
Separator : String := " ";
|
||||||
|
Align : Alignments := (1 .. 0 => <>));
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user