1 ------------------------------------------------------------------------------
3 -- GNAT ncurses Binding --
5 -- Terminal_Interface.Curses.Text_IO --
9 ------------------------------------------------------------------------------
10 -- Copyright (c) 1998-2009,2011 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: 2011/03/22 23:38:49 $
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 : 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 : 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 : 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 : 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 : Window; Spacing : 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 : Positive_Count := 1)
147 New_Line (Get_Window, Spacing);
150 procedure New_Page (Win : Window)
159 New_Page (Get_Window);
162 procedure Set_Col (Win : Window; To : 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 : Positive_Count)
193 Set_Col (Get_Window, To);
196 procedure Set_Line (Win : Window; To : Positive_Count)
204 raise Constraint_Error;
207 Get_Cursor_Position (Win, Y1, X);
208 pragma Unreferenced (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 : Positive_Count)
223 Set_Line (Get_Window, To);
226 function Col (Win : 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
235 -- raise Layout_Error;
237 return Positive_Count (N);
240 function Col return Positive_Count
243 return Col (Get_Window);
246 function Line (Win : 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
255 -- raise Layout_Error;
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 : Window; Item : 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 : Character)
291 Put (Get_Window, Item);
298 procedure Put (Win : Window; Item : 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 : String)
319 Put (Get_Window, Item);
335 Put_Line (Get_Window, Item);
338 end Terminal_Interface.Curses.Text_IO;