1 ------------------------------------------------------------------------------
3 -- GNAT ncurses Binding --
5 -- Terminal_Interface.Curses.Text_IO --
11 -- The ncurses Ada95 binding is copyrighted 1996 by --
12 -- Juergen Pfeifer, Email: Juergen.Pfeifer@T-Online.de --
14 -- Permission is hereby granted to reproduce and distribute this --
15 -- binding by any means and for any fee, whether alone or as part --
16 -- of a larger distribution, in source or in binary form, PROVIDED --
17 -- this notice is included with any such distribution, and is not --
18 -- removed from any of its header files. Mention of ncurses and the --
19 -- author of this binding in any applications linked with it is --
20 -- highly appreciated. --
22 -- This binding comes AS IS with no warranty, implied or expressed. --
23 ------------------------------------------------------------------------------
26 ------------------------------------------------------------------------------
29 package body Terminal_Interface.Curses.Text_IO is
31 Default_Window : Window;
33 procedure Set_Window (Win : in Window)
36 Default_Window := Win;
39 function Get_Window return Window
42 if Default_Window = Null_Window then
43 return Standard_Window;
45 return Default_Window;
48 pragma Inline (Get_Window);
50 procedure Flush (Win : in Window)
62 --------------------------------------------
63 -- Specification of line and page lengths --
64 --------------------------------------------
66 -- There are no set routines in this package. I assume, that you allocate
67 -- the window with an appropriate size.
68 -- A scroll-window is interpreted as an page with unbounded page length,
69 -- i.e. it returns the conventional 0 as page length.
71 function Line_Length (Win : in Window) return Count
74 N_Cols : Column_Count;
76 Get_Size (Win, N_Lines, N_Cols);
77 if Natural (N_Cols) > Natural (Count'Last) then
80 return Count (N_Cols);
83 function Line_Length return Count
86 return Line_Length (Get_Window);
89 function Page_Length (Win : in Window) return Count
92 N_Cols : Column_Count;
94 if Scrolling_Allowed (Win) then
97 Get_Size (Win, N_Lines, N_Cols);
98 if Natural (N_Lines) > Natural (Count'Last) then
101 return Count (N_Lines);
105 function Page_Length return Count
108 return Page_Length (Get_Window);
111 ------------------------------------
112 -- Column, Line, and Page Control --
113 ------------------------------------
114 procedure New_Line (Win : in Window; Spacing : in Positive_Count := 1)
116 P_Size : constant Count := Page_Length (Win);
118 if Spacing not in Positive_Count then
119 raise Constraint_Error;
122 for I in 1 .. Spacing loop
123 if P_Size > 0 and then Line (Win) >= P_Size then
131 procedure New_Line (Spacing : in Positive_Count := 1)
134 New_Line (Get_Window, Spacing);
137 procedure New_Page (Win : in Window)
146 New_Page (Get_Window);
149 procedure Set_Col (Win : in Window; To : in Positive_Count)
152 X1 : Column_Position;
153 X2 : Column_Position;
156 if To not in Positive_Count then
157 raise Constraint_Error;
160 Get_Cursor_Position (Win, Y, X1);
161 N := Natural (To); N := N - 1;
162 X2 := Column_Position (N);
169 Filler : constant String (Integer (X1) .. (Integer (X2) - 1))
177 procedure Set_Col (To : in Positive_Count)
180 Set_Col (Get_Window, To);
183 procedure Set_Line (Win : in Window; To : in Positive_Count)
190 if To not in Positive_Count then
191 raise Constraint_Error;
194 Get_Cursor_Position (Win, Y1, X);
195 N := Natural (To); N := N - 1;
196 Y2 := Line_Position (N);
202 New_Line (Win, Positive_Count (Y2 - Y1));
206 procedure Set_Line (To : in Positive_Count)
209 Set_Line (Get_Window, To);
212 function Col (Win : in Window) return Positive_Count
218 Get_Cursor_Position (Win, Y, X);
219 N := Natural (X); N := N + 1;
220 if N > Natural (Count'Last) then
223 return Positive_Count (N);
226 function Col return Positive_Count
229 return Col (Get_Window);
232 function Line (Win : in Window) return Positive_Count
238 Get_Cursor_Position (Win, Y, X);
239 N := Natural (Y); N := N + 1;
240 if N > Natural (Count'Last) then
243 return Positive_Count (N);
246 function Line return Positive_Count
249 return Line (Get_Window);
252 -----------------------
253 -- Characters Output --
254 -----------------------
256 procedure Put (Win : in Window; Item : in Character)
258 P_Size : constant Count := Page_Length (Win);
265 Get_Cursor_Position (Win, Y, X);
266 Get_Size (Win, L, C);
267 if (Y + 1) = L and then (X + 1) = C then
274 procedure Put (Item : in Character)
277 Put (Get_Window, Item);
284 procedure Put (Win : in Window; Item : in String)
286 P_Size : constant Count := Page_Length (Win);
293 Get_Cursor_Position (Win, Y, X);
294 Get_Size (Win, L, C);
295 if (Y + 1) = L and then (X + 1 + Item'Length) >= C then
302 procedure Put (Item : in String)
305 Put (Get_Window, Item);
321 Put_Line (Get_Window, Item);
325 Default_Window := Null_Window;
327 end Terminal_Interface.Curses.Text_IO;