ncurses2-color_test.adb 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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.3 $
  39. -- $Date: 2008/07/26 18:47:17 $
  40. -- Binding Version 01.00
  41. ------------------------------------------------------------------------------
  42. with ncurses2.util; use ncurses2.util;
  43. with Terminal_Interface.Curses; use Terminal_Interface.Curses;
  44. with Ada.Strings.Fixed;
  45. procedure ncurses2.color_test is
  46. use Int_IO;
  47. procedure show_color_name (y, x : Integer; color : Integer);
  48. color_names : constant array (0 .. 15) of String (1 .. 7) :=
  49. (
  50. "black ",
  51. "red ",
  52. "green ",
  53. "yellow ",
  54. "blue ",
  55. "magenta",
  56. "cyan ",
  57. "white ",
  58. "BLACK ",
  59. "RED ",
  60. "GREEN ",
  61. "YELLOW ",
  62. "BLUE ",
  63. "MAGENTA",
  64. "CYAN ",
  65. "WHITE "
  66. );
  67. procedure show_color_name (y, x : Integer; color : Integer) is
  68. tmp5 : String (1 .. 5);
  69. begin
  70. if Number_Of_Colors > 8 then
  71. Put (tmp5, color);
  72. Add (Line => Line_Position (y), Column => Column_Position (x),
  73. Str => tmp5);
  74. else
  75. Add (Line => Line_Position (y), Column => Column_Position (x),
  76. Str => color_names (color));
  77. end if;
  78. end show_color_name;
  79. top, width : Integer;
  80. hello : String (1 .. 5);
  81. -- tmp3 : String (1 .. 3);
  82. -- tmp2 : String (1 .. 2);
  83. begin
  84. Refresh;
  85. Add (Str => "There are ");
  86. -- Put(tmp3, Number_Of_Colors*Number_Of_Colors);
  87. Add (Str => Ada.Strings.Fixed.Trim (Integer'Image (Number_Of_Colors *
  88. Number_Of_Colors),
  89. Ada.Strings.Left));
  90. Add (Str => " color pairs");
  91. Add (Ch => newl);
  92. if Number_Of_Colors > 8 then
  93. width := 4;
  94. else
  95. width := 8;
  96. end if;
  97. if Number_Of_Colors > 8 then
  98. hello := "Test ";
  99. else
  100. hello := "Hello";
  101. end if;
  102. for Bright in Boolean loop
  103. if Number_Of_Colors > 8 then
  104. top := 0;
  105. else
  106. top := Boolean'Pos (Bright) * (Number_Of_Colors + 3);
  107. end if;
  108. Clear_To_End_Of_Screen;
  109. Move_Cursor (Line => Line_Position (top) + 1, Column => 0);
  110. -- Put(tmp2, Number_Of_Colors);
  111. Add (Str => Ada.Strings.Fixed.Trim (Integer'Image (Number_Of_Colors),
  112. Ada.Strings.Left));
  113. Add (Ch => 'x');
  114. Add (Str => Ada.Strings.Fixed.Trim (Integer'Image (Number_Of_Colors),
  115. Ada.Strings.Left));
  116. Add (Str => " matrix of foreground/background colors, bright *");
  117. if Bright then
  118. Add (Str => "on");
  119. else
  120. Add (Str => "off");
  121. end if;
  122. Add (Ch => '*');
  123. for i in 0 .. Number_Of_Colors - 1 loop
  124. show_color_name (top + 2, (i + 1) * width, i);
  125. end loop;
  126. for i in 0 .. Number_Of_Colors - 1 loop
  127. show_color_name (top + 3 + i, 0, i);
  128. end loop;
  129. for i in 1 .. Number_Of_Color_Pairs - 1 loop
  130. Init_Pair (Color_Pair (i), Color_Number (i mod Number_Of_Colors),
  131. Color_Number (i / Number_Of_Colors));
  132. -- attron((attr_t) COLOR_PAIR(i)) -- Huh?
  133. Set_Color (Pair => Color_Pair (i));
  134. if Bright then
  135. Switch_Character_Attribute (Attr => (Bold_Character => True,
  136. others => False));
  137. end if;
  138. Add (Line => Line_Position (top + 3 + (i / Number_Of_Colors)),
  139. Column => Column_Position ((i mod Number_Of_Colors + 1) *
  140. width),
  141. Str => hello);
  142. Set_Character_Attributes;
  143. end loop;
  144. if Number_Of_Colors > 8 or Bright then
  145. Pause;
  146. end if;
  147. end loop;
  148. Erase;
  149. End_Windows;
  150. end ncurses2.color_test;