]> ncurses.scripts.mit.edu Git - ncurses.git/blob - Ada95/samples/sample-text_io_demo.adb
ncurses 4.1
[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 --  Version 00.92                                                           --
10 --                                                                          --
11 --  The ncurses Ada95 binding is copyrighted 1996 by                        --
12 --  Juergen Pfeifer, Email: Juergen.Pfeifer@T-Online.de                     --
13 --                                                                          --
14 --  Permission is hereby granted to reproduce and distribute this           --
15 --  binding by any means and for any fee, whether alone or as part          --
16 --  of a larger distribution, in source or in binary form, PROVIDED         --
17 --  this notice is included with any such distribution, and is not          --
18 --  removed from any of its header files. Mention of ncurses and the        --
19 --  author of this binding in any applications linked with it is            --
20 --  highly appreciated.                                                     --
21 --                                                                          --
22 --  This binding comes AS IS with no warranty, implied or expressed.        --
23 ------------------------------------------------------------------------------
24 --  Version Control
25 --  $Revision: 1.2 $
26 ------------------------------------------------------------------------------
27 with Ada.Numerics.Generic_Elementary_Functions;
28 with Ada.Numerics.Complex_Types;
29 use  Ada.Numerics.Complex_Types;
30
31 with Terminal_Interface.Curses; use Terminal_Interface.Curses;
32 with Terminal_Interface.Curses.Panels; use Terminal_Interface.Curses.Panels;
33 with Terminal_Interface.Curses.Text_IO;
34 use  Terminal_Interface.Curses.Text_IO;
35 with Terminal_Interface.Curses.Text_IO.Integer_IO;
36 with Terminal_Interface.Curses.Text_IO.Float_IO;
37 with Terminal_Interface.Curses.Text_IO.Enumeration_IO;
38 with Terminal_Interface.Curses.Text_IO.Complex_IO;
39 with Terminal_Interface.Curses.Text_IO.Fixed_IO;
40 with Terminal_Interface.Curses.Text_IO.Decimal_IO;
41 with Terminal_Interface.Curses.Text_IO.Modular_IO;
42
43 with Sample.Manifest; use Sample.Manifest;
44 with Sample.Helpers; use Sample.Helpers;
45 with Sample.Function_Key_Setting; use Sample.Function_Key_Setting;
46 with Sample.Keyboard_Handler; use Sample.Keyboard_Handler;
47 with Sample.Explanation; use Sample.Explanation;
48
49 package body Sample.Text_IO_Demo is
50
51    type Weekday is (Sunday,
52                     Monday,
53                     Tuesday,
54                     Wednesday,
55                     Thursday,
56                     Friday,
57                     Saturday);
58
59    type Fix is delta 0.1 range 0.0 .. 4.0;
60    type Dec is delta 0.01 digits 5 range 0.0 .. 4.0;
61    type Md is mod 5;
62
63    package Math is new
64      Ada.Numerics.Generic_Elementary_Functions (Float);
65
66    package Int_IO is new
67      Terminal_Interface.Curses.Text_IO.Integer_IO (Integer);
68    use Int_IO;
69
70    package Real_IO is new
71      Terminal_Interface.Curses.Text_IO.Float_IO (Float);
72    use Real_IO;
73
74    package Enum_IO is new
75      Terminal_Interface.Curses.Text_IO.Enumeration_IO (Weekday);
76    use Enum_IO;
77
78    package C_IO is new
79      Terminal_Interface.Curses.Text_IO.Complex_IO (Ada.Numerics.Complex_Types);
80    use C_IO;
81
82    package F_IO is new
83      Terminal_Interface.Curses.Text_IO.Fixed_IO (Fix);
84    use F_IO;
85
86    package D_IO is new
87      Terminal_Interface.Curses.Text_IO.Decimal_IO (Dec);
88    use D_IO;
89
90    package M_IO is new
91      Terminal_Interface.Curses.Text_IO.Modular_IO (Md);
92    use M_IO;
93
94    procedure Demo
95    is
96       W : Window;
97       P : Panel := Create (Standard_Window);
98       K : Real_Key_Code;
99       Im : Complex := (0.0, 1.0);
100       Fx : Fix := 3.14;
101       Dc : Dec := 2.72;
102       L : Md;
103
104    begin
105       Push_Environment ("TEXTIO");
106       Default_Labels;
107       Notepad ("TEXTIO-PAD00");
108
109       Set_Echo_Mode (FALSE);
110       Set_Raw_Mode;
111       Set_Meta_Mode;
112       Set_KeyPad_Mode;
113       W := Sub_Window (Standard_Window, Lines - 2, Columns - 2, 1, 1);
114       Box;
115       Refresh_Without_Update;
116       Set_Meta_Mode (W);
117       Set_KeyPad_Mode (W);
118       Immediate_Update_Mode (W, True);
119
120       Set_Window (W);
121
122       for I in 1 .. 10 loop
123          Put ("Square root of ");
124          Put (Item => I, Width => 5);
125          Put (" is ");
126          Put (Item => Math.Sqrt (Float (I)), Exp => 0, Aft => 7);
127          New_Line;
128       end loop;
129
130       for W in Weekday loop
131          Put (Item => W); Put (' ');
132       end loop;
133       New_Line;
134
135       L := Md'First;
136       for I in 1 .. 2 loop
137          for J in Md'Range loop
138             Put (L); Put (' ');
139             L := L + 1;
140          end loop;
141       end loop;
142       New_Line;
143
144       Put (Im); New_Line;
145       Put (Fx); New_Line;
146       Put (Dc); New_Line;
147
148       loop
149          K := Get_Key;
150          if K in Special_Key_Code'Range then
151             case K is
152                when QUIT_CODE     => exit;
153                when HELP_CODE     => Explain_Context;
154                when EXPLAIN_CODE  => Explain ("TEXTIOKEYS");
155                when others        => null;
156             end case;
157          end if;
158       end loop;
159
160       Set_Window (Null_Window);
161       Erase; Refresh_Without_Update;
162       Delete (P);
163       Delete (W);
164
165       Pop_Environment;
166    end Demo;
167
168 end Sample.Text_IO_Demo;