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