1 ------------------------------------------------------------------------------
3 -- GNAT ncurses Binding --
5 -- Terminal_Interface.Curses.Text_IO --
9 ------------------------------------------------------------------------------
10 -- Copyright (c) 1998-2004,2006 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, 1996
39 -- $Date: 2006/06/25 14:24:40 $
40 -- Binding Version 01.00
41 ------------------------------------------------------------------------------
42 package body Terminal_Interface.Curses.Text_IO is
44 Default_Window : Window := Null_Window;
46 procedure Set_Window (Win : in Window)
49 Default_Window := Win;
52 function Get_Window return Window
55 if Default_Window = Null_Window then
56 return Standard_Window;
58 return Default_Window;
61 pragma Inline (Get_Window);
63 procedure Flush (Win : in Window)
75 --------------------------------------------
76 -- Specification of line and page lengths --
77 --------------------------------------------
79 -- There are no set routines in this package. I assume, that you allocate
80 -- the window with an appropriate size.
81 -- A scroll-window is interpreted as an page with unbounded page length,
82 -- i.e. it returns the conventional 0 as page length.
84 function Line_Length (Win : in Window) return Count
87 N_Cols : Column_Count;
89 Get_Size (Win, N_Lines, N_Cols);
90 -- if Natural (N_Cols) > Natural (Count'Last) then
91 -- raise Layout_Error;
93 return Count (N_Cols);
96 function Line_Length return Count
99 return Line_Length (Get_Window);
102 function Page_Length (Win : in Window) return Count
104 N_Lines : Line_Count;
105 N_Cols : Column_Count;
107 if Scrolling_Allowed (Win) then
110 Get_Size (Win, N_Lines, N_Cols);
111 -- if Natural (N_Lines) > Natural (Count'Last) then
112 -- raise Layout_Error;
114 return Count (N_Lines);
118 function Page_Length return Count
121 return Page_Length (Get_Window);
124 ------------------------------------
125 -- Column, Line, and Page Control --
126 ------------------------------------
127 procedure New_Line (Win : in Window; Spacing : in Positive_Count := 1)
129 P_Size : constant Count := Page_Length (Win);
131 if not Spacing'Valid then
132 raise Constraint_Error;
135 for I in 1 .. Spacing loop
136 if P_Size > 0 and then Line (Win) >= P_Size then
144 procedure New_Line (Spacing : in Positive_Count := 1)
147 New_Line (Get_Window, Spacing);
150 procedure New_Page (Win : in Window)
159 New_Page (Get_Window);
162 procedure Set_Col (Win : in Window; To : in Positive_Count)
165 X1 : Column_Position;
166 X2 : Column_Position;
170 raise Constraint_Error;
173 Get_Cursor_Position (Win, Y, X1);
174 N := Natural (To); N := N - 1;
175 X2 := Column_Position (N);
182 Filler : constant String (Integer (X1) .. (Integer (X2) - 1))
190 procedure Set_Col (To : in Positive_Count)
193 Set_Col (Get_Window, To);
196 procedure Set_Line (Win : in Window; To : in Positive_Count)
204 raise Constraint_Error;
207 Get_Cursor_Position (Win, Y1, X);
208 N := Natural (To); N := N - 1;
209 Y2 := Line_Position (N);
215 New_Line (Win, Positive_Count (Y2 - Y1));
219 procedure Set_Line (To : in Positive_Count)
222 Set_Line (Get_Window, To);
225 function Col (Win : in Window) return Positive_Count
231 Get_Cursor_Position (Win, Y, X);
232 N := Natural (X); N := N + 1;
233 -- if N > Natural (Count'Last) then
234 -- raise Layout_Error;
236 return Positive_Count (N);
239 function Col return Positive_Count
242 return Col (Get_Window);
245 function Line (Win : in Window) return Positive_Count
251 Get_Cursor_Position (Win, Y, X);
252 N := Natural (Y); N := N + 1;
253 -- if N > Natural (Count'Last) then
254 -- raise Layout_Error;
256 return Positive_Count (N);
259 function Line return Positive_Count
262 return Line (Get_Window);
265 -----------------------
266 -- Characters Output --
267 -----------------------
269 procedure Put (Win : in Window; Item : in Character)
271 P_Size : constant Count := Page_Length (Win);
278 Get_Cursor_Position (Win, Y, X);
279 Get_Size (Win, L, C);
280 if (Y + 1) = L and then (X + 1) = C then
287 procedure Put (Item : in Character)
290 Put (Get_Window, Item);
297 procedure Put (Win : in Window; Item : in String)
299 P_Size : constant Count := Page_Length (Win);
306 Get_Cursor_Position (Win, Y, X);
307 Get_Size (Win, L, C);
308 if (Y + 1) = L and then (X + 1 + Item'Length) >= C then
315 procedure Put (Item : in String)
318 Put (Get_Window, Item);
334 Put_Line (Get_Window, Item);
337 end Terminal_Interface.Curses.Text_IO;