Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1 | ------------------------------------------------------------------------------ |
| 2 | -- -- |
| 3 | -- GNAT ncurses Binding Samples -- |
| 4 | -- -- |
| 5 | -- ncurses -- |
| 6 | -- -- |
| 7 | -- B O D Y -- |
| 8 | -- -- |
| 9 | ------------------------------------------------------------------------------ |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 10 | -- Copyright 2020 Thomas E. Dickey -- |
| 11 | -- Copyright 2000 Free Software Foundation, Inc. -- |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 12 | -- -- |
| 13 | -- Permission is hereby granted, free of charge, to any person obtaining a -- |
| 14 | -- copy of this software and associated documentation files (the -- |
| 15 | -- "Software"), to deal in the Software without restriction, including -- |
| 16 | -- without limitation the rights to use, copy, modify, merge, publish, -- |
| 17 | -- distribute, distribute with modifications, sublicense, and/or sell -- |
| 18 | -- copies of the Software, and to permit persons to whom the Software is -- |
| 19 | -- furnished to do so, subject to the following conditions: -- |
| 20 | -- -- |
| 21 | -- The above copyright notice and this permission notice shall be included -- |
| 22 | -- in all copies or substantial portions of the Software. -- |
| 23 | -- -- |
| 24 | -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -- |
| 25 | -- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -- |
| 26 | -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -- |
| 27 | -- IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -- |
| 28 | -- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -- |
| 29 | -- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR -- |
| 30 | -- THE USE OR OTHER DEALINGS IN THE SOFTWARE. -- |
| 31 | -- -- |
| 32 | -- Except as contained in this notice, the name(s) of the above copyright -- |
| 33 | -- holders shall not be used in advertising or otherwise to promote the -- |
| 34 | -- sale, use or other dealings in this Software without prior written -- |
| 35 | -- authorization. -- |
| 36 | ------------------------------------------------------------------------------ |
| 37 | -- Author: Eugene V. Melaragno <aldomel@ix.netcom.com> 2000 |
| 38 | -- Version Control |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 39 | -- $Revision: 1.2 $ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 40 | -- Binding Version 01.00 |
| 41 | ------------------------------------------------------------------------------ |
| 42 | with Terminal_Interface.Curses; use Terminal_Interface.Curses; |
| 43 | with ncurses2.util; use ncurses2.util; |
| 44 | |
| 45 | procedure ncurses2.flushinp_test (win : Window) is |
| 46 | |
| 47 | procedure Continue (win : Window); |
| 48 | |
| 49 | procedure Continue (win : Window) is |
| 50 | begin |
| 51 | Set_Echo_Mode (False); |
| 52 | Move_Cursor (win, 10, 1); |
| 53 | Add (win, 10, 1, " Press any key to continue"); |
| 54 | Refresh (win); |
| 55 | Getchar (win); |
| 56 | end Continue; |
| 57 | |
| 58 | h, by, sh : Line_Position; |
| 59 | w, bx, sw : Column_Position; |
| 60 | |
| 61 | subWin : Window; |
| 62 | |
| 63 | begin |
| 64 | Clear (win); |
| 65 | Get_Size (win, h, w); |
| 66 | Get_Window_Position (win, by, bx); |
| 67 | sw := w / 3; |
| 68 | sh := h / 3; |
| 69 | subWin := Sub_Window (win, sh, sw, by + h - sh - 2, bx + w - sw - 2); |
| 70 | |
| 71 | if Has_Colors then |
| 72 | Init_Pair (2, Cyan, Blue); |
| 73 | Change_Background (subWin, |
| 74 | Attributed_Character'(Ch => ' ', Color => 2, |
| 75 | Attr => Normal_Video)); |
| 76 | end if; |
| 77 | |
| 78 | Set_Character_Attributes (subWin, |
| 79 | (Bold_Character => True, others => False)); |
| 80 | Box (subWin); |
| 81 | Add (subWin, 2, 1, "This is a subwindow"); |
| 82 | Refresh (win); |
| 83 | |
| 84 | Set_Cbreak_Mode (True); |
| 85 | Add (win, 0, 1, "This is a test of the flushinp() call."); |
| 86 | |
| 87 | Add (win, 2, 1, "Type random keys for 5 seconds."); |
| 88 | Add (win, 3, 1, |
| 89 | "These should be discarded (not echoed) after the subwindow " & |
| 90 | "goes away."); |
| 91 | Refresh (win); |
| 92 | |
| 93 | for i in 0 .. 4 loop |
| 94 | Move_Cursor (subWin, 1, 1); |
| 95 | Add (subWin, Str => "Time = "); |
| 96 | Add (subWin, Str => Integer'Image (i)); |
| 97 | Refresh (subWin); |
| 98 | Nap_Milli_Seconds (1000); |
| 99 | Flush_Input; |
| 100 | end loop; |
| 101 | |
| 102 | Delete (subWin); |
| 103 | Erase (win); |
| 104 | Flash_Screen; |
| 105 | Refresh (win); |
| 106 | Nap_Milli_Seconds (1000); |
| 107 | |
| 108 | Add (win, 2, 1, |
| 109 | Str => "If you were still typing when the window timer expired,"); |
| 110 | Add (win, 3, 1, |
| 111 | "or else you typed nothing at all while it was running,"); |
| 112 | Add (win, 4, 1, |
| 113 | "test was invalid. You'll see garbage or nothing at all. "); |
| 114 | Add (win, 6, 1, "Press a key"); |
| 115 | Move_Cursor (win, 9, 10); |
| 116 | Refresh (win); |
| 117 | Set_Echo_Mode (True); |
| 118 | Getchar (win); |
| 119 | Flush_Input; |
| 120 | Add (win, 12, 0, |
| 121 | "If you see any key other than what you typed, flushinp() is broken."); |
| 122 | Continue (win); |
| 123 | |
| 124 | Move_Cursor (win, 9, 10); |
| 125 | Delete_Character (win); |
| 126 | Refresh (win); |
| 127 | Move_Cursor (win, 12, 0); |
| 128 | Clear_To_End_Of_Line; |
| 129 | Add (win, |
| 130 | "What you typed should now have been deleted; if not, wdelch() " & |
| 131 | "failed."); |
| 132 | Continue (win); |
| 133 | |
| 134 | Set_Cbreak_Mode (True); |
| 135 | |
| 136 | end ncurses2.flushinp_test; |