1--  This file is covered by the Internet Software Consortium (ISC) License
2--  Reference: ../License.txt
3
4with Terminal_Interface.Curses;
5
6with Definitions;  use Definitions;
7
8package Display is
9
10   package TIC renames Terminal_Interface.Curses;
11
12   subtype history_origin  is String (1 .. 45);
13   subtype history_elapsed is String (1 .. 8);
14   subtype history_action  is String (1 .. 8);
15   subtype fivelong        is String (1 .. 5);
16   type history_rec is
17      record
18         id          : builders;
19         slavid      : String (1 .. 2);
20         run_elapsed : history_elapsed;
21         action      : history_action;
22         pkg_elapsed : history_elapsed;
23         origin      : history_origin;
24         established : Boolean := False;
25      end record;
26
27   type summary_rec is
28      record
29         Initially : Natural;
30         Built     : Natural;
31         Failed    : Natural;
32         Ignored   : Natural;
33         Skipped   : Natural;
34         elapsed   : history_elapsed;
35         impulse   : Natural;
36         pkg_hour  : Natural;
37         load      : Float;
38         swap      : Float;
39      end record;
40
41   type builder_rec is
42      record
43         id        : builders;
44         shutdown  : Boolean;
45         idle      : Boolean;
46         slavid    : String (1 .. 2);
47         Elapsed   : history_elapsed;
48         LLines    : String (1 .. 7);
49         phase     : String (1 .. 15);
50         origin    : String (1 .. 37);
51      end record;
52
53   action_shutdown : constant history_action := "shutdown";
54   action_skipped  : constant history_action := "skipped ";
55   action_ignored  : constant history_action := "ignored ";
56   action_success  : constant history_action := "success ";
57   action_failure  : constant history_action := "failure ";
58
59   --  Initialize the curses screen.
60   --  Returns False if no color support (curses not used at all)
61   function launch_monitor (num_builders : builders) return Boolean;
62
63   --  The build is done, return to the console
64   procedure terminate_monitor;
65
66   --  prints the summary header
67   procedure summarize (data : summary_rec);
68
69   --  Updates the status of a builder (contained in builder_rec)
70   procedure update_builder (BR : builder_rec);
71
72   --  After all the update_builder calls, call refresh to implement
73   procedure refresh_builder_window;
74
75   --  After all the history inserts, call refresh to implement
76   procedure refresh_history_window;
77
78   --  Insert history as builder finishes (shutdown, success, failure);
79   procedure insert_history (HR : history_rec);
80
81   --  Clears and redraws the static portion of builder and summary zones
82   --  (Realized when the regular zones are refreshed)
83   procedure set_full_redraw_next_update;
84
85   --  Expose helper function that formats float values for www report
86   function fmtpc (f : Float; percent : Boolean) return fivelong;
87
88   --  Expose helper function that formats load values for www report
89   function fmtload (f : Float) return fivelong;
90
91private
92
93   type palette_rec is
94      record
95         palette   : TIC.Color_Pair;
96         attribute : TIC.Character_Attribute_Set;
97      end record;
98
99   type builder_palette is array (builders) of palette_rec;
100   type cyclic_range is range 1 .. 50;
101   type dim_history is array (cyclic_range) of history_rec;
102   type zones is (summary, builder, action);
103   subtype appline is TIC.Attributed_String (1 .. 79);
104
105   history       : dim_history;
106   history_arrow : cyclic_range := cyclic_range'Last;
107   builders_used : Integer;
108
109   app_width     : constant TIC.Column_Count := 80;
110   historyheight : TIC.Line_Position;
111   zone_summary  : TIC.Window;
112   zone_builders : TIC.Window;
113   zone_actions  : TIC.Window;
114   viewheight    : TIC.Line_Count;
115
116   c_standard    : TIC.Color_Pair;
117   c_slave       : builder_palette;
118   c_success     : TIC.Color_Pair;
119   c_failure     : TIC.Color_Pair;
120   c_ignored     : TIC.Color_Pair;
121   c_skipped     : TIC.Color_Pair;
122   c_sumlabel    : TIC.Color_Pair;
123   c_dashes      : TIC.Color_Pair;
124   c_tableheader : TIC.Color_Pair;
125   c_elapsed     : TIC.Color_Pair;
126   c_origin      : TIC.Color_Pair;
127   c_bldphase    : TIC.Color_Pair;
128   c_shutdown    : TIC.Color_Pair;
129   c_advisory    : TIC.Color_Pair;
130
131   cursor_vis    : TIC.Cursor_Visibility := TIC.Invisible;
132
133   normal        : constant TIC.Character_Attribute_Set :=
134                            (others => False);
135   bright        : constant TIC.Character_Attribute_Set :=
136                            (Bold_Character => True, others => False);
137   dimmed        : constant TIC.Character_Attribute_Set :=
138                            (Dim_Character => True, others => False);
139
140   function launch_summary_zone  return Boolean;
141   function launch_builders_zone return Boolean;
142   function launch_actions_zone  return Boolean;
143
144   function inc (X : TIC.Line_Position; by : Integer) return TIC.Line_Position;
145   function zone_window (zone : zones) return TIC.Window;
146   function Start_Curses_Mode return Boolean;
147   function establish_colors return Boolean;
148   function blank_line return appline;
149   function shutdown_message return appline;
150   function emphasis       (dimmed    : Boolean) return TIC.Character_Attribute_Set;
151   function custom_message (message   : String;
152                            attribute : TIC.Character_Attribute_Set;
153                            pen_color : TIC.Color_Pair) return TIC.Attributed_String;
154
155   procedure draw_static_summary_zone;
156   procedure draw_static_builders_zone;
157
158   procedure Scrawl
159     (zone        : zones;
160      information : TIC.Attributed_String;
161      at_line     : TIC.Line_Position;
162      at_column   : TIC.Column_Position := 0);
163
164   procedure Return_To_Text_Mode;
165   procedure Refresh_Zone (zone : zones);
166
167end Display;
168