1 ------------------------------------------------------------------------------
3 -- GNAT ncurses Binding Samples --
9 ------------------------------------------------------------------------------
10 -- Copyright 2020 Thomas E. Dickey --
11 -- Copyright 1998-2008,2011 Free Software Foundation, Inc. --
13 -- Permission is hereby granted, free of charge, to any person obtaining a --
14 -- copy of this software and associated documentation files (the --
15 -- "Software"), to deal in the Software without restriction, including --
16 -- without limitation the rights to use, copy, modify, merge, publish, --
17 -- distribute, distribute with modifications, sublicense, and/or sell --
18 -- copies of the Software, and to permit persons to whom the Software is --
19 -- furnished to do so, subject to the following conditions: --
21 -- The above copyright notice and this permission notice shall be included --
22 -- in all copies or substantial portions of the Software. --
24 -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS --
25 -- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF --
26 -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. --
27 -- IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, --
28 -- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR --
29 -- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR --
30 -- THE USE OR OTHER DEALINGS IN THE SOFTWARE. --
32 -- Except as contained in this notice, the name(s) of the above copyright --
33 -- holders shall not be used in advertising or otherwise to promote the --
34 -- sale, use or other dealings in this Software without prior written --
36 ------------------------------------------------------------------------------
37 -- Author: Juergen Pfeifer, 1996
40 -- $Date: 2020/02/02 23:34:34 $
41 -- Binding Version 01.00
42 ------------------------------------------------------------------------------
45 with Ada.Exceptions; use Ada.Exceptions;
47 with Terminal_Interface.Curses; use Terminal_Interface.Curses;
48 with Terminal_Interface.Curses.Panels; use Terminal_Interface.Curses.Panels;
49 with Terminal_Interface.Curses.Menus; use Terminal_Interface.Curses.Menus;
50 with Terminal_Interface.Curses.Menus.Menu_User_Data;
51 with Terminal_Interface.Curses.Menus.Item_User_Data;
53 with Sample.Manifest; use Sample.Manifest;
54 with Sample.Function_Key_Setting; use Sample.Function_Key_Setting;
55 with Sample.Keyboard_Handler; use Sample.Keyboard_Handler;
56 with Sample.Header_Handler; use Sample.Header_Handler;
57 with Sample.Explanation; use Sample.Explanation;
59 with Sample.Menu_Demo.Handler;
60 with Sample.Curses_Demo;
61 with Sample.Form_Demo;
62 with Sample.Menu_Demo;
63 with Sample.Text_IO_Demo;
67 package body Sample is
73 type User_Access is access User_Data;
76 Terminal_Interface.Curses.Menus.Menu_User_Data
77 (User_Data, User_Access);
80 Terminal_Interface.Curses.Menus.Item_User_Data
81 (User_Data, User_Access);
87 function My_Driver (M : Menu;
89 Pan : Panel) return Boolean;
91 package Mh is new Sample.Menu_Demo.Handler (My_Driver);
93 I : Item_Array_Access := new Item_Array'
94 (New_Item ("Curses Core Demo"),
95 New_Item ("Menu Demo"),
96 New_Item ("Form Demo"),
97 New_Item ("Text IO Demo"),
100 M : Menu := New_Menu (I);
102 D1, D2 : User_Access;
103 I1, I2 : User_Access;
105 function My_Driver (M : Menu;
107 Pan : Panel) return Boolean
109 Idx : constant Positive := Get_Index (Current (M));
111 if K in User_Key_Code'Range then
114 elsif K = SELECT_ITEM then
120 when 1 => Sample.Curses_Demo.Demo;
121 when 2 => Sample.Menu_Demo.Demo;
122 when 3 => Sample.Form_Demo.Demo;
123 when 4 => Sample.Text_IO_Demo.Demo;
139 if (1 + Item_Count (M)) /= I'Length then
140 raise Constraint_Error;
143 D1 := new User_Data'(Data => 4711);
144 Ud.Set_User_Data (M, D1);
146 I1 := new User_Data'(Data => 1174);
147 Id.Set_User_Data (I.all (1), I1);
149 Set_Spacing (Men => M, Row => 2);
154 Mh.Drive_Me (M, " Demo ");
156 Ud.Get_User_Data (M, D2);
157 pragma Assert (D1 = D2);
158 pragma Assert (D1.Data = D2.Data);
160 Id.Get_User_Data (I.all (1), I2);
161 pragma Assert (I1 = I2);
162 pragma Assert (I1.Data = I2.Data);
169 Initialize (PC_Style_With_Index);
176 Init_Pair (Pair => Default_Colors, Fore => Black, Back => White);
177 Init_Pair (Pair => Menu_Back_Color, Fore => Black, Back => Cyan);
178 Init_Pair (Pair => Menu_Fore_Color, Fore => Red, Back => Cyan);
179 Init_Pair (Pair => Menu_Grey_Color, Fore => White, Back => Cyan);
180 Init_Pair (Pair => Notepad_Color, Fore => Black, Back => Yellow);
181 Init_Pair (Pair => Help_Color, Fore => Blue, Back => Cyan);
182 Init_Pair (Pair => Form_Back_Color, Fore => Black, Back => Cyan);
183 Init_Pair (Pair => Form_Fore_Color, Fore => Red, Back => Cyan);
184 Init_Pair (Pair => Header_Color, Fore => Black, Back => Green);
186 Set_Background (Ch => (Color => Default_Colors,
187 Attr => Normal_Video,
189 Set_Character_Attributes (Attr => Normal_Video,
190 Color => Default_Colors);
193 Set_Soft_Label_Key_Attributes (Color => Header_Color);
194 -- This propagates the attributes to the label window
195 Refresh_Soft_Label_Keys;
198 Init_Keyboard_Handler;
200 Set_Echo_Mode (False);
205 -- Initialize the Function Key Environment
206 -- We have some fixed key throughout this sample
212 when Event : others =>
213 Terminal_Interface.Curses.End_Windows;
214 Text_IO.Put ("Exception: ");
215 Text_IO.Put (Exception_Name (Event));
217 GNAT.OS_Lib.OS_Exit (1);