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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151 | -----------------------------------------------------------------------
-- util-commands-consoles-text -- Text console interface
-- Copyright (C) 2014, 2015, 2017, 2018 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
package body Util.Commands.Consoles.Text is
-- ------------------------------
-- Report an error message.
-- ------------------------------
overriding
procedure Error (Console : in out Console_Type;
Message : in String) is
pragma Unreferenced (Console);
begin
Ada.Text_IO.Put_Line (Message);
end Error;
-- ------------------------------
-- Report a notice message.
-- ------------------------------
overriding
procedure Notice (Console : in out Console_Type;
Kind : in Notice_Type;
Message : in String) is
pragma Unreferenced (Console, Kind);
begin
Ada.Text_IO.Put_Line (Message);
end Notice;
-- ------------------------------
-- Print the field value for the given field.
-- ------------------------------
overriding
procedure Print_Field (Console : in out Console_Type;
Field : in Field_Type;
Value : in String;
Justify : in Justify_Type := J_LEFT) is
use type Ada.Text_IO.Count;
Pos : constant Ada.Text_IO.Count := Ada.Text_IO.Count (Console.Cols (Field));
Size : constant Natural := Console.Sizes (Field);
Start : Natural := Value'First;
Last : constant Natural := Value'Last;
Pad : Natural := 0;
begin
case Justify is
when J_LEFT =>
if Value'Length > Size and Size > 0 then
Start := Last - Size + 1;
end if;
when J_RIGHT =>
if Value'Length < Size then
Pad := Size - Value'Length - 1;
else
Start := Last - Size + 1;
end if;
when J_CENTER =>
if Value'Length < Size then
Pad := (Size - Value'Length) / 2;
else
Start := Last - Size + 1;
end if;
when J_RIGHT_NO_FILL =>
if Value'Length >= Size then
Start := Last - Size + 1;
end if;
end case;
if Pad > 0 then
Ada.Text_IO.Set_Col (Pos + Ada.Text_IO.Count (Pad));
elsif Pos > 1 then
Ada.Text_IO.Set_Col (Pos);
end if;
Ada.Text_IO.Put (Value (Start .. Last));
end Print_Field;
-- ------------------------------
-- Print the title for the given field.
-- ------------------------------
overriding
procedure Print_Title (Console : in out Console_Type;
Field : in Field_Type;
Title : in String) is
use type Ada.Text_IO.Count;
Pos : constant Ada.Text_IO.Count := Ada.Text_IO.Count (Console.Cols (Field));
begin
if Pos > 1 then
Ada.Text_IO.Set_Col (Pos);
end if;
Ada.Text_IO.Put (Title);
end Print_Title;
-- ------------------------------
-- Start a new title in a report.
-- ------------------------------
overriding
procedure Start_Title (Console : in out Console_Type) is
begin
Console.Field_Count := 0;
Console.Sizes := (others => 0);
Console.Cols := (others => 1);
end Start_Title;
-- ------------------------------
-- Finish a new title in a report.
-- ------------------------------
procedure End_Title (Console : in out Console_Type) is
pragma Unreferenced (Console);
begin
Ada.Text_IO.New_Line;
end End_Title;
-- ------------------------------
-- Start a new row in a report.
-- ------------------------------
overriding
procedure Start_Row (Console : in out Console_Type) is
pragma Unreferenced (Console);
begin
null;
end Start_Row;
-- ------------------------------
-- Finish a new row in a report.
-- ------------------------------
overriding
procedure End_Row (Console : in out Console_Type) is
pragma Unreferenced (Console);
begin
Ada.Text_IO.New_Line;
end End_Row;
end Util.Commands.Consoles.Text;
|