aboutsummaryrefslogtreecommitdiff
path: root/Ada95/samples/ncurses2-demo_panels.adb
blob: aa6ca369f5b20add7e269e06b20a5c5af961a9d0 (plain) (blame)
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
------------------------------------------------------------------------------
--                                                                          --
--                       GNAT ncurses Binding Samples                       --
--                                                                          --
--                                 ncurses                                  --
--                                                                          --
--                                 B O D Y                                  --
--                                                                          --
------------------------------------------------------------------------------
-- Copyright 2018,2020 Thomas E. Dickey                                     --
-- Copyright 2000-2008,2011 Free Software Foundation, Inc.                  --
--                                                                          --
-- Permission is hereby granted, free of charge, to any person obtaining a  --
-- copy of this software and associated documentation files (the            --
-- "Software"), to deal in the Software without restriction, including      --
-- without limitation the rights to use, copy, modify, merge, publish,      --
-- distribute, distribute with modifications, sublicense, and/or sell       --
-- copies of the Software, and to permit persons to whom the Software is    --
-- furnished to do so, subject to the following conditions:                 --
--                                                                          --
-- The above copyright notice and this permission notice shall be included  --
-- in all copies or substantial portions of the Software.                   --
--                                                                          --
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  --
-- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               --
-- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   --
-- IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   --
-- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    --
-- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    --
-- THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               --
--                                                                          --
-- Except as contained in this notice, the name(s) of the above copyright   --
-- holders shall not be used in advertising or otherwise to promote the     --
-- sale, use or other dealings in this Software without prior written       --
-- authorization.                                                           --
------------------------------------------------------------------------------
--  Author: Eugene V. Melaragno <aldomel@ix.netcom.com> 2000
--  Version Control
--  $Revision: 1.9 $
--  $Date: 2020/02/02 23:34:34 $
--  Binding Version 01.00
------------------------------------------------------------------------------
with ncurses2.util; use ncurses2.util;
with Terminal_Interface.Curses; use Terminal_Interface.Curses;
with Terminal_Interface.Curses.Panels; use Terminal_Interface.Curses.Panels;
with Terminal_Interface.Curses.Panels.User_Data;

with ncurses2.genericPuts;

