]> ncurses.scripts.mit.edu Git - ncurses.git/blob - Ada95/samples/sample-text_io_demo.adb
ncurses 6.1 - patch 20191130
[ncurses.git] / Ada95 / samples / sample-text_io_demo.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                       GNAT ncurses Binding Samples                       --
4 --                                                                          --
5 --                            Sample.Text_IO_Demo                           --
6 --                                                                          --
7 --                                 B O D Y                                  --
8 --                                                                          --
9 ------------------------------------------------------------------------------
10 -- Copyright (c) 1998-2011,2018 Free Software Foundation, Inc.              --
11 --                                                                          --
12 -- Permission is hereby granted, free of charge, to any person obtaining a  --
13 -- copy of this software and associated documentation files (the            --
14 -- "Software"), to deal in the Software without restriction, including      --
15 -- without limitation the rights to use, copy, modify, merge, publish,      --
16 -- distribute, distribute with modifications, sublicense, and/or sell       --
17 -- copies of the Software, and to permit persons to whom the Software is    --
18 -- furnished to do so, subject to the following conditions:                 --
19 --                                                                          --
20 -- The above copyright notice and this permission notice shall be included  --
21 -- in all copies or substantial portions of the Software.                   --
22 --                                                                          --
23 -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  --
24 -- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               --
25 -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   --
26 -- IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   --
27 -- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    --
28 -- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    --
29 -- THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               --
30 --                                                                          --
31 -- Except as contained in this notice, the name(s) of the above copyright   --
32 -- holders shall not be used in advertising or otherwise to promote the     --
33 -- sale, use or other dealings in this Software without prior written       --
34 -- authorization.                                                           --
35 ------------------------------------------------------------------------------
36 --  Author:  Juergen Pfeifer, 1996
37 --  Version Control
38 --  $Revision: 1.18 $
39 --  $Date: 2018/07/07 23:38:02 $
40 --  Binding Version 01.00
41 ------------------------------------------------------------------------------
42 with Ada.Numerics.Generic_Elementary_Functions;
43
44 with Ada.Numerics.Complex_Types;
45 use  Ada.Numerics.Complex_Types;
46
47 with Terminal_Interface.Curses;
48 use  Terminal_Interface.Curses;
49
50 with Terminal_Interface.Curses.Panels;
51 use  Terminal_Interface.Curses.Panels;
52
53 with Terminal_Interface.Curses.Text_IO;
54 use  Terminal_Interface.Curses.Text_IO;
55
56 with Terminal_Interface.Curses.Text_IO.Integer_IO;
57 with Terminal_Interface.Curses.Text_IO.Float_IO;
58 with Terminal_Interface.Curses.Text_IO.Enumeration_IO;
59 with Terminal_Interface.Curses.Text_IO.Complex_IO;
60 with Terminal_Interface.Curses.Text_IO.Decimal_IO;
61 with Terminal_Interface.Curses.Text_IO.Modular_IO;
62
63 with Sample.Manifest; use Sample.Manifest;
64 with Sample.Function_Key_Setting; use Sample.Function_Key_Setting;
65 with Sample.Keyboard_Handler; use Sample.Keyboard_Handler;
66 with Sample.Explanation; use Sample.Explanation;
67
68 pragma Elaborate_All (Terminal_Interface.Curses.Text_Io.Complex_IO);
69 pragma Elaborate_All (Terminal_Interface.Curses.Text_Io.Decimal_IO);
70 pragma Elaborate_All (Terminal_Interface.Curses.Text_Io.Enumeration_IO);
71 pragma Elaborate_All (Terminal_Interface.Curses.Text_Io.Float_IO);
72 pragma Elaborate_All (Terminal_Interface.Curses.Text_Io.Integer_IO);
73 pragma Elaborate_All (Terminal_Interface.Curses.Text_Io.Modular_IO);
74
75 package body Sample.Text_IO_Demo is
76
77    type Weekday is (Sunday,
78                     Monday,
79                     Tuesday,
80                     Wednesday,
81                     Thursday,
82                     Friday,
83                     Saturday);
84
85    type Dec is delta 0.01 digits 5 range 0.0 .. 4.0;
86    type Md is mod 5;
87
88    package Math is new
89      Ada.Numerics.Generic_Elementary_Functions (Float);
90
91    package Int_IO is new
92      Terminal_Interface.Curses.Text_IO.Integer_IO (Integer);
93    use Int_IO;
94
95    package Real_IO is new
96      Terminal_Interface.Curses.Text_IO.Float_IO (Float);
97    use Real_IO;
98
99    package Enum_IO is new
100      Terminal_Interface.Curses.Text_IO.Enumeration_IO (Weekday);
101    use Enum_IO;
102
103    package C_IO is new
104      Terminal_Interface.Curses.Text_IO.Complex_IO (Ada.Numerics.Complex_Types);
105    use C_IO;
106
107    package D_IO is new
108      Terminal_Interface.Curses.Text_IO.Decimal_IO (Dec);
109    use D_IO;
110
111    package M_IO is new
112      Terminal_Interface.Curses.Text_IO.Modular_IO (Md);
113    use M_IO;
114
115    procedure Demo
116    is
117       W : Window;
118       P : Panel := Create (Standard_Window);
119       K : Real_Key_Code;
120       Im : constant Complex := (0.0, 1.0);
121       Fx : constant Dec := 3.14;
122       Dc : constant Dec := 2.72;
123       L : Md;
124
125    begin
126       Push_Environment ("TEXTIO");
127       Default_Labels;
128       Notepad ("TEXTIO-PAD00");
129
130       Set_Echo_Mode (False);
131       Set_Meta_Mode;
132       Set_KeyPad_Mode;
133       W := Sub_Window (Standard_Window, Lines - 2, Columns - 2, 1, 1);
134       Box;
135       Refresh_Without_Update;
136       Set_Meta_Mode (W);
137       Set_KeyPad_Mode (W);
138       Immediate_Update_Mode (W, True);
139
140       Set_Window (W);
141
142       for I in 1 .. 10 loop
143          Put ("Square root of ");
144          Put (Item => I, Width => 5);
145          Put (" is ");
146          Put (Item => Math.Sqrt (Float (I)), Exp => 0, Aft => 7);
147          New_Line;
148       end loop;
149
150       for W in Weekday loop
151          Put (Item => W); Put (' ');
152       end loop;
153       New_Line;
154
155       L := Md'First;
156       for I in 1 .. 2 loop
157          for J in Md'Range loop
158             Put (L); Put (' ');
159             L := L + 1;
160          end loop;
161       end loop;
162       New_Line;
163
164       Put (Im); New_Line;
165       Put (Fx); New_Line;
166       Put (Dc); New_Line;
167
168       loop
169          K := Get_Key;
170          if K in Special_Key_Code'Range then
171             case K is
172                when QUIT_CODE     => exit;
173                when HELP_CODE     => Explain_Context;
174                when EXPLAIN_CODE  => Explain ("TEXTIOKEYS");
175                when others        => null;
176             end case;
177          end if;
178       end loop;
179
180       Set_Window (Null_Window);
181       Erase; Refresh_Without_Update;
182       Delete (P);
183       Delete (W);
184
185       Pop_Environment;
186    end Demo;
187
188 end Sample.Text_IO_Demo;