ncurses2-acs_display.adb 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. ------------------------------------------------------------------------------
  2. -- --
  3. -- GNAT ncurses Binding Samples --
  4. -- --
  5. -- ncurses --
  6. -- --
  7. -- B O D Y --
  8. -- --
  9. ------------------------------------------------------------------------------
  10. -- Copyright (c) 2000-2006,2008 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: Eugene V. Melaragno <aldomel@ix.netcom.com> 2000
  37. -- Version Control
  38. -- $Revision: 1.6 $
  39. -- $Date: 2008/07/26 18:47:34 $
  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;
  45. with Ada.Strings.Unbounded;
  46. with Ada.Strings.Fixed;
  47. procedure ncurses2.acs_display is
  48. use Int_IO;
  49. procedure show_upper_chars (first : Integer);
  50. function show_1_acs (N : Integer;
  51. name : String;
  52. code : Attributed_Character)
  53. return Integer;
  54. procedure show_acs_chars;
  55. procedure show_upper_chars (first : Integer) is
  56. C1 : constant Boolean := (first = 128);
  57. last : constant Integer := first + 31;
  58. package p is new ncurses2.genericPuts (200);
  59. use p;
  60. use p.BS;
  61. use Ada.Strings.Unbounded;
  62. tmpa : Unbounded_String;
  63. tmpb : BS.Bounded_String;
  64. begin
  65. Erase;
  66. Switch_Character_Attribute
  67. (Attr => (Bold_Character => True, others => False));
  68. Move_Cursor (Line => 0, Column => 20);
  69. tmpa := To_Unbounded_String ("Display of ");
  70. if C1 then
  71. tmpa := tmpa & "C1";
  72. else
  73. tmpa := tmpa & "GR";
  74. end if;
  75. tmpa := tmpa & " Character Codes ";
  76. myPut (tmpb, first);
  77. Append (tmpa, To_String (tmpb));
  78. Append (tmpa, " to ");
  79. myPut (tmpb, last);
  80. Append (tmpa, To_String (tmpb));
  81. Add (Str => To_String (tmpa));
  82. Switch_Character_Attribute
  83. (On => False,
  84. Attr => (Bold_Character => True, others => False));
  85. Refresh;
  86. for code in first .. last loop
  87. declare
  88. row : constant Line_Position
  89. := Line_Position (4 + ((code - first) mod 16));
  90. col : constant Column_Position
  91. := Column_Position (((code - first) / 16) *
  92. Integer (Columns) / 2);
  93. tmp3 : String (1 .. 3);
  94. tmpx : String (1 .. Integer (Columns / 4));
  95. reply : Key_Code;
  96. begin
  97. Put (tmp3, code);
  98. myPut (tmpb, code, 16);
  99. tmpa := To_Unbounded_String (tmp3 & " (" & To_String (tmpb) & ')');
  100. Ada.Strings.Fixed.Move (To_String (tmpa), tmpx,
  101. Justify => Ada.Strings.Right);
  102. Add (Line => row, Column => col,
  103. Str => tmpx & ' ' & ':' & ' ');
  104. if C1 then
  105. Set_NoDelay_Mode (Mode => True);
  106. end if;
  107. Add_With_Immediate_Echo (Ch => Code_To_Char (Key_Code (code)));
  108. -- TODO check this
  109. if C1 then
  110. reply := Getchar;
  111. while reply /= Key_None loop
  112. Add (Ch => Code_To_Char (reply));
  113. Nap_Milli_Seconds (10);
  114. reply := Getchar;
  115. end loop;
  116. Set_NoDelay_Mode (Mode => False);
  117. end if;
  118. end;
  119. end loop;
  120. end show_upper_chars;
  121. function show_1_acs (N : Integer;
  122. name : String;
  123. code : Attributed_Character)
  124. return Integer is
  125. height : constant Integer := 16;
  126. row : constant Line_Position := Line_Position (4 + (N mod height));
  127. col : constant Column_Position := Column_Position ((N / height) *
  128. Integer (Columns) / 2);
  129. tmpx : String (1 .. Integer (Columns) / 3);
  130. begin
  131. Ada.Strings.Fixed.Move (name, tmpx,
  132. Justify => Ada.Strings.Right,
  133. Drop => Ada.Strings.Left);
  134. Add (Line => row, Column => col, Str => tmpx & ' ' & ':' & ' ');
  135. -- we need more room than C because our identifiers are longer
  136. -- 22 chars actually
  137. Add (Ch => code);
  138. return N + 1;
  139. end show_1_acs;
  140. procedure show_acs_chars is
  141. n : Integer;
  142. begin
  143. Erase;
  144. Switch_Character_Attribute
  145. (Attr => (Bold_Character => True, others => False));
  146. Add (Line => 0, Column => 20,
  147. Str => "Display of the ACS Character Set");
  148. Switch_Character_Attribute (On => False,
  149. Attr => (Bold_Character => True,
  150. others => False));
  151. Refresh;
  152. -- the following is useful to generate the below
  153. -- grep '^[ ]*ACS_' ../src/terminal_interface-curses.ads |
  154. -- awk '{print "n := show_1_acs(n, \""$1"\", ACS_Map("$1"));"}'
  155. n := show_1_acs (0, "ACS_Upper_Left_Corner",
  156. ACS_Map (ACS_Upper_Left_Corner));
  157. n := show_1_acs (n, "ACS_Lower_Left_Corner",
  158. ACS_Map (ACS_Lower_Left_Corner));
  159. n := show_1_acs (n, "ACS_Upper_Right_Corner",
  160. ACS_Map (ACS_Upper_Right_Corner));
  161. n := show_1_acs (n, "ACS_Lower_Right_Corner",
  162. ACS_Map (ACS_Lower_Right_Corner));
  163. n := show_1_acs (n, "ACS_Left_Tee", ACS_Map (ACS_Left_Tee));
  164. n := show_1_acs (n, "ACS_Right_Tee", ACS_Map (ACS_Right_Tee));
  165. n := show_1_acs (n, "ACS_Bottom_Tee", ACS_Map (ACS_Bottom_Tee));
  166. n := show_1_acs (n, "ACS_Top_Tee", ACS_Map (ACS_Top_Tee));
  167. n := show_1_acs (n, "ACS_Horizontal_Line",
  168. ACS_Map (ACS_Horizontal_Line));
  169. n := show_1_acs (n, "ACS_Vertical_Line", ACS_Map (ACS_Vertical_Line));
  170. n := show_1_acs (n, "ACS_Plus_Symbol", ACS_Map (ACS_Plus_Symbol));
  171. n := show_1_acs (n, "ACS_Scan_Line_1", ACS_Map (ACS_Scan_Line_1));
  172. n := show_1_acs (n, "ACS_Scan_Line_9", ACS_Map (ACS_Scan_Line_9));
  173. n := show_1_acs (n, "ACS_Diamond", ACS_Map (ACS_Diamond));
  174. n := show_1_acs (n, "ACS_Checker_Board", ACS_Map (ACS_Checker_Board));
  175. n := show_1_acs (n, "ACS_Degree", ACS_Map (ACS_Degree));
  176. n := show_1_acs (n, "ACS_Plus_Minus", ACS_Map (ACS_Plus_Minus));
  177. n := show_1_acs (n, "ACS_Bullet", ACS_Map (ACS_Bullet));
  178. n := show_1_acs (n, "ACS_Left_Arrow", ACS_Map (ACS_Left_Arrow));
  179. n := show_1_acs (n, "ACS_Right_Arrow", ACS_Map (ACS_Right_Arrow));
  180. n := show_1_acs (n, "ACS_Down_Arrow", ACS_Map (ACS_Down_Arrow));
  181. n := show_1_acs (n, "ACS_Up_Arrow", ACS_Map (ACS_Up_Arrow));
  182. n := show_1_acs (n, "ACS_Board_Of_Squares",
  183. ACS_Map (ACS_Board_Of_Squares));
  184. n := show_1_acs (n, "ACS_Lantern", ACS_Map (ACS_Lantern));
  185. n := show_1_acs (n, "ACS_Solid_Block", ACS_Map (ACS_Solid_Block));
  186. n := show_1_acs (n, "ACS_Scan_Line_3", ACS_Map (ACS_Scan_Line_3));
  187. n := show_1_acs (n, "ACS_Scan_Line_7", ACS_Map (ACS_Scan_Line_7));
  188. n := show_1_acs (n, "ACS_Less_Or_Equal", ACS_Map (ACS_Less_Or_Equal));
  189. n := show_1_acs (n, "ACS_Greater_Or_Equal",
  190. ACS_Map (ACS_Greater_Or_Equal));
  191. n := show_1_acs (n, "ACS_PI", ACS_Map (ACS_PI));
  192. n := show_1_acs (n, "ACS_Not_Equal", ACS_Map (ACS_Not_Equal));
  193. n := show_1_acs (n, "ACS_Sterling", ACS_Map (ACS_Sterling));
  194. if n = 0 then
  195. raise Constraint_Error;
  196. end if;
  197. end show_acs_chars;
  198. c1 : Key_Code;
  199. c : Character := 'a';
  200. begin
  201. loop
  202. case c is
  203. when 'a' =>
  204. show_acs_chars;
  205. when '0' | '1' | '2' | '3' =>
  206. show_upper_chars (ctoi (c) * 32 + 128);
  207. when others =>
  208. null;
  209. end case;
  210. Add (Line => Lines - 3, Column => 0,
  211. Str => "Note: ANSI terminals may not display C1 characters.");
  212. Add (Line => Lines - 2, Column => 0,
  213. Str => "Select: a=ACS, 0=C1, 1,2,3=GR characters, q=quit");
  214. Refresh;
  215. c1 := Getchar;
  216. c := Code_To_Char (c1);
  217. exit when c = 'q' or c = 'x';
  218. end loop;
  219. Pause;
  220. Erase;
  221. End_Windows;
  222. end ncurses2.acs_display;