1 ------------------------------------------------------------------------------
3 -- GNAT ncurses Binding --
5 -- Terminal_Interface.Curses.Text_IO --
9 ------------------------------------------------------------------------------
10 -- Copyright 2020 Thomas E. Dickey --
11 -- Copyright 1999-2011,2014 Free Software Foundation, Inc. --
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: --
21 -- The above copyright notice and this permission notice shall be included --
22 -- in all copies or substantial portions of the Software. --
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. --
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 --
36 ------------------------------------------------------------------------------
37 -- Author: Juergen Pfeifer, 1996
40 -- $Date: 2020/02/02 23:34:34 $
41 -- Binding Version 01.00
42 ------------------------------------------------------------------------------
43 package body Terminal_Interface.Curses.Text_IO is
45 Default_Window : Window := Null_Window;
47 procedure Set_Window (Win : Window)
50 Default_Window := Win;
53 function Get_Window return Window
56 if Default_Window = Null_Window then
57 return Standard_Window;
59 return Default_Window;
62 pragma Inline (Get_Window);
64 procedure Flush (Win : Window)
76 --------------------------------------------
77 -- Specification of line and page lengths --
78 --------------------------------------------
80 -- There are no set routines in this package. I assume, that you allocate
81 -- the window with an appropriate size.
82 -- A scroll-window is interpreted as an page with unbounded page length,
83 -- i.e. it returns the conventional 0 as page length.
85 function Line_Length (Win : Window) return Count
88 N_Cols : Column_Count;
90 Get_Size (Win, N_Lines, N_Cols);
91 -- if Natural (N_Cols) > Natural (Count'Last) then
92 -- raise Layout_Error;
94 return Count (N_Cols);
97 function Line_Length return Count
100 return Line_Length (Get_Window);
103 function Page_Length (Win : Window) return Count
105 N_Lines : Line_Count;
106 N_Cols : Column_Count;
108 if Scrolling_Allowed (Win) then
111 Get_Size (Win, N_Lines, N_Cols);
112 -- if Natural (N_Lines) > Natural (Count'Last) then
113 -- raise Layout_Error;
115 return Count (N_Lines);
119 function Page_Length return Count
122 return Page_Length (Get_Window);
125 ------------------------------------
126 -- Column, Line, and Page Control --
127 ------------------------------------
128 procedure New_Line (Win : Window; Spacing : Positive_Count := 1)
130 P_Size : constant Count := Page_Length (Win);
132 if not Spacing'Valid then
133 raise Constraint_Error;
136 for I in 1 .. Spacing loop
137 if P_Size > 0 and then Line (Win) >= P_Size then
145 procedure New_Line (Spacing : Positive_Count := 1)
148 New_Line (Get_Window, Spacing);
151 procedure New_Page (Win : Window)
160 New_Page (Get_Window);
163 procedure Set_Col (Win : Window; To : Positive_Count)
166 X1 : Column_Position;
167 X2 : Column_Position;
171 raise Constraint_Error;
174 Get_Cursor_Position (Win, Y, X1);
175 N := Natural (To); N := N - 1;
176 X2 := Column_Position (N);
183 Filler : constant String (Integer (X1) .. (Integer (X2) - 1))
191 procedure Set_Col (To : Positive_Count)
194 Set_Col (Get_Window, To);
197 procedure Set_Line (Win : Window; To : Positive_Count)
205 raise Constraint_Error;
208 Get_Cursor_Position (Win, Y1, X);
209 pragma Warnings (Off, X); -- unreferenced
210 N := Natural (To); N := N - 1;
211 Y2 := Line_Position (N);
217 New_Line (Win, Positive_Count (Y2 - Y1));
221 procedure Set_Line (To : Positive_Count)
224 Set_Line (Get_Window, To);
227 function Col (Win : Window) return Positive_Count
233 Get_Cursor_Position (Win, Y, X);
234 N := Natural (X); N := N + 1;
235 -- if N > Natural (Count'Last) then
236 -- raise Layout_Error;
238 return Positive_Count (N);
241 function Col return Positive_Count
244 return Col (Get_Window);
247 function Line (Win : Window) return Positive_Count
253 Get_Cursor_Position (Win, Y, X);
254 N := Natural (Y); N := N + 1;
255 -- if N > Natural (Count'Last) then
256 -- raise Layout_Error;
258 return Positive_Count (N);
261 function Line return Positive_Count
264 return Line (Get_Window);
267 -----------------------
268 -- Characters Output --
269 -----------------------
271 procedure Put (Win : Window; Item : Character)
273 P_Size : constant Count := Page_Length (Win);
280 Get_Cursor_Position (Win, Y, X);
281 Get_Size (Win, L, C);
282 if (Y + 1) = L and then (X + 1) = C then
289 procedure Put (Item : Character)
292 Put (Get_Window, Item);
299 procedure Put (Win : Window; Item : String)
301 P_Size : constant Count := Page_Length (Win);
308 Get_Cursor_Position (Win, Y, X);
309 Get_Size (Win, L, C);
310 if (Y + 1) = L and then (X + 1 + Item'Length) >= C then
317 procedure Put (Item : String)
320 Put (Get_Window, Item);
336 Put_Line (Get_Window, Item);
339 end Terminal_Interface.Curses.Text_IO;