1 ------------------------------------------------------------------------------
3 -- GNAT ncurses Binding Samples --
9 ------------------------------------------------------------------------------
10 -- Copyright (c) 2000,2004 Free Software Foundation, Inc. --
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: --
20 -- The above copyright notice and this permission notice shall be included --
21 -- in all copies or substantial portions of the Software. --
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. --
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 --
35 ------------------------------------------------------------------------------
36 -- Author: Eugene V. Melaragno <aldomel@ix.netcom.com> 2000
39 -- $Date: 2004/08/21 21:37:00 $
40 -- Binding Version 01.00
41 ------------------------------------------------------------------------------
42 with ncurses2.util; use ncurses2.util;
43 with ncurses2.genericPuts;
44 with Terminal_Interface.Curses; use Terminal_Interface.Curses;
46 with Ada.Strings.Unbounded;
47 with Ada.Strings.Fixed;
49 procedure ncurses2.acs_display is
52 procedure show_upper_chars (first : Integer);
53 function show_1_acs (N : Integer;
55 code : Attributed_Character)
57 procedure show_acs_chars;
60 procedure show_upper_chars (first : Integer) is
61 C1 : constant Boolean := (first = 128);
62 last : constant Integer := first + 31;
63 package p is new ncurses2.genericPuts (200);
66 use Ada.Strings.Unbounded;
68 tmpa : Unbounded_String;
69 tmpb : BS.Bounded_String;
72 Switch_Character_Attribute
73 (Attr => (Bold_Character => True, others => False));
74 Move_Cursor (Line => 0, Column => 20);
75 tmpa := To_Unbounded_String ("Display of ");
81 tmpa := tmpa & " Character Codes ";
83 Append (tmpa, To_String (tmpb));
84 Append (tmpa, " to ");
86 Append (tmpa, To_String (tmpb));
87 Add (Str => To_String (tmpa));
88 Switch_Character_Attribute
90 Attr => (Bold_Character => True, others => False));
93 for code in first .. last loop
95 row : constant Line_Position
96 := Line_Position (4 + ((code - first) mod 16));
97 col : constant Column_Position
98 := Column_Position (((code - first) / 16) *
99 Integer (Columns) / 2);
100 tmp3 : String (1 .. 3);
101 tmpx : String (1 .. Integer (Columns / 4));
105 myPut (tmpb, code, 16);
106 tmpa := To_Unbounded_String (tmp3 & " (" & To_String (tmpb) & ')');
108 Ada.Strings.Fixed.Move (To_String (tmpa), tmpx,
109 Justify => Ada.Strings.Right);
110 Add (Line => row, Column => col,
111 Str => tmpx & ' ' & ':' & ' ');
113 Set_NoDelay_Mode (Mode => True);
115 Add_With_Immediate_Echo (Ch => Code_To_Char (Key_Code (code)));
119 while reply /= Key_None loop
120 Add (Ch => Code_To_Char (reply));
121 Nap_Milli_Seconds (10);
124 Set_NoDelay_Mode (Mode => False);
128 end show_upper_chars;
130 function show_1_acs (N : Integer;
132 code : Attributed_Character)
134 height : constant Integer := 16;
135 row : constant Line_Position := Line_Position (4 + (N mod height));
136 col : constant Column_Position := Column_Position ((N / height) *
137 Integer (Columns) / 2);
138 tmpx : String (1 .. Integer (Columns) / 3);
140 Ada.Strings.Fixed.Move (name, tmpx,
141 Justify => Ada.Strings.Right,
142 Drop => Ada.Strings.Left);
143 Add (Line => row, Column => col, Str => tmpx & ' ' & ':' & ' ');
144 -- we need more room than C because our identifiers are longer
150 procedure show_acs_chars is
154 Switch_Character_Attribute
155 (Attr => (Bold_Character => True, others => False));
156 Add (Line => 0, Column => 20,
157 Str => "Display of the ACS Character Set");
158 Switch_Character_Attribute (On => False,
159 Attr => (Bold_Character => True,
163 -- the following is useful to generate the below
164 -- grep '^[ ]*ACS_' ../src/terminal_interface-curses.ads |
165 -- awk '{print "n := show_1_acs(n, \""$1"\", ACS_Map("$1"));"}'
167 n := show_1_acs (0, "ACS_Upper_Left_Corner",
168 ACS_Map (ACS_Upper_Left_Corner));
169 n := show_1_acs (n, "ACS_Lower_Left_Corner",
170 ACS_Map (ACS_Lower_Left_Corner));
171 n := show_1_acs (n, "ACS_Upper_Right_Corner",
172 ACS_Map (ACS_Upper_Right_Corner));
173 n := show_1_acs (n, "ACS_Lower_Right_Corner",
174 ACS_Map (ACS_Lower_Right_Corner));
175 n := show_1_acs (n, "ACS_Left_Tee", ACS_Map (ACS_Left_Tee));
176 n := show_1_acs (n, "ACS_Right_Tee", ACS_Map (ACS_Right_Tee));
177 n := show_1_acs (n, "ACS_Bottom_Tee", ACS_Map (ACS_Bottom_Tee));
178 n := show_1_acs (n, "ACS_Top_Tee", ACS_Map (ACS_Top_Tee));
179 n := show_1_acs (n, "ACS_Horizontal_Line",
180 ACS_Map (ACS_Horizontal_Line));
181 n := show_1_acs (n, "ACS_Vertical_Line", ACS_Map (ACS_Vertical_Line));
182 n := show_1_acs (n, "ACS_Plus_Symbol", ACS_Map (ACS_Plus_Symbol));
183 n := show_1_acs (n, "ACS_Scan_Line_1", ACS_Map (ACS_Scan_Line_1));
184 n := show_1_acs (n, "ACS_Scan_Line_9", ACS_Map (ACS_Scan_Line_9));
185 n := show_1_acs (n, "ACS_Diamond", ACS_Map (ACS_Diamond));
186 n := show_1_acs (n, "ACS_Checker_Board", ACS_Map (ACS_Checker_Board));
187 n := show_1_acs (n, "ACS_Degree", ACS_Map (ACS_Degree));
188 n := show_1_acs (n, "ACS_Plus_Minus", ACS_Map (ACS_Plus_Minus));
189 n := show_1_acs (n, "ACS_Bullet", ACS_Map (ACS_Bullet));
190 n := show_1_acs (n, "ACS_Left_Arrow", ACS_Map (ACS_Left_Arrow));
191 n := show_1_acs (n, "ACS_Right_Arrow", ACS_Map (ACS_Right_Arrow));
192 n := show_1_acs (n, "ACS_Down_Arrow", ACS_Map (ACS_Down_Arrow));
193 n := show_1_acs (n, "ACS_Up_Arrow", ACS_Map (ACS_Up_Arrow));
194 n := show_1_acs (n, "ACS_Board_Of_Squares",
195 ACS_Map (ACS_Board_Of_Squares));
196 n := show_1_acs (n, "ACS_Lantern", ACS_Map (ACS_Lantern));
197 n := show_1_acs (n, "ACS_Solid_Block", ACS_Map (ACS_Solid_Block));
198 n := show_1_acs (n, "ACS_Scan_Line_3", ACS_Map (ACS_Scan_Line_3));
199 n := show_1_acs (n, "ACS_Scan_Line_7", ACS_Map (ACS_Scan_Line_7));
200 n := show_1_acs (n, "ACS_Less_Or_Equal", ACS_Map (ACS_Less_Or_Equal));
201 n := show_1_acs (n, "ACS_Greater_Or_Equal",
202 ACS_Map (ACS_Greater_Or_Equal));
203 n := show_1_acs (n, "ACS_PI", ACS_Map (ACS_PI));
204 n := show_1_acs (n, "ACS_Not_Equal", ACS_Map (ACS_Not_Equal));
205 n := show_1_acs (n, "ACS_Sterling", ACS_Map (ACS_Sterling));
210 c : Character := 'a';
216 when '0' | '1' | '2' | '3' =>
217 show_upper_chars (ctoi (c) * 32 + 128);
221 Add (Line => Lines - 3, Column => 0,
222 Str => "Note: ANSI terminals may not display C1 characters.");
223 Add (Line => Lines - 2, Column => 0,
224 Str => "Select: a=ACS, 0=C1, 1,2,3=GR characters, q=quit");
227 c := Code_To_Char (c1);
228 exit when c = 'q' or c = 'x';
233 end ncurses2.acs_display;