1 ------------------------------------------------------------------------------
3 -- GNAT ncurses Binding Samples --
11 -- The ncurses Ada95 binding is copyrighted 1996 by --
12 -- Juergen Pfeifer, Email: Juergen.Pfeifer@T-Online.de --
14 -- Permission is hereby granted to reproduce and distribute this --
15 -- binding by any means and for any fee, whether alone or as part --
16 -- of a larger distribution, in source or in binary form, PROVIDED --
17 -- this notice is included with any such distribution, and is not --
18 -- removed from any of its header files. Mention of ncurses and the --
19 -- author of this binding in any applications linked with it is --
20 -- highly appreciated. --
22 -- This binding comes AS IS with no warranty, implied or expressed. --
23 ------------------------------------------------------------------------------
26 ------------------------------------------------------------------------------
29 with Ada.Characters.Latin_1; use Ada.Characters.Latin_1;
30 with Ada.Exceptions; use Ada.Exceptions;
32 with Terminal_Interface.Curses; use Terminal_Interface.Curses;
33 with Terminal_Interface.Curses.Panels; use Terminal_Interface.Curses.Panels;
34 with Terminal_Interface.Curses.Menus; use Terminal_Interface.Curses.Menus;
35 with Terminal_Interface.Curses.Menus.Menu_User_Data;
36 with Terminal_Interface.Curses.Menus.Item_User_Data;
38 with Sample.Manifest; use Sample.Manifest;
39 with Sample.Helpers; use Sample.Helpers;
40 with Sample.Function_Key_Setting; use Sample.Function_Key_Setting;
41 with Sample.Keyboard_Handler; use Sample.Keyboard_Handler;
42 with Sample.Header_Handler; use Sample.Header_Handler;
43 with Sample.Explanation; use Sample.Explanation;
45 with Sample.Menu_Demo.Handler;
46 with Sample.Curses_Demo;
47 with Sample.Form_Demo;
48 with Sample.Menu_Demo;
49 with Sample.Text_IO_Demo;
53 package body Sample is
59 type User_Access is access User_Data;
62 Terminal_Interface.Curses.Menus.Menu_User_Data
63 (User_Data, User_Access);
66 Terminal_Interface.Curses.Menus.Item_User_Data
67 (User_Data, User_Access);
73 function My_Driver (M : Menu;
75 Pan : Panel) return Boolean;
77 package Mh is new Sample.Menu_Demo.Handler (My_Driver);
79 I : constant Item_Array (1 .. 4) :=
80 (New_Item ("Curses Core Demo"),
81 New_Item ("Menu Demo"),
82 New_Item ("Form Demo"),
83 New_Item ("Text IO Demo"));
85 M : Menu := New_Menu (I);
90 function My_Driver (M : Menu;
92 Pan : Panel) return Boolean
94 Idx : constant Positive := Get_Index (Current (M));
96 if K in User_Key_Code'Range then
99 elsif K = SELECT_ITEM then
100 if Idx in 1 .. 4 then
105 when 1 => Sample.Curses_Demo.Demo;
106 when 2 => Sample.Menu_Demo.Demo;
107 when 3 => Sample.Form_Demo.Demo;
108 when 4 => Sample.Text_IO_Demo.Demo;
111 if Idx in 1 .. 4 then
124 if Item_Count (M) /= I'Length then
125 raise Constraint_Error;
128 D1 := new User_Data'(Data => 4711);
129 Ud.Set_User_Data (M, D1);
131 I1 := new User_Data'(Data => 1174);
132 Id.Set_User_Data (I (1), I1);
134 Set_Spacing (Men => M, Row => 2);
139 Mh.Drive_Me (M, " Demo ");
141 Ud.Get_User_Data (M, D2);
142 pragma Assert (D1 = D2);
143 pragma Assert (D1.Data = D2.Data);
145 Id.Get_User_Data (I (1), I2);
146 pragma Assert (I1 = I2);
147 pragma Assert (I1.Data = I2.Data);
153 Initialize (PC_Style_With_Index);
160 Init_Pair (Pair => Default_Colors, Fore => Black, Back => White);
161 Init_Pair (Pair => Menu_Back_Color, Fore => Black, Back => Cyan);
162 Init_Pair (Pair => Menu_Fore_Color, Fore => Red, Back => Cyan);
163 Init_Pair (Pair => Menu_Grey_Color, Fore => White, Back => Cyan);
164 Init_Pair (Pair => Notepad_Color, Fore => Black, Back => Yellow);
165 Init_Pair (Pair => Help_Color, Fore => Blue, Back => Cyan);
166 Init_Pair (Pair => Form_Back_Color, Fore => Black, Back => Cyan);
167 Init_Pair (Pair => Form_Fore_Color, Fore => Red, Back => Cyan);
168 Init_Pair (Pair => Header_Color, Fore => Black, Back => Green);
170 Set_Background (Ch => (Color => Default_Colors,
171 Attr => Normal_Video,
173 Set_Character_Attributes (Attr => Normal_Video,
174 Color => Default_Colors);
177 Set_Soft_Label_Key_Attributes (Color => Header_Color);
178 -- This propagates the attributes to the label window
179 Clear_Soft_Label_Keys; Restore_Soft_Label_Keys;
182 Init_Keyboard_Handler;
184 Set_Echo_Mode (FALSE);
189 -- Initialize the Function Key Environment
190 -- We have some fixed key throughout this sample
195 when Event : others =>
196 Terminal_Interface.Curses.End_Windows;
197 Text_IO.Put ("Exception: ");
198 Text_IO.Put (Exception_Name (Event));
200 GNAT.OS_Lib.OS_Exit (1);