1 ------------------------------------------------------------------------------
3 -- GNAT ncurses Binding --
5 -- Terminal_Interface.Curses.Text_IO --
9 ------------------------------------------------------------------------------
10 -- Copyright (c) 1998 Free Software Foundation, Inc. --
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: --
20 -- The above copyright notice and this permission notice shall be included --
21 -- in all copies or substantial portions of the Software. --
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. --
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 --
35 ------------------------------------------------------------------------------
36 -- Author: Juergen Pfeifer <Juergen.Pfeifer@T-Online.de> 1996
39 -- Binding Version 00.93
40 ------------------------------------------------------------------------------
43 package body Terminal_Interface.Curses.Text_IO is
45 Default_Window : Window := Null_Window;
47 procedure Set_Window (Win : in 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 : in 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 : in 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
94 return Count (N_Cols);
97 function Line_Length return Count
100 return Line_Length (Get_Window);
103 function Page_Length (Win : in 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
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 : in Window; Spacing : in Positive_Count := 1)
130 P_Size : constant Count := Page_Length (Win);
132 if Spacing not in Positive_Count 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 : in Positive_Count := 1)
148 New_Line (Get_Window, Spacing);
151 procedure New_Page (Win : in Window)
160 New_Page (Get_Window);
163 procedure Set_Col (Win : in Window; To : in Positive_Count)
166 X1 : Column_Position;
167 X2 : Column_Position;
170 if To not in Positive_Count then
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 : in Positive_Count)
194 Set_Col (Get_Window, To);
197 procedure Set_Line (Win : in Window; To : in Positive_Count)
204 if To not in Positive_Count then
205 raise Constraint_Error;
208 Get_Cursor_Position (Win, Y1, X);
209 N := Natural (To); N := N - 1;
210 Y2 := Line_Position (N);
216 New_Line (Win, Positive_Count (Y2 - Y1));
220 procedure Set_Line (To : in Positive_Count)
223 Set_Line (Get_Window, To);
226 function Col (Win : in Window) return Positive_Count
232 Get_Cursor_Position (Win, Y, X);
233 N := Natural (X); N := N + 1;
234 if N > Natural (Count'Last) then
237 return Positive_Count (N);
240 function Col return Positive_Count
243 return Col (Get_Window);
246 function Line (Win : in Window) return Positive_Count
252 Get_Cursor_Position (Win, Y, X);
253 N := Natural (Y); N := N + 1;
254 if N > Natural (Count'Last) then
257 return Positive_Count (N);
260 function Line return Positive_Count
263 return Line (Get_Window);
266 -----------------------
267 -- Characters Output --
268 -----------------------
270 procedure Put (Win : in Window; Item : in Character)
272 P_Size : constant Count := Page_Length (Win);
279 Get_Cursor_Position (Win, Y, X);
280 Get_Size (Win, L, C);
281 if (Y + 1) = L and then (X + 1) = C then
288 procedure Put (Item : in Character)
291 Put (Get_Window, Item);
298 procedure Put (Win : in Window; Item : in String)
300 P_Size : constant Count := Page_Length (Win);
307 Get_Cursor_Position (Win, Y, X);
308 Get_Size (Win, L, C);
309 if (Y + 1) = L and then (X + 1 + Item'Length) >= C then
316 procedure Put (Item : in String)
319 Put (Get_Window, Item);
335 Put_Line (Get_Window, Item);
338 end Terminal_Interface.Curses.Text_IO;