printer_toolkit_0.2.0_dcd7470e/examples/src/progress.adb

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
with Ada.Command_Line;
with Ada.Strings.Fixed;
with Ada.Text_IO;
with PT.Drivers.Texts;
with PT.Drivers.Texts.GNAT_IO;
with PT.Texts;
with PT.Colors;
with PT.Charts.Barcharts;
procedure Progress is

   function Percent is new PT.Charts.Width_Range (Natural);

   package Draw_Natural_Bar is
      new PT.Charts.Barcharts (Natural, Percent => Percent);

   Screen     : constant PT.Dimension_Type := PT.Drivers.Texts.Screen_Dimension;
   Driver     : PT.Drivers.Texts.Printer_Type := PT.Drivers.Texts.Create (Screen);
   Printer    : PT.Texts.Printer_Type := PT.Texts.Create (Driver);
   White      : constant PT.Style_Type := Driver.Create_Style (PT.Colors.White);
   Green      : constant PT.Style_Type := Driver.Create_Style (PT.Colors.Green);
   Red        : constant PT.Style_Type := Driver.Create_Style (PT.Colors.Red);
   Label      : PT.Texts.Field_Type;
   Count1     : PT.Texts.Field_Type;
   Count2     : PT.Texts.Field_Type;
   Progress   : PT.Texts.Field_Type;
   Count      : constant Natural := Ada.Command_Line.Argument_Count;
begin
   if Count = 0 then
      Ada.Text_IO.Put_Line ("Usage: progress {label:value:value} ...");
      return;
   end if;
   Driver.Set_Flush (PT.Drivers.Texts.GNAT_IO.Flush'Access);
   Driver.Set_Fill (Red, PT.Drivers.Texts.F_FULL);
   Driver.Set_Fill (Green, PT.Drivers.Texts.F_FULL);
   Printer.Create_Field (Label, White, 20.0);
   Printer.Create_Field (Count1, Green, 10.0);
   Printer.Create_Field (Count2, Green, 10.0);
   Printer.Create_Field (Progress, Red, 60.0);

   for I in 1 .. Count loop
      declare
         Arg : constant String := Ada.Command_Line.Argument (I);
         Sep1, Sep2 : Natural;
         Val1, Val2 : Natural;
      begin
         Sep1 := Ada.Strings.Fixed.Index (Arg, ":");
         Sep2 := Ada.Strings.Fixed.Index (Arg, ":", Sep1 + 1);
         Val1 := Natural'Value (Arg (Sep1 + 1 .. Sep2 - 1));
         Val2 := Natural'Value (Arg (Sep2 + 1 .. Arg'Last));
         Printer.Put (Label, Arg (Arg'First .. Sep1 - 1));
         Printer.Put_Int (Count1, Val1);
         Printer.Put_Int (Count2, Val2);
         Draw_Natural_Bar.Draw_Progress (Printer, Printer.Get_Box (Progress),
                                         Val1, 0, Val1 + Val2, Red, Green);
         Printer.New_Line;

      exception
         when others =>
            null;
      end;
   end loop;
end Progress;