procedure ncurses2.demo_panels (nap_mseci : Integer) is

   function  mkpanel (color : Color_Number;
                      rows  : Line_Count;
                      cols  : Column_Count;
                      tly   : Line_Position;
                      tlx   : Column_Position) return Panel;
   procedure rmpanel (pan : in out Panel);
   procedure pflush;
   procedure wait_a_while (msec : Integer);
   procedure saywhat (text : String);
   procedure fill_panel (pan : Panel);

   nap_msec : Integer := nap_mseci;

   function mkpanel (color : Color_Number;
                     rows  : Line_Count;
                     cols  : Column_Count;
                     tly   : Line_Position;
                     tlx   : Column_Position) return Panel is
      win : Window;
      pan : Panel := Null_Panel;
   begin
      win := New_Window (rows, cols, tly, tlx);
      if Null_Window /= win then
         pan := New_Panel (win);
         if pan = Null_Panel then
            Delete (win);
         elsif Has_Colors then
            declare
               fg, bg : Color_Number;
            begin
               if color = Blue then
                  fg := White;
               else
                  fg := Black;
               end if;
               bg := color;
               Init_Pair (Color_Pair (color), fg, bg);
               Set_Background (win, (Ch => ' ',
                                     Attr => Normal_Video,
                                     Color => Color_Pair (color)));
            end;
         else
            Set_Background (win, (Ch => ' ',
                                  Attr => (Bold_Character => True,
                                           others => False),
                                  Color => Color_Pair (color)));
         end if;
      end if;
      return pan;
   end mkpanel;

   procedure rmpanel (pan : in out Panel) is
      win : Window := Panel_Window (pan);
   begin
      Delete (pan);
      Delete (win);
   end rmpanel;

   procedure pflush is
   begin
      Update_Panels;
      Update_Screen;
   end pflush;

   procedure wait_a_while (msec : Integer) is
   begin
      --  The C version had some #ifdef blocks here
      if msec = 1 then
         Getchar;
      else
         Nap_Milli_Seconds (msec);
      end if;
   end wait_a_while;

   procedure saywhat (text : String) is
   begin
      Move_Cursor (Line => Lines - 1, Column => 0);
      Clear_To_End_Of_Line;
      Add (Str => text);
   end saywhat;

   --  from sample-curses_demo.adb
   type User_Data is new String (1 .. 2);
   type User_Data_Access is access all User_Data;
   package PUD is new Panels.User_Data (User_Data, User_Data_Access);

   use PUD;

   procedure fill_panel (pan : Panel) is
      win : constant Window := Panel_Window (pan);
      num : constant Character := Get_User_Data (pan).all (2);
      tmp6 : String (1 .. 6) := "-panx-";
      maxy : Line_Count;
      maxx : Column_Count;

   begin
      Move_Cursor (win, 1, 1);
      tmp6 (5) := num;
      Add (win, Str => tmp6);
      Clear_To_End_Of_Line (win);
      Box (win);
      Get_Size (win, maxy, maxx);
      for y in 2 .. maxy - 3 loop
         for x in 1 .. maxx - 3 loop
            Move_Cursor (win, y, x);
            Add (win, num);
         end loop;
      end loop;
   exception
   when Curses_Exception => null;
   end fill_panel;

   modstr : constant array (0 .. 5) of String (1 .. 5) :=
     ("test ",
      "TEST ",
      "(**) ",
      "*()* ",
      "<--> ",
      "LAST "
      );

   package p is new ncurses2.genericPuts (1024);
   use p;
   use p.BS;
   --  the C version said register int y, x;
   tmpb : BS.Bounded_String;

begin
   Refresh;

   for y in 0 .. Integer (Lines - 2) loop
      for x in 0 .. Integer (Columns - 1) loop
         myPut (tmpb, (y + x) mod 10);
         myAdd (Str => tmpb);
      end loop;
   end loop;
   for y in 0 .. 4 loop
      declare
         p1, p2, p3, p4, p5 : Panel;
         U1 : constant User_Data_Access := new User_Data'("p1");
         U2 : constant User_Data_Access := new User_Data'("p2");
         U3 : constant User_Data_Access := new User_Data'("p3");
         U4 : constant User_Data_Access := new User_Data'("p4");
         U5 : constant User_Data_Access := new User_Data'("p5");

      begin
         p1 := mkpanel (Red, Lines / 2 - 2, Columns / 8 + 1, 0, 0);
         Set_User_Data (p1, U1);
         p2 := mkpanel (Green, Lines / 2 + 1, Columns / 7, Lines / 4,
                        Columns / 10);
         Set_User_Data (p2, U2);
         p3 := mkpanel (Yellow, Lines / 4, Columns / 10, Lines / 2,
                        Columns / 9);
         Set_User_Data (p3, U3);
         p4 := mkpanel (Blue, Lines / 2 - 2, Columns / 8,  Lines / 2 - 2,
                        Columns / 3);
         Set_User_Data (p4, U4);
         p5 := mkpanel (Magenta, Lines / 2 - 2, Columns / 8,  Lines / 2,
                        Columns / 2 - 2);
         Set_User_Data (p5, U5);

         fill_panel (p1);
         fill_panel (p2);
         fill_panel (p3);
         fill_panel (p4);
         fill_panel (p5);
         Hide (p4);
         Hide (p5);
         pflush;
         saywhat ("press any key to continue");
         wait_a_while (nap_msec);

         saywhat ("h3 s1 s2 s4 s5; press any key to continue");
         Move (p1, 0, 0);
         Hide (p3);
         Show (p1);
         Show (p2);
         Show (p4);
         Show (p5);
         pflush;
         wait_a_while (nap_msec);

         saywhat ("s1; press any key to continue");
         Show (p1);
         pflush;
         wait_a_while (nap_msec);

         saywhat ("s2; press any key to continue");
         Show (p2);
         pflush;
         wait_a_while (nap_msec);

         saywhat ("m2; press any key to continue");
         Move (p2, Lines / 3 + 1, Columns / 8);
         pflush;
         wait_a_while (nap_msec);

         saywhat ("s3;");
         Show (p3);
         pflush;
         wait_a_while (nap_msec);

         saywhat ("m3; press any key to continue");
         Move (p3, Lines / 4 + 1, Columns / 15);
         pflush;
         wait_a_while (nap_msec);

         saywhat ("b3; press any key to continue");
         Bottom (p3);
         pflush;
         wait_a_while (nap_msec);

         saywhat ("s4; press any key to continue");
         Show (p4);
         pflush;
         wait_a_while (nap_msec);

         saywhat ("s5; press any key to continue");
         Show (p5);
         pflush;
         wait_a_while (nap_msec);

         saywhat ("t3; press any key to continue");
         Top (p3);
         pflush;
         wait_a_while (nap_msec);

         saywhat ("t1; press any key to continue");
         Top (p1);
         pflush;
         wait_a_while (nap_msec);

         saywhat ("t2; press any key to continue");
         Top (p2);
         pflush;
         wait_a_while (nap_msec);

         saywhat ("t3; press any key to continue");
         Top (p3);
         pflush;
         wait_a_while (nap_msec);

         saywhat ("t4; press any key to continue");
         Top (p4);
         pflush;
         wait_a_while (nap_msec);

         for itmp in  0 ..  5 loop
            declare
               w4 : constant Window := Panel_Window (p4);
               w5 : constant Window := Panel_Window (p5);
            begin

               saywhat ("m4; press any key to continue");
               Move_Cursor (w4, Lines / 8, 1);
               Add (w4, modstr (itmp));
               Move (p4, Lines / 6, Column_Position (itmp) * (Columns / 8));
               Move_Cursor (w5, Lines / 6, 1);
               Add (w5, modstr (itmp));
               pflush;
               wait_a_while (nap_msec);

               saywhat ("m5; press any key to continue");
               Move_Cursor (w4, Lines / 6, 1);
               Add (w4, modstr (itmp));
               Move (p5, Lines / 3 - 1, (Column_Position (itmp) * 10) + 6);
               Move_Cursor (w5, Lines / 8, 1);
               Add (w5, modstr (itmp));
               pflush;
               wait_a_while (nap_msec);
            end;
         end loop;

         saywhat ("m4; press any key to continue");
         Move (p4, Lines / 6, 6 * (Columns / 8));
         --  Move(p4, Lines / 6, itmp * (Columns / 8));
         pflush;
         wait_a_while (nap_msec);

         saywhat ("t5; press any key to continue");
         Top (p5);
         pflush;
         wait_a_while (nap_msec);

         saywhat ("t2; press any key to continue");
         Top (p2);
         pflush;
         wait_a_while (nap_msec);

         saywhat ("t1; press any key to continue");
         Top (p1);
         pflush;
         wait_a_while (nap_msec);

         saywhat ("d2; press any key to continue");
         rmpanel (p2);
         pflush;
         wait_a_while (nap_msec);

         saywhat ("h3; press any key to continue");
         Hide (p3);
         pflush;
         wait_a_while (nap_msec);

         saywhat ("d1; press any key to continue");
         rmpanel (p1);
         pflush;
         wait_a_while (nap_msec);

         saywhat ("d4; press any key to continue");
         rmpanel (p4);
         pflush;
         wait_a_while (nap_msec);

         saywhat ("d5; press any key to continue");
         rmpanel (p5);
         pflush;
         wait_a_while (nap_msec);
         if nap_msec = 1 then
            exit;
         else
            nap_msec := 100;
         end if;

      end;
   end loop;

   Erase;
   End_Windows;

end ncurses2.demo_panels;