missing ncurses sources
[tomato.git] / release / src / router / libncurses / Ada95 / samples / sample-text_io_demo.adb
bloba458a37cdbd9c822fbfc7d6a3183be1551c4e005
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-2006,2011 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.17 $
39 -- $Date: 2011/03/23 00:44:12 $
40 -- Binding Version 01.00
41 ------------------------------------------------------------------------------
42 with Ada.Numerics.Generic_Elementary_Functions;
44 with Ada.Numerics.Complex_Types;
45 use Ada.Numerics.Complex_Types;
47 with Terminal_Interface.Curses;
48 use Terminal_Interface.Curses;
50 with Terminal_Interface.Curses.Panels;
51 use Terminal_Interface.Curses.Panels;
53 with Terminal_Interface.Curses.Text_IO;
54 use Terminal_Interface.Curses.Text_IO;
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.Fixed_IO;
61 with Terminal_Interface.Curses.Text_IO.Decimal_IO;
62 with Terminal_Interface.Curses.Text_IO.Modular_IO;
64 with Sample.Manifest; use Sample.Manifest;
65 with Sample.Function_Key_Setting; use Sample.Function_Key_Setting;
66 with Sample.Keyboard_Handler; use Sample.Keyboard_Handler;
67 with Sample.Explanation; use Sample.Explanation;
69 pragma Elaborate_All (Terminal_Interface.Curses.Text_Io.Complex_IO);
70 pragma Elaborate_All (Terminal_Interface.Curses.Text_Io.Decimal_IO);
71 pragma Elaborate_All (Terminal_Interface.Curses.Text_Io.Enumeration_IO);
72 pragma Elaborate_All (Terminal_Interface.Curses.Text_Io.Fixed_IO);
73 pragma Elaborate_All (Terminal_Interface.Curses.Text_Io.Float_IO);
74 pragma Elaborate_All (Terminal_Interface.Curses.Text_Io.Integer_IO);
75 pragma Elaborate_All (Terminal_Interface.Curses.Text_Io.Modular_IO);
77 package body Sample.Text_IO_Demo is
79 type Weekday is (Sunday,
80 Monday,
81 Tuesday,
82 Wednesday,
83 Thursday,
84 Friday,
85 Saturday);
87 type Fix is delta 0.1 range 0.0 .. 4.0;
88 type Dec is delta 0.01 digits 5 range 0.0 .. 4.0;
89 type Md is mod 5;
91 package Math is new
92 Ada.Numerics.Generic_Elementary_Functions (Float);
94 package Int_IO is new
95 Terminal_Interface.Curses.Text_IO.Integer_IO (Integer);
96 use Int_IO;
98 package Real_IO is new
99 Terminal_Interface.Curses.Text_IO.Float_IO (Float);
100 use Real_IO;
102 package Enum_IO is new
103 Terminal_Interface.Curses.Text_IO.Enumeration_IO (Weekday);
104 use Enum_IO;
106 package C_IO is new
107 Terminal_Interface.Curses.Text_IO.Complex_IO (Ada.Numerics.Complex_Types);
108 use C_IO;
110 package F_IO is new
111 Terminal_Interface.Curses.Text_IO.Fixed_IO (Fix);
112 use F_IO;
114 package D_IO is new
115 Terminal_Interface.Curses.Text_IO.Decimal_IO (Dec);
116 use D_IO;
118 package M_IO is new
119 Terminal_Interface.Curses.Text_IO.Modular_IO (Md);
120 use M_IO;
122 procedure Demo
124 W : Window;
125 P : Panel := Create (Standard_Window);
126 K : Real_Key_Code;
127 Im : constant Complex := (0.0, 1.0);
128 Fx : constant Dec := 3.14;
129 Dc : constant Dec := 2.72;
130 L : Md;
132 begin
133 Push_Environment ("TEXTIO");
134 Default_Labels;
135 Notepad ("TEXTIO-PAD00");
137 Set_Echo_Mode (False);
138 Set_Meta_Mode;
139 Set_KeyPad_Mode;
140 W := Sub_Window (Standard_Window, Lines - 2, Columns - 2, 1, 1);
141 Box;
142 Refresh_Without_Update;
143 Set_Meta_Mode (W);
144 Set_KeyPad_Mode (W);
145 Immediate_Update_Mode (W, True);
147 Set_Window (W);
149 for I in 1 .. 10 loop
150 Put ("Square root of ");
151 Put (Item => I, Width => 5);
152 Put (" is ");
153 Put (Item => Math.Sqrt (Float (I)), Exp => 0, Aft => 7);
154 New_Line;
155 end loop;
157 for W in Weekday loop
158 Put (Item => W); Put (' ');
159 end loop;
160 New_Line;
162 L := Md'First;
163 for I in 1 .. 2 loop
164 for J in Md'Range loop
165 Put (L); Put (' ');
166 L := L + 1;
167 end loop;
168 end loop;
169 New_Line;
171 Put (Im); New_Line;
172 Put (Fx); New_Line;
173 Put (Dc); New_Line;
175 loop
176 K := Get_Key;
177 if K in Special_Key_Code'Range then
178 case K is
179 when QUIT_CODE => exit;
180 when HELP_CODE => Explain_Context;
181 when EXPLAIN_CODE => Explain ("TEXTIOKEYS");
182 when others => null;
183 end case;
184 end if;
185 end loop;
187 Set_Window (Null_Window);
188 Erase; Refresh_Without_Update;
189 Delete (P);
190 Delete (W);
192 Pop_Environment;
193 end Demo;
195 end Sample.Text_IO_Demo;