Debian Codegraph @

Ada95/samples/sample-text_io_demo.adb

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