]> ncurses.scripts.mit.edu Git - ncurses.git/blob - Ada95/samples/sample-text_io_demo.adb
ed796095990e60cddbab433db82dbdc5908f893d
[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 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 <juergen.pfeifer@gmx.net> 1996
37 --  Version Control
38 --  $Revision: 1.8 $
39 --  Binding Version 01.00
40 ------------------------------------------------------------------------------
41 with Ada.Numerics.Generic_Elementary_Functions;
42 with Ada.Numerics.Complex_Types;
43 use  Ada.Numerics.Complex_Types;
44
45 with Terminal_Interface.Curses; use Terminal_Interface.Curses;
46 with Terminal_Interface.Curses.Panels; use Terminal_Interface.Curses.Panels;
47 with Terminal_Interface.Curses.Text_IO;
48 use  Terminal_Interface.Curses.Text_IO;
49 with Terminal_Interface.Curses.Text_IO.Integer_IO;
50 with Terminal_Interface.Curses.Text_IO.Float_IO;
51 with Terminal_Interface.Curses.Text_IO.Enumeration_IO;
52 with Terminal_Interface.Curses.Text_IO.Complex_IO;
53 with Terminal_Interface.Curses.Text_IO.Fixed_IO;
54 with Terminal_Interface.Curses.Text_IO.Decimal_IO;
55 with Terminal_Interface.Curses.Text_IO.Modular_IO;
56
57 with Sample.Manifest; use Sample.Manifest;
58 with Sample.Function_Key_Setting; use Sample.Function_Key_Setting;
59 with Sample.Keyboard_Handler; use Sample.Keyboard_Handler;
60 with Sample.Explanation; use Sample.Explanation;
61
62 package body Sample.Text_IO_Demo is
63
64    type Weekday is (Sunday,
65                     Monday,
66                     Tuesday,
67                     Wednesday,
68                     Thursday,
69                     Friday,
70                     Saturday);
71
72    type Fix is delta 0.1 range 0.0 .. 4.0;
73    type Dec is delta 0.01 digits 5 range 0.0 .. 4.0;
74    type Md is mod 5;
75
76    package Math is new
77      Ada.Numerics.Generic_Elementary_Functions (Float);
78
79    package Int_IO is new
80      Terminal_Interface.Curses.Text_IO.Integer_IO (Integer);
81    use Int_IO;
82
83    package Real_IO is new
84      Terminal_Interface.Curses.Text_IO.Float_IO (Float);
85    use Real_IO;
86
87    package Enum_IO is new
88      Terminal_Interface.Curses.Text_IO.Enumeration_IO (Weekday);
89    use Enum_IO;
90
91    package C_IO is new
92      Terminal_Interface.Curses.Text_IO.Complex_IO (Ada.Numerics.Complex_Types);
93    use C_IO;
94
95    package F_IO is new
96      Terminal_Interface.Curses.Text_IO.Fixed_IO (Fix);
97    use F_IO;
98
99    package D_IO is new
100      Terminal_Interface.Curses.Text_IO.Decimal_IO (Dec);
101    use D_IO;
102
103    package M_IO is new
104      Terminal_Interface.Curses.Text_IO.Modular_IO (Md);
105    use M_IO;
106
107    procedure Demo
108    is
109       W : Window;
110       P : Panel := Create (Standard_Window);
111       K : Real_Key_Code;
112       Im : Complex := (0.0, 1.0);
113       Fx : Fix := 3.14;
114       Dc : Dec := 2.72;
115       L : Md;
116
117    begin
118       Push_Environment ("TEXTIO");
119       Default_Labels;
120       Notepad ("TEXTIO-PAD00");
121
122       Set_Echo_Mode (FALSE);
123       Set_Meta_Mode;
124       Set_KeyPad_Mode;
125       W := Sub_Window (Standard_Window, Lines - 2, Columns - 2, 1, 1);
126       Box;
127       Refresh_Without_Update;
128       Set_Meta_Mode (W);
129       Set_KeyPad_Mode (W);
130       Immediate_Update_Mode (W, True);
131
132       Set_Window (W);
133
134       for I in 1 .. 10 loop
135          Put ("Square root of ");
136          Put (Item => I, Width => 5);
137          Put (" is ");
138          Put (Item => Math.Sqrt (Float (I)), Exp => 0, Aft => 7);
139          New_Line;
140       end loop;
141
142       for W in Weekday loop
143          Put (Item => W); Put (' ');
144       end loop;
145       New_Line;
146
147       L := Md'First;
148       for I in 1 .. 2 loop
149          for J in Md'Range loop
150             Put (L); Put (' ');
151             L := L + 1;
152          end loop;
153       end loop;
154       New_Line;
155
156       Put (Im); New_Line;
157       Put (Fx); New_Line;
158       Put (Dc); New_Line;
159
160       loop
161          K := Get_Key;
162          if K in Special_Key_Code'Range then
163             case K is
164                when QUIT_CODE     => exit;
165                when HELP_CODE     => Explain_Context;
166                when EXPLAIN_CODE  => Explain ("TEXTIOKEYS");
167                when others        => null;
168             end case;
169          end if;
170       end loop;
171
172       Set_Window (Null_Window);
173       Erase; Refresh_Without_Update;
174       Delete (P);
175       Delete (W);
176
177       Pop_Environment;
178    end Demo;
179
180 end Sample.Text_IO_Demo;