ncurses2-flushinp_test.adb 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. ------------------------------------------------------------------------------
  2. -- --
  3. -- GNAT ncurses Binding Samples --
  4. -- --
  5. -- ncurses --
  6. -- --
  7. -- B O D Y --
  8. -- --
  9. ------------------------------------------------------------------------------
  10. -- Copyright (c) 2000 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.1 $
  39. -- Binding Version 01.00
  40. ------------------------------------------------------------------------------
  41. with Terminal_Interface.Curses; use Terminal_Interface.Curses;
  42. with ncurses2.util; use ncurses2.util;
  43. procedure ncurses2.flushinp_test (win : Window) is
  44. procedure Continue (win : Window);
  45. procedure Continue (win : Window) is
  46. begin
  47. Set_Echo_Mode (False);
  48. Move_Cursor (win, 10, 1);
  49. Add (win, 10, 1, " Press any key to continue");
  50. Refresh (win);
  51. Getchar (win);
  52. end Continue;
  53. h, by, sh : Line_Position;
  54. w, bx, sw : Column_Position;
  55. subWin : Window;
  56. begin
  57. Clear (win);
  58. Get_Size (win, h, w);
  59. Get_Window_Position (win, by, bx);
  60. sw := w / 3;
  61. sh := h / 3;
  62. subWin := Sub_Window (win, sh, sw, by + h - sh - 2, bx + w - sw - 2);
  63. if Has_Colors then
  64. Init_Pair (2, Cyan, Blue);
  65. Change_Background (subWin,
  66. Attributed_Character'(Ch => ' ', Color => 2,
  67. Attr => Normal_Video));
  68. end if;
  69. Set_Character_Attributes (subWin,
  70. (Bold_Character => True, others => False));
  71. Box (subWin);
  72. Add (subWin, 2, 1, "This is a subwindow");
  73. Refresh (win);
  74. Set_Cbreak_Mode (True);
  75. Add (win, 0, 1, "This is a test of the flushinp() call.");
  76. Add (win, 2, 1, "Type random keys for 5 seconds.");
  77. Add (win, 3, 1,
  78. "These should be discarded (not echoed) after the subwindow " &
  79. "goes away.");
  80. Refresh (win);
  81. for i in 0 .. 4 loop
  82. Move_Cursor (subWin, 1, 1);
  83. Add (subWin, Str => "Time = ");
  84. Add (subWin, Str => Integer'Image (i));
  85. Refresh (subWin);
  86. Nap_Milli_Seconds (1000);
  87. Flush_Input;
  88. end loop;
  89. Delete (subWin);
  90. Erase (win);
  91. Flash_Screen;
  92. Refresh (win);
  93. Nap_Milli_Seconds (1000);
  94. Add (win, 2, 1,
  95. Str => "If you were still typing when the window timer expired,");
  96. Add (win, 3, 1,
  97. "or else you typed nothing at all while it was running,");
  98. Add (win, 4, 1,
  99. "test was invalid. You'll see garbage or nothing at all. ");
  100. Add (win, 6, 1, "Press a key");
  101. Move_Cursor (win, 9, 10);
  102. Refresh (win);
  103. Set_Echo_Mode (True);
  104. Getchar (win);
  105. Flush_Input;
  106. Add (win, 12, 0,
  107. "If you see any key other than what you typed, flushinp() is broken.");
  108. Continue (win);
  109. Move_Cursor (win, 9, 10);
  110. Delete_Character (win);
  111. Refresh (win);
  112. Move_Cursor (win, 12, 0);
  113. Clear_To_End_Of_Line;
  114. Add (win,
  115. "What you typed should now have been deleted; if not, wdelch() " &
  116. "failed.");
  117. Continue (win);
  118. Set_Cbreak_Mode (True);
  119. end ncurses2.flushinp_test;