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, 1996
39 -- Binding Version 01.00
40 ------------------------------------------------------------------------------
41 package body Terminal_Interface.Curses.Text_IO is
43 Default_Window : Window := Null_Window;
45 procedure Set_Window (Win : in Window)
48 Default_Window := Win;
51 function Get_Window return Window
54 if Default_Window = Null_Window then
55 return Standard_Window;
57 return Default_Window;
60 pragma Inline (Get_Window);
62 procedure Flush (Win : in Window)
74 --------------------------------------------
75 -- Specification of line and page lengths --
76 --------------------------------------------
78 -- There are no set routines in this package. I assume, that you allocate
79 -- the window with an appropriate size.
80 -- A scroll-window is interpreted as an page with unbounded page length,
81 -- i.e. it returns the conventional 0 as page length.
83 function Line_Length (Win : in Window) return Count
86 N_Cols : Column_Count;
88 Get_Size (Win, N_Lines, N_Cols);
89 if Natural (N_Cols) > Natural (Count'Last) then
92 return Count (N_Cols);
95 function Line_Length return Count
98 return Line_Length (Get_Window);
101 function Page_Length (Win : in Window) return Count
103 N_Lines : Line_Count;
104 N_Cols : Column_Count;
106 if Scrolling_Allowed (Win) then
109 Get_Size (Win, N_Lines, N_Cols);
110 if Natural (N_Lines) > Natural (Count'Last) then
113 return Count (N_Lines);
117 function Page_Length return Count
120 return Page_Length (Get_Window);
123 ------------------------------------
124 -- Column, Line, and Page Control --
125 ------------------------------------
126 procedure New_Line (Win : in Window; Spacing : in Positive_Count := 1)
128 P_Size : constant Count := Page_Length (Win);
130 if Spacing not in Positive_Count then
131 raise Constraint_Error;
134 for I in 1 .. Spacing loop
135 if P_Size > 0 and then Line (Win) >= P_Size then
143 procedure New_Line (Spacing : in Positive_Count := 1)
146 New_Line (Get_Window, Spacing);
149 procedure New_Page (Win : in Window)
158 New_Page (Get_Window);
161 procedure Set_Col (Win : in Window; To : in Positive_Count)
164 X1 : Column_Position;
165 X2 : Column_Position;
168 if To not in Positive_Count then
169 raise Constraint_Error;
172 Get_Cursor_Position (Win, Y, X1);
173 N := Natural (To); N := N - 1;
174 X2 := Column_Position (N);
181 Filler : constant String (Integer (X1) .. (Integer (X2) - 1))
189 procedure Set_Col (To : in Positive_Count)
192 Set_Col (Get_Window, To);
195 procedure Set_Line (Win : in Window; To : in Positive_Count)
202 if To not in Positive_Count then
203 raise Constraint_Error;
206 Get_Cursor_Position (Win, Y1, X);
207 N := Natural (To); N := N - 1;
208 Y2 := Line_Position (N);
214 New_Line (Win, Positive_Count (Y2 - Y1));
218 procedure Set_Line (To : in Positive_Count)
221 Set_Line (Get_Window, To);
224 function Col (Win : in Window) return Positive_Count
230 Get_Cursor_Position (Win, Y, X);
231 N := Natural (X); N := N + 1;
232 if N > Natural (Count'Last) then
235 return Positive_Count (N);
238 function Col return Positive_Count
241 return Col (Get_Window);
244 function Line (Win : in Window) return Positive_Count
250 Get_Cursor_Position (Win, Y, X);
251 N := Natural (Y); N := N + 1;
252 if N > Natural (Count'Last) then
255 return Positive_Count (N);
258 function Line return Positive_Count
261 return Line (Get_Window);
264 -----------------------
265 -- Characters Output --
266 -----------------------
268 procedure Put (Win : in Window; Item : in Character)
270 P_Size : constant Count := Page_Length (Win);
277 Get_Cursor_Position (Win, Y, X);
278 Get_Size (Win, L, C);
279 if (Y + 1) = L and then (X + 1) = C then
286 procedure Put (Item : in Character)
289 Put (Get_Window, Item);
296 procedure Put (Win : in Window; Item : in String)
298 P_Size : constant Count := Page_Length (Win);
305 Get_Cursor_Position (Win, Y, X);
306 Get_Size (Win, L, C);
307 if (Y + 1) = L and then (X + 1 + Item'Length) >= C then
314 procedure Put (Item : in String)
317 Put (Get_Window, Item);
333 Put_Line (Get_Window, Item);
336 end Terminal_Interface.Curses.Text_IO;