1 ------------------------------------------------------------------------------
3 -- GNAT ncurses Binding --
5 -- Terminal_Interface.Curses --
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 with Terminal_Interface.Curses.Aux; use Terminal_Interface.Curses.Aux;
44 with Interfaces.C; use Interfaces.C;
45 with Interfaces.C.Strings; use Interfaces.C.Strings;
46 with Ada.Characters.Handling; use Ada.Characters.Handling;
47 with Ada.Strings.Fixed;
48 with Unchecked_Conversion;
50 package body Terminal_Interface.Curses is
52 use type System.Bit_Order;
54 package ASF renames Ada.Strings.Fixed;
56 type chtype_array is array (size_t range <>)
57 of aliased Attributed_Character;
58 pragma Convention (C, chtype_array);
60 ------------------------------------------------------------------------------
61 function Key_Name (Key : in Real_Key_Code) return String
63 function Keyname (K : C_Int) return chars_ptr;
64 pragma Import (C, Keyname, "keyname");
68 if Key <= Character'Pos (Character'Last) then
69 Ch := Character'Val (Key);
70 if Is_Control (Ch) then
71 return Un_Control (Attributed_Character'(Ch => Ch,
72 Color => Color_Pair'First,
73 Attr => Normal_Video));
74 elsif Is_Graphic (Ch) then
85 return Fill_String (Keyname (C_Int (Key)));
89 procedure Key_Name (Key : in Real_Key_Code;
93 ASF.Move (Key_Name (Key), Name);
96 ------------------------------------------------------------------------------
99 function Initscr return Window;
100 pragma Import (C, Initscr, "initscr");
102 function Check_Version (Major, Minor : C_Int) return C_Int;
103 pragma Import (C, Check_Version, "_nc_ada_vcheck");
107 if (Check_Version (NC_Major_Version, NC_Minor_Version) = 0) then
108 raise Wrong_Curses_Version;
111 if W = Null_Window then
112 raise Curses_Exception;
117 procedure End_Windows
119 function Endwin return C_Int;
120 pragma Import (C, Endwin, "endwin");
122 if Endwin = Curses_Err then
123 raise Curses_Exception;
127 function Is_End_Window return Boolean
129 function Isendwin return C_Int;
130 pragma Import (C, Isendwin, "isendwin");
132 if Isendwin = Curses_False then
138 ------------------------------------------------------------------------------
139 procedure Move_Cursor (Win : in Window := Standard_Window;
140 Line : in Line_Position;
141 Column : in Column_Position)
143 function Wmove (Win : Window;
147 pragma Import (C, Wmove, "wmove");
149 if Wmove (Win, C_Int (Line), C_Int (Column)) = Curses_Err then
150 raise Curses_Exception;
153 ------------------------------------------------------------------------------
154 procedure Add (Win : in Window := Standard_Window;
155 Ch : in Attributed_Character)
157 function Waddch (W : Window;
158 Ch : C_Int) return C_Int;
159 pragma Import (C, Waddch, "waddch");
161 if Waddch (Win, Chtype_To_Cint (Ch)) = Curses_Err then
162 raise Curses_Exception;
166 procedure Add (Win : in Window := Standard_Window;
171 Attributed_Character'(Ch => Ch,
172 Color => Color_Pair'First,
173 Attr => Normal_Video));
177 (Win : in Window := Standard_Window;
178 Line : in Line_Position;
179 Column : in Column_Position;
180 Ch : in Attributed_Character)
182 function mvwaddch (W : Window;
185 Ch : C_Int) return C_Int;
186 pragma Import (C, mvwaddch, "mvwaddch");
188 if mvwaddch (Win, C_Int (Line),
190 Chtype_To_CInt (Ch)) = Curses_Err then
191 raise Curses_Exception;
196 (Win : in Window := Standard_Window;
197 Line : in Line_Position;
198 Column : in Column_Position;
205 Attributed_Character'(Ch => Ch,
206 Color => Color_Pair'First,
207 Attr => Normal_Video));
210 procedure Add_With_Immediate_Echo
211 (Win : in Window := Standard_Window;
212 Ch : in Attributed_Character)
214 function Wechochar (W : Window;
215 Ch : C_Int) return C_Int;
216 pragma Import (C, Wechochar, "wechochar");
218 if Wechochar (Win, Chtype_To_CInt (Ch)) = Curses_Err then
219 raise Curses_Exception;
221 end Add_With_Immediate_Echo;
223 procedure Add_With_Immediate_Echo
224 (Win : in Window := Standard_Window;
228 Add_With_Immediate_Echo
230 Attributed_Character'(Ch => Ch,
231 Color => Color_Pair'First,
232 Attr => Normal_Video));
233 end Add_With_Immediate_Echo;
234 ------------------------------------------------------------------------------
235 function Create (Number_Of_Lines : Line_Count;
236 Number_Of_Columns : Column_Count;
237 First_Line_Position : Line_Position;
238 First_Column_Position : Column_Position) return Window
240 function Newwin (Number_Of_Lines : C_Int;
241 Number_Of_Columns : C_Int;
242 First_Line_Position : C_Int;
243 First_Column_Position : C_Int) return Window;
244 pragma Import (C, Newwin, "newwin");
248 W := Newwin (C_Int (Number_Of_Lines),
249 C_Int (Number_Of_Columns),
250 C_Int (First_Line_Position),
251 C_Int (First_Column_Position));
252 if W = Null_Window then
253 raise Curses_Exception;
258 procedure Delete (Win : in out Window)
260 function Wdelwin (W : Window) return C_Int;
261 pragma Import (C, Wdelwin, "delwin");
263 if Wdelwin (Win) = Curses_Err then
264 raise Curses_Exception;
270 (Win : Window := Standard_Window;
271 Number_Of_Lines : Line_Count;
272 Number_Of_Columns : Column_Count;
273 First_Line_Position : Line_Position;
274 First_Column_Position : Column_Position) return Window
278 Number_Of_Lines : C_Int;
279 Number_Of_Columns : C_Int;
280 First_Line_Position : C_Int;
281 First_Column_Position : C_Int) return Window;
282 pragma Import (C, Subwin, "subwin");
287 C_Int (Number_Of_Lines),
288 C_Int (Number_Of_Columns),
289 C_Int (First_Line_Position),
290 C_Int (First_Column_Position));
291 if W = Null_Window then
292 raise Curses_Exception;
297 function Derived_Window
298 (Win : Window := Standard_Window;
299 Number_Of_Lines : Line_Count;
300 Number_Of_Columns : Column_Count;
301 First_Line_Position : Line_Position;
302 First_Column_Position : Column_Position) return Window
306 Number_Of_Lines : C_Int;
307 Number_Of_Columns : C_Int;
308 First_Line_Position : C_Int;
309 First_Column_Position : C_Int) return Window;
310 pragma Import (C, Derwin, "derwin");
315 C_Int (Number_Of_Lines),
316 C_Int (Number_Of_Columns),
317 C_Int (First_Line_Position),
318 C_Int (First_Column_Position));
319 if W = Null_Window then
320 raise Curses_Exception;
325 function Duplicate (Win : Window) return Window
327 function Dupwin (Win : Window) return Window;
328 pragma Import (C, Dupwin, "dupwin");
330 W : Window := Dupwin (Win);
332 if W = Null_Window then
333 raise Curses_Exception;
338 procedure Move_Window (Win : in Window;
339 Line : in Line_Position;
340 Column : in Column_Position)
342 function Mvwin (Win : Window;
344 Column : C_Int) return C_Int;
345 pragma Import (C, Mvwin, "mvwin");
347 if Mvwin (Win, C_Int (Line), C_Int (Column)) = Curses_Err then
348 raise Curses_Exception;
352 procedure Move_Derived_Window (Win : in Window;
353 Line : in Line_Position;
354 Column : in Column_Position)
356 function Mvderwin (Win : Window;
358 Column : C_Int) return C_Int;
359 pragma Import (C, Mvderwin, "mvderwin");
361 if Mvderwin (Win, C_Int (Line), C_Int (Column)) = Curses_Err then
362 raise Curses_Exception;
364 end Move_Derived_Window;
366 procedure Set_Synch_Mode (Win : in Window := Standard_Window;
367 Mode : in Boolean := False)
369 function Syncok (Win : Window;
370 Mode : C_Int) return C_Int;
371 pragma Import (C, Syncok, "syncok");
373 if Syncok (Win, Boolean'Pos (Mode)) = Curses_Err then
374 raise Curses_Exception;
377 ------------------------------------------------------------------------------
378 procedure Add (Win : in Window := Standard_Window;
380 Len : in Integer := -1)
382 type Char_Ptr is access all Interfaces.C.Char;
383 function Waddnstr (Win : Window;
385 Len : C_Int := -1) return C_Int;
386 pragma Import (C, Waddnstr, "waddnstr");
388 Txt : char_array (0 .. Str'Length);
391 To_C (Str, Txt, Length);
392 if Waddnstr (Win, Txt (Txt'First)'Access, C_Int (Len)) = Curses_Err then
393 raise Curses_Exception;
398 (Win : in Window := Standard_Window;
399 Line : in Line_Position;
400 Column : in Column_Position;
402 Len : in Integer := -1)
405 Move_Cursor (Win, Line, Column);
408 ------------------------------------------------------------------------------
410 (Win : in Window := Standard_Window;
411 Str : in Attributed_String;
412 Len : in Integer := -1)
414 type Chtype_Ptr is access all Attributed_Character;
415 function Waddchnstr (Win : Window;
417 Len : C_Int := -1) return C_Int;
418 pragma Import (C, Waddchnstr, "waddchnstr");
420 Txt : chtype_array (0 .. Str'Length);
422 for Length in 1 .. size_t (Str'Length) loop
423 Txt (Length - 1) := Str (Natural (Length));
425 Txt (Str'Length) := Default_Character;
427 Txt (Txt'First)'Access,
428 C_Int (Len)) = Curses_Err then
429 raise Curses_Exception;
434 (Win : in Window := Standard_Window;
435 Line : in Line_Position;
436 Column : in Column_Position;
437 Str : in Attributed_String;
438 Len : in Integer := -1)
441 Move_Cursor (Win, Line, Column);
444 ------------------------------------------------------------------------------
446 (Win : in Window := Standard_Window;
447 Left_Side_Symbol : in Attributed_Character := Default_Character;
448 Right_Side_Symbol : in Attributed_Character := Default_Character;
449 Top_Side_Symbol : in Attributed_Character := Default_Character;
450 Bottom_Side_Symbol : in Attributed_Character := Default_Character;
451 Upper_Left_Corner_Symbol : in Attributed_Character := Default_Character;
452 Upper_Right_Corner_Symbol : in Attributed_Character := Default_Character;
453 Lower_Left_Corner_Symbol : in Attributed_Character := Default_Character;
454 Lower_Right_Corner_Symbol : in Attributed_Character := Default_Character)
456 function Wborder (W : Window;
464 LRC : C_Int) return C_Int;
465 pragma Import (C, Wborder, "wborder");
468 Chtype_To_CInt (Left_Side_Symbol),
469 Chtype_To_CInt (Right_Side_Symbol),
470 Chtype_To_CInt (Top_Side_Symbol),
471 Chtype_To_CInt (Bottom_Side_Symbol),
472 Chtype_To_CInt (Upper_Left_Corner_Symbol),
473 Chtype_To_CInt (Upper_Right_Corner_Symbol),
474 Chtype_To_CInt (Lower_Left_Corner_Symbol),
475 Chtype_To_CInt (Lower_Right_Corner_Symbol)
478 raise Curses_Exception;
483 (Win : in Window := Standard_Window;
484 Vertical_Symbol : in Attributed_Character := Default_Character;
485 Horizontal_Symbol : in Attributed_Character := Default_Character)
489 Vertical_Symbol, Vertical_Symbol,
490 Horizontal_Symbol, Horizontal_Symbol);
493 procedure Horizontal_Line
494 (Win : in Window := Standard_Window;
495 Line_Size : in Natural;
496 Line_Symbol : in Attributed_Character := Default_Character)
498 function Whline (W : Window;
500 Len : C_Int) return C_Int;
501 pragma Import (C, Whline, "whline");
504 Chtype_To_CInt (Line_Symbol),
505 C_Int (Line_Size)) = Curses_Err then
506 raise Curses_Exception;
510 procedure Vertical_Line
511 (Win : in Window := Standard_Window;
512 Line_Size : in Natural;
513 Line_Symbol : in Attributed_Character := Default_Character)
515 function Wvline (W : Window;
517 Len : C_Int) return C_Int;
518 pragma Import (C, Wvline, "wvline");
521 Chtype_To_CInt (Line_Symbol),
522 C_Int (Line_Size)) = Curses_Err then
523 raise Curses_Exception;
527 ------------------------------------------------------------------------------
528 function Get_Keystroke (Win : Window := Standard_Window)
531 function Wgetch (W : Window) return C_Int;
532 pragma Import (C, Wgetch, "wgetch");
534 C : constant C_Int := Wgetch (Win);
536 if C = Curses_Err then
539 return Real_Key_Code (C);
543 procedure Undo_Keystroke (Key : in Real_Key_Code)
545 function Ungetch (Ch : C_Int) return C_Int;
546 pragma Import (C, Ungetch, "ungetch");
548 if Ungetch (C_Int (Key)) = Curses_Err then
549 raise Curses_Exception;
553 function Has_Key (Key : Special_Key_Code) return Boolean
555 function Haskey (Key : C_Int) return C_Int;
556 pragma Import (C, Haskey, "has_key");
558 if Haskey (C_Int (Key)) = Curses_False then
565 function Is_Function_Key (Key : Special_Key_Code) return Boolean
567 L : constant Special_Key_Code := Special_Key_Code (Natural (Key_F0) +
568 Natural (Function_Key_Number'Last));
570 if (Key >= Key_F0) and then (Key <= L) then
577 function Function_Key (Key : Real_Key_Code)
578 return Function_Key_Number
581 if Is_Function_Key (Key) then
582 return Function_Key_Number (Key - Key_F0);
584 raise Constraint_Error;
588 function Function_Key_Code (Key : Function_Key_Number) return Real_Key_Code
591 return Real_Key_Code (Natural (Key_F0) + Natural (Key));
592 end Function_Key_Code;
593 ------------------------------------------------------------------------------
594 procedure Switch_Character_Attribute
595 (Win : in Window := Standard_Window;
596 Attr : in Character_Attribute_Set := Normal_Video;
597 On : in Boolean := True)
599 function Wattron (Win : Window;
600 C_Attr : C_Int) return C_Int;
601 pragma Import (C, Wattron, "wattr_on");
602 function Wattroff (Win : Window;
603 C_Attr : C_Int) return C_Int;
604 pragma Import (C, Wattroff, "wattr_off");
605 -- In Ada we use the On Boolean to control whether or not we want to
606 -- switch on or off the attributes in the set.
608 AC : constant Attributed_Character := (Ch => Character'First,
609 Color => Color_Pair'First,
613 Err := Wattron (Win, Chtype_To_CInt (AC));
615 Err := Wattroff (Win, Chtype_To_CInt (AC));
617 if Err = Curses_Err then
618 raise Curses_Exception;
620 end Switch_Character_Attribute;
622 procedure Set_Character_Attributes
623 (Win : in Window := Standard_Window;
624 Attr : in Character_Attribute_Set := Normal_Video;
625 Color : in Color_Pair := Color_Pair'First)
627 function Wattrset (Win : Window;
628 C_Attr : C_Int) return C_Int;
629 pragma Import (C, Wattrset, "wattrset"); -- ??? wattr_set
632 Chtype_To_CInt (Attributed_Character'
633 (Ch => Character'First,
635 Attr => Attr))) = Curses_Err then
636 raise Curses_Exception;
638 end Set_Character_Attributes;
640 function Get_Character_Attribute (Win : Window := Standard_Window)
641 return Character_Attribute_Set
643 function Wattrget (Win : Window) return C_Int;
644 pragma Import (C, Wattrget, "wattr_get");
646 Ch : Attributed_Character := CInt_To_Chtype (Wattrget (Win));
649 end Get_Character_Attribute;
651 function Get_Character_Attribute (Win : Window := Standard_Window)
654 function Wattrget (Win : Window) return C_Int;
655 pragma Import (C, Wattrget, "wattr_get");
657 Ch : Attributed_Character := CInt_To_Chtype (Wattrget (Win));
660 end Get_Character_Attribute;
662 procedure Change_Attributes
663 (Win : in Window := Standard_Window;
664 Count : in Integer := -1;
665 Attr : in Character_Attribute_Set := Normal_Video;
666 Color : in Color_Pair := Color_Pair'First)
668 function Wchgat (Win : Window;
672 Opts : System.Address := System.Null_Address)
674 pragma Import (C, Wchgat, "wchgat");
676 Ch : constant Attributed_Character :=
677 (Ch => Character'First, Color => Color_Pair'First, Attr => Attr);
679 if Wchgat (Win, C_Int (Count), Chtype_To_CInt (Ch),
680 C_Short (Color)) = Curses_Err then
681 raise Curses_Exception;
683 end Change_Attributes;
685 procedure Change_Attributes
686 (Win : in Window := Standard_Window;
687 Line : in Line_Position := Line_Position'First;
688 Column : in Column_Position := Column_Position'First;
689 Count : in Integer := -1;
690 Attr : in Character_Attribute_Set := Normal_Video;
691 Color : in Color_Pair := Color_Pair'First)
694 Move_Cursor (Win, Line, Column);
695 Change_Attributes (Win, Count, Attr, Color);
696 end Change_Attributes;
697 ------------------------------------------------------------------------------
700 function Beeper return C_Int;
701 pragma Import (C, Beeper, "beep");
703 if Beeper = Curses_Err then
704 raise Curses_Exception;
708 procedure Flash_Screen
710 function Flash return C_Int;
711 pragma Import (C, Flash, "flash");
713 if Flash = Curses_Err then
714 raise Curses_Exception;
717 ------------------------------------------------------------------------------
718 procedure Set_Cbreak_Mode (SwitchOn : in Boolean := True)
720 function Cbreak return C_Int;
721 pragma Import (C, Cbreak, "cbreak");
722 function NoCbreak return C_Int;
723 pragma Import (C, NoCbreak, "nocbreak");
732 if Err = Curses_Err then
733 raise Curses_Exception;
737 procedure Set_Raw_Mode (SwitchOn : in Boolean := True)
739 function Raw return C_Int;
740 pragma Import (C, Raw, "raw");
741 function NoRaw return C_Int;
742 pragma Import (C, NoRaw, "noraw");
751 if Err = Curses_Err then
752 raise Curses_Exception;
756 procedure Set_Echo_Mode (SwitchOn : in Boolean := True)
758 function Echo return C_Int;
759 pragma Import (C, Echo, "echo");
760 function NoEcho return C_Int;
761 pragma Import (C, NoEcho, "noecho");
770 if Err = Curses_Err then
771 raise Curses_Exception;
775 procedure Set_Meta_Mode (Win : in Window := Standard_Window;
776 SwitchOn : in Boolean := True)
778 function Meta (W : Window; Mode : C_Int) return C_Int;
779 pragma Import (C, Meta, "meta");
781 if Meta (Win, Boolean'Pos (SwitchOn)) = Curses_Err then
782 raise Curses_Exception;
786 procedure Set_KeyPad_Mode (Win : in Window := Standard_Window;
787 SwitchOn : in Boolean := True)
789 function Keypad (W : Window; Mode : C_Int) return C_Int;
790 pragma Import (C, Keypad, "keypad");
792 if Keypad (Win, Boolean'Pos (SwitchOn)) = Curses_Err then
793 raise Curses_Exception;
797 procedure Half_Delay (Amount : in Half_Delay_Amount)
799 function Halfdelay (Amount : C_Int) return C_Int;
800 pragma Import (C, Halfdelay, "halfdelay");
802 if Halfdelay (C_Int (Amount)) = Curses_Err then
803 raise Curses_Exception;
807 procedure Set_Flush_On_Interrupt_Mode
808 (Win : in Window := Standard_Window;
809 Mode : in Boolean := True)
811 function Intrflush (Win : Window; Mode : C_Int) return C_Int;
812 pragma Import (C, Intrflush, "intrflush");
814 if Intrflush (Win, Boolean'Pos (Mode)) = Curses_Err then
815 raise Curses_Exception;
817 end Set_Flush_On_Interrupt_Mode;
819 procedure Set_Queue_Interrupt_Mode
820 (Win : in Window := Standard_Window;
821 Flush : in Boolean := True)
824 pragma Import (C, Qiflush, "qiflush");
825 procedure No_Qiflush;
826 pragma Import (C, No_Qiflush, "noqiflush");
833 end Set_Queue_Interrupt_Mode;
835 procedure Set_NoDelay_Mode
836 (Win : in Window := Standard_Window;
837 Mode : in Boolean := False)
839 function Nodelay (Win : Window; Mode : C_Int) return C_Int;
840 pragma Import (C, Nodelay, "nodelay");
842 if Nodelay (Win, Boolean'Pos (Mode)) = Curses_Err then
843 raise Curses_Exception;
845 end Set_NoDelay_Mode;
847 procedure Set_Timeout_Mode (Win : in Window := Standard_Window;
848 Mode : in Timeout_Mode;
851 function Wtimeout (Win : Window; Amount : C_Int) return C_Int;
852 pragma Import (C, Wtimeout, "wtimeout");
857 when Blocking => Time := -1;
858 when Non_Blocking => Time := 0;
861 raise CONSTRAINT_ERROR;
863 Time := C_Int (Amount);
865 if Wtimeout (Win, Time) = Curses_Err then
866 raise Curses_Exception;
868 end Set_Timeout_Mode;
870 procedure Set_Escape_Timer_Mode
871 (Win : in Window := Standard_Window;
872 Timer_Off : in Boolean := False)
874 function Notimeout (Win : Window; Mode : C_Int) return C_Int;
875 pragma Import (C, Notimeout, "notimeout");
877 if Notimeout (Win, Boolean'Pos (Timer_Off)) = Curses_Err then
878 raise Curses_Exception;
880 end Set_Escape_Timer_Mode;
882 ------------------------------------------------------------------------------
883 procedure Set_NL_Mode (SwitchOn : in Boolean := True)
885 function NL return C_Int;
886 pragma Import (C, NL, "nl");
887 function NoNL return C_Int;
888 pragma Import (C, NoNL, "nonl");
897 if Err = Curses_Err then
898 raise Curses_Exception;
902 procedure Clear_On_Next_Update
903 (Win : in Window := Standard_Window;
904 Do_Clear : in Boolean := True)
906 function Clear_Ok (W : Window; Flag : C_Int) return C_Int;
907 pragma Import (C, Clear_Ok, "clearok");
909 if Clear_Ok (Win, Boolean'Pos (Do_Clear)) = Curses_Err then
910 raise Curses_Exception;
912 end Clear_On_Next_Update;
914 procedure Use_Insert_Delete_Line
915 (Win : in Window := Standard_Window;
916 Do_Idl : in Boolean := True)
918 function IDL_Ok (W : Window; Flag : C_Int) return C_Int;
919 pragma Import (C, IDL_Ok, "idlok");
921 if IDL_Ok (Win, Boolean'Pos (Do_Idl)) = Curses_Err then
922 raise Curses_Exception;
924 end Use_Insert_Delete_Line;
926 procedure Use_Insert_Delete_Character
927 (Win : in Window := Standard_Window;
928 Do_Idc : in Boolean := True)
930 function IDC_Ok (W : Window; Flag : C_Int) return C_Int;
931 pragma Import (C, IDC_Ok, "idcok");
933 if IDC_Ok (Win, Boolean'Pos (Do_Idc)) = Curses_Err then
934 raise Curses_Exception;
936 end Use_Insert_Delete_Character;
938 procedure Leave_Cursor_After_Update
939 (Win : in Window := Standard_Window;
940 Do_Leave : in Boolean := True)
942 function Leave_Ok (W : Window; Flag : C_Int) return C_Int;
943 pragma Import (C, Leave_Ok, "leaveok");
945 if Leave_Ok (Win, Boolean'Pos (Do_Leave)) = Curses_Err then
946 raise Curses_Exception;
948 end Leave_Cursor_After_Update;
950 procedure Immediate_Update_Mode
951 (Win : in Window := Standard_Window;
952 Mode : in Boolean := False)
954 function Immedok (Win : Window; Mode : C_Int) return C_Int;
955 pragma Import (C, Immedok, "immedok");
957 if Immedok (Win, Boolean'Pos (Mode)) = Curses_Err then
958 raise Curses_Exception;
960 end Immediate_Update_Mode;
962 procedure Allow_Scrolling
963 (Win : in Window := Standard_Window;
964 Mode : in Boolean := False)
966 function Scrollok (Win : Window; Mode : C_Int) return C_Int;
967 pragma Import (C, Scrollok, "scrollok");
969 if Scrollok (Win, Boolean'Pos (Mode)) = Curses_Err then
970 raise Curses_Exception;
974 function Scrolling_Allowed (Win : Window := Standard_Window) return Boolean
976 function Is_Scroll (Win : Window) return C_Int;
977 pragma Import (C, Is_Scroll, "_nc_ada_isscroll");
979 Res : constant C_Int := Is_Scroll (Win);
982 when Curses_True => return True;
983 when Curses_False => return False;
984 when others => raise Curses_Exception;
986 end Scrolling_Allowed;
988 procedure Set_Scroll_Region
989 (Win : in Window := Standard_Window;
990 Top_Line : in Line_Position;
991 Bottom_Line : in Line_Position)
993 function Wsetscrreg (Win : Window;
995 Col : C_Int) return C_Int;
996 pragma Import (C, Wsetscrreg, "wsetscrreg");
998 if Wsetscrreg (Win, C_Int (Top_Line), C_Int (Bottom_Line))
1000 raise Curses_Exception;
1002 end Set_Scroll_Region;
1003 ------------------------------------------------------------------------------
1004 procedure Update_Screen
1006 function Do_Update return C_Int;
1007 pragma Import (C, Do_Update, "doupdate");
1009 if Do_Update = Curses_Err then
1010 raise Curses_Exception;
1014 procedure Refresh (Win : in Window := Standard_Window)
1016 function Wrefresh (W : Window) return C_Int;
1017 pragma Import (C, Wrefresh, "wrefresh");
1019 if Wrefresh (Win) = Curses_Err then
1020 raise Curses_Exception;
1024 procedure Refresh_Without_Update
1025 (Win : in Window := Standard_Window)
1027 function Wnoutrefresh (W : Window) return C_Int;
1028 pragma Import (C, Wnoutrefresh, "wnoutrefresh");
1030 if Wnoutrefresh (Win) = Curses_Err then
1031 raise Curses_Exception;
1033 end Refresh_Without_Update;
1035 procedure Redraw (Win : in Window := Standard_Window)
1037 function Redrawwin (Win : Window) return C_Int;
1038 pragma Import (C, Redrawwin, "redrawwin");
1040 if Redrawwin (Win) = Curses_Err then
1041 raise Curses_Exception;
1046 (Win : in Window := Standard_Window;
1047 Begin_Line : in Line_Position;
1048 Line_Count : in Positive)
1050 function Wredrawln (Win : Window; First : C_Int; Cnt : C_Int)
1052 pragma Import (C, Wredrawln, "wredrawln");
1056 C_Int (Line_Count)) = Curses_Err then
1057 raise Curses_Exception;
1061 ------------------------------------------------------------------------------
1062 procedure Erase (Win : in Window := Standard_Window)
1064 function Werase (W : Window) return C_Int;
1065 pragma Import (C, Werase, "werase");
1067 if Werase (Win) = Curses_Err then
1068 raise Curses_Exception;
1072 procedure Clear (Win : in Window := Standard_Window)
1074 function Wclear (W : Window) return C_Int;
1075 pragma Import (C, Wclear, "wclear");
1077 if Wclear (Win) = Curses_Err then
1078 raise Curses_Exception;
1082 procedure Clear_To_End_Of_Screen (Win : in Window := Standard_Window)
1084 function Wclearbot (W : Window) return C_Int;
1085 pragma Import (C, Wclearbot, "wclrtobot");
1087 if Wclearbot (Win) = Curses_Err then
1088 raise Curses_Exception;
1090 end Clear_To_End_Of_Screen;
1092 procedure Clear_To_End_Of_Line (Win : in Window := Standard_Window)
1094 function Wcleareol (W : Window) return C_Int;
1095 pragma Import (C, Wcleareol, "wclrtoeol");
1097 if Wcleareol (Win) = Curses_Err then
1098 raise Curses_Exception;
1100 end Clear_To_End_Of_Line;
1101 ------------------------------------------------------------------------------
1102 procedure Set_Background
1103 (Win : in Window := Standard_Window;
1104 Ch : in Attributed_Character)
1106 procedure WBackground (W : in Window; Ch : in C_Int);
1107 pragma Import (C, WBackground, "wbkgdset");
1109 WBackground (Win, Chtype_To_CInt (Ch));
1112 procedure Change_Background
1113 (Win : in Window := Standard_Window;
1114 Ch : in Attributed_Character)
1116 function WChangeBkgd (W : Window; Ch : C_Int)
1118 pragma Import (C, WChangeBkgd, "wbkgd");
1120 if WChangeBkgd (Win, Chtype_To_CInt (Ch)) = Curses_Err then
1121 raise Curses_Exception;
1123 end Change_Background;
1125 function Get_Background (Win : Window := Standard_Window)
1126 return Attributed_Character
1128 function Wgetbkgd (Win : Window) return C_Int;
1129 pragma Import (C, Wgetbkgd, "getbkgd");
1131 return CInt_To_Chtype (Wgetbkgd (Win));
1133 ------------------------------------------------------------------------------
1134 procedure Change_Lines_Status (Win : in Window := Standard_Window;
1135 Start : in Line_Position;
1136 Count : in Positive;
1139 function Wtouchln (Win : Window;
1142 Chg : C_Int) return C_Int;
1143 pragma Import (C, Wtouchln, "wtouchln");
1145 if Wtouchln (Win, C_Int (Start), C_Int (Count),
1146 C_Int (Boolean'Pos (State))) = Curses_Err then
1147 raise Curses_Exception;
1149 end Change_Lines_Status;
1151 procedure Touch (Win : in Window := Standard_Window)
1154 X : Column_Position;
1156 Get_Size (Win, Y, X);
1157 Change_Lines_Status (Win, 0, Positive (Y), True);
1160 procedure Untouch (Win : in Window := Standard_Window)
1163 X : Column_Position;
1165 Get_Size (Win, Y, X);
1166 Change_Lines_Status (Win, 0, Positive (Y), False);
1169 procedure Touch (Win : in Window := Standard_Window;
1170 Start : in Line_Position;
1171 Count : in Positive)
1174 Change_Lines_Status (Win, Start, Count, True);
1178 (Win : Window := Standard_Window;
1179 Line : Line_Position) return Boolean
1181 function WLineTouched (W : Window; L : C_Int) return C_Int;
1182 pragma Import (C, WLineTouched, "is_linetouched");
1184 if WLineTouched (Win, C_Int (Line)) = Curses_False then
1192 (Win : Window := Standard_Window) return Boolean
1194 function WWinTouched (W : Window) return C_Int;
1195 pragma Import (C, WWinTouched, "is_wintouched");
1197 if WWinTouched (Win) = Curses_False then
1203 ------------------------------------------------------------------------------
1205 (Source_Window : in Window;
1206 Destination_Window : in Window;
1207 Source_Top_Row : in Line_Position;
1208 Source_Left_Column : in Column_Position;
1209 Destination_Top_Row : in Line_Position;
1210 Destination_Left_Column : in Column_Position;
1211 Destination_Bottom_Row : in Line_Position;
1212 Destination_Right_Column : in Column_Position;
1213 Non_Destructive_Mode : in Boolean := True)
1215 function Copywin (Src : Window;
1223 Ndm : C_Int) return C_Int;
1224 pragma Import (C, Copywin, "copywin");
1226 if Copywin (Source_Window,
1228 C_Int (Source_Top_Row),
1229 C_Int (Source_Left_Column),
1230 C_Int (Destination_Top_Row),
1231 C_Int (Destination_Left_Column),
1232 C_Int (Destination_Bottom_Row),
1233 C_Int (Destination_Right_Column),
1234 Boolean'Pos (Non_Destructive_Mode)
1236 raise Curses_Exception;
1241 (Source_Window : in Window;
1242 Destination_Window : in Window)
1244 function Overwrite (Src : Window; Dst : Window) return C_Int;
1245 pragma Import (C, Overwrite, "overwrite");
1247 if Overwrite (Source_Window, Destination_Window) = Curses_Err then
1248 raise Curses_Exception;
1253 (Source_Window : in Window;
1254 Destination_Window : in Window)
1256 function Overlay (Src : Window; Dst : Window) return C_Int;
1257 pragma Import (C, Overlay, "overlay");
1259 if Overlay (Source_Window, Destination_Window) = Curses_Err then
1260 raise Curses_Exception;
1264 ------------------------------------------------------------------------------
1265 procedure Insert_Delete_Lines
1266 (Win : in Window := Standard_Window;
1267 Lines : in Integer := 1) -- default is to insert one line above
1269 function Winsdelln (W : Window; N : C_Int) return C_Int;
1270 pragma Import (C, Winsdelln, "winsdelln");
1272 if Winsdelln (Win, C_Int (Lines)) = Curses_Err then
1273 raise Curses_Exception;
1275 end Insert_Delete_Lines;
1277 procedure Delete_Line (Win : in Window := Standard_Window)
1280 Insert_Delete_Lines (Win, -1);
1283 procedure Insert_Line (Win : in Window := Standard_Window)
1286 Insert_Delete_Lines (Win, 1);
1288 ------------------------------------------------------------------------------
1290 (Win : in Window := Standard_Window;
1291 Number_Of_Lines : out Line_Count;
1292 Number_Of_Columns : out Column_Count)
1294 type Int_Access is access all C_Int;
1295 function Getmaxyx (W : Window; Y, X : Int_Access) return C_Int;
1296 pragma Import (C, Getmaxyx, "_nc_ada_getmaxyx");
1298 Y, X : aliased C_Int;
1299 Err : constant C_Int := Getmaxyx (Win, Y'Access, X'Access);
1301 if Err = Curses_Err then
1302 raise Curses_Exception;
1304 Number_Of_Lines := Line_Count (Y);
1305 Number_Of_Columns := Column_Count (X);
1309 procedure Get_Window_Position
1310 (Win : in Window := Standard_Window;
1311 Top_Left_Line : out Line_Position;
1312 Top_Left_Column : out Column_Position)
1314 type Int_Access is access all C_Int;
1315 function Getbegyx (W : Window; Y, X : Int_Access) return C_Int;
1316 pragma Import (C, Getbegyx, "_nc_ada_getbegyx");
1318 Y, X : aliased C_Int;
1319 Err : constant C_Int := Getbegyx (Win, Y'Access, X'Access);
1321 if Err = Curses_Err then
1322 raise Curses_Exception;
1324 Top_Left_Line := Line_Position (Y);
1325 Top_Left_Column := Column_Position (X);
1327 end Get_Window_Position;
1329 procedure Get_Cursor_Position
1330 (Win : in Window := Standard_Window;
1331 Line : out Line_Position;
1332 Column : out Column_Position)
1334 type Int_Access is access all C_Int;
1335 function Getyx (W : Window; Y, X : Int_Access) return C_Int;
1336 pragma Import (C, Getyx, "_nc_ada_getyx");
1338 Y, X : aliased C_Int;
1339 Err : constant C_Int := Getyx (Win, Y'Access, X'Access);
1341 if Err = Curses_Err then
1342 raise Curses_Exception;
1344 Line := Line_Position (Y);
1345 Column := Column_Position (X);
1347 end Get_Cursor_Position;
1349 procedure Get_Origin_Relative_To_Parent
1351 Top_Left_Line : out Line_Position;
1352 Top_Left_Column : out Column_Position;
1353 Is_Not_A_Subwindow : out Boolean)
1355 type Int_Access is access all C_Int;
1356 function Getparyx (W : Window; Y, X : Int_Access) return C_Int;
1357 pragma Import (C, Getparyx, "_nc_ada_getparyx");
1359 Y, X : aliased C_Int;
1360 Err : constant C_Int := Getparyx (Win, Y'Access, X'Access);
1362 if Err = Curses_Err then
1363 raise Curses_Exception;
1366 Top_Left_Line := Line_Position'Last;
1367 Top_Left_Column := Column_Position'Last;
1368 Is_Not_A_Subwindow := True;
1370 Top_Left_Line := Line_Position (Y);
1371 Top_Left_Column := Column_Position (X);
1372 Is_Not_A_Subwindow := False;
1375 end Get_Origin_Relative_To_Parent;
1376 ------------------------------------------------------------------------------
1377 function New_Pad (Lines : Line_Count;
1378 Columns : Column_Count) return Window
1380 function Newpad (Lines : C_Int; Columns : C_Int) return Window;
1381 pragma Import (C, Newpad, "newpad");
1385 W := Newpad (C_Int (Lines), C_Int (Columns));
1386 if W = Null_Window then
1387 raise Curses_Exception;
1394 Number_Of_Lines : Line_Count;
1395 Number_Of_Columns : Column_Count;
1396 First_Line_Position : Line_Position;
1397 First_Column_Position : Column_Position) return Window
1401 Number_Of_Lines : C_Int;
1402 Number_Of_Columns : C_Int;
1403 First_Line_Position : C_Int;
1404 First_Column_Position : C_Int) return Window;
1405 pragma Import (C, Subpad, "subpad");
1410 C_Int (Number_Of_Lines),
1411 C_Int (Number_Of_Columns),
1412 C_Int (First_Line_Position),
1413 C_Int (First_Column_Position));
1414 if W = Null_Window then
1415 raise Curses_Exception;
1422 Source_Top_Row : in Line_Position;
1423 Source_Left_Column : in Column_Position;
1424 Destination_Top_Row : in Line_Position;
1425 Destination_Left_Column : in Column_Position;
1426 Destination_Bottom_Row : in Line_Position;
1427 Destination_Right_Column : in Column_Position)
1431 Source_Top_Row : C_Int;
1432 Source_Left_Column : C_Int;
1433 Destination_Top_Row : C_Int;
1434 Destination_Left_Column : C_Int;
1435 Destination_Bottom_Row : C_Int;
1436 Destination_Right_Column : C_Int) return C_Int;
1437 pragma Import (C, Prefresh, "prefresh");
1440 C_Int (Source_Top_Row),
1441 C_Int (Source_Left_Column),
1442 C_Int (Destination_Top_Row),
1443 C_Int (Destination_Left_Column),
1444 C_Int (Destination_Bottom_Row),
1445 C_Int (Destination_Right_Column)) = Curses_Err then
1446 raise Curses_Exception;
1450 procedure Refresh_Without_Update
1452 Source_Top_Row : in Line_Position;
1453 Source_Left_Column : in Column_Position;
1454 Destination_Top_Row : in Line_Position;
1455 Destination_Left_Column : in Column_Position;
1456 Destination_Bottom_Row : in Line_Position;
1457 Destination_Right_Column : in Column_Position)
1459 function Pnoutrefresh
1461 Source_Top_Row : C_Int;
1462 Source_Left_Column : C_Int;
1463 Destination_Top_Row : C_Int;
1464 Destination_Left_Column : C_Int;
1465 Destination_Bottom_Row : C_Int;
1466 Destination_Right_Column : C_Int) return C_Int;
1467 pragma Import (C, Pnoutrefresh, "pnoutrefresh");
1469 if Pnoutrefresh (Pad,
1470 C_Int (Source_Top_Row),
1471 C_Int (Source_Left_Column),
1472 C_Int (Destination_Top_Row),
1473 C_Int (Destination_Left_Column),
1474 C_Int (Destination_Bottom_Row),
1475 C_Int (Destination_Right_Column)) = Curses_Err then
1476 raise Curses_Exception;
1478 end Refresh_Without_Update;
1480 procedure Add_Character_To_Pad_And_Echo_It
1482 Ch : in Attributed_Character)
1484 function Pechochar (Pad : Window; Ch : C_Int)
1486 pragma Import (C, Pechochar, "pechochar");
1488 if Pechochar (Pad, Chtype_To_CInt (Ch)) = Curses_Err then
1489 raise Curses_Exception;
1491 end Add_Character_To_Pad_And_Echo_It;
1493 procedure Add_Character_To_Pad_And_Echo_It
1498 Add_Character_To_Pad_And_Echo_It
1500 Attributed_Character'(Ch => Ch,
1501 Color => Color_Pair'First,
1502 Attr => Normal_Video));
1503 end Add_Character_To_Pad_And_Echo_It;
1504 ------------------------------------------------------------------------------
1505 procedure Scroll (Win : in Window := Standard_Window;
1506 Amount : in Integer := 1)
1508 function Wscrl (Win : Window; N : C_Int) return C_Int;
1509 pragma Import (C, Wscrl, "wscrl");
1512 if Wscrl (Win, C_Int (Amount)) = Curses_Err then
1513 raise Curses_Exception;
1517 ------------------------------------------------------------------------------
1518 procedure Delete_Character (Win : in Window := Standard_Window)
1520 function Wdelch (Win : Window) return C_Int;
1521 pragma Import (C, Wdelch, "wdelch");
1523 if Wdelch (Win) = Curses_Err then
1524 raise Curses_Exception;
1526 end Delete_Character;
1528 procedure Delete_Character
1529 (Win : in Window := Standard_Window;
1530 Line : in Line_Position;
1531 Column : in Column_Position)
1533 function Mvwdelch (Win : Window;
1535 Col : C_Int) return C_Int;
1536 pragma Import (C, Mvwdelch, "mvwdelch");
1538 if Mvwdelch (Win, C_Int (Line), C_Int (Column)) = Curses_Err then
1539 raise Curses_Exception;
1541 end Delete_Character;
1542 ------------------------------------------------------------------------------
1543 function Peek (Win : Window := Standard_Window)
1544 return Attributed_Character
1546 function Winch (Win : Window) return C_Int;
1547 pragma Import (C, Winch, "winch");
1549 return CInt_To_Chtype (Winch (Win));
1553 (Win : Window := Standard_Window;
1554 Line : Line_Position;
1555 Column : Column_Position) return Attributed_Character
1557 function Mvwinch (Win : Window;
1559 Col : C_Int) return C_Int;
1560 pragma Import (C, Mvwinch, "mvwinch");
1562 return CInt_To_Chtype (Mvwinch (Win, C_Int (Line), C_Int (Column)));
1564 ------------------------------------------------------------------------------
1565 procedure Insert (Win : in Window := Standard_Window;
1566 Ch : in Attributed_Character)
1568 function Winsch (Win : Window; Ch : C_Int) return C_Int;
1569 pragma Import (C, Winsch, "winsch");
1571 if Winsch (Win, Chtype_To_CInt (Ch)) = Curses_Err then
1572 raise Curses_Exception;
1577 (Win : in Window := Standard_Window;
1578 Line : in Line_Position;
1579 Column : in Column_Position;
1580 Ch : in Attributed_Character)
1582 function Mvwinsch (Win : Window;
1585 Ch : C_Int) return C_Int;
1586 pragma Import (C, Mvwinsch, "mvwinsch");
1591 Chtype_To_CInt (Ch)) = Curses_Err then
1592 raise Curses_Exception;
1595 ------------------------------------------------------------------------------
1596 procedure Insert (Win : in Window := Standard_Window;
1598 Len : in Integer := -1)
1600 type Char_Ptr is access all Interfaces.C.Char;
1601 function Winsnstr (Win : Window;
1603 Len : Integer := -1) return C_Int;
1604 pragma Import (C, Winsnstr, "winsnstr");
1606 Txt : char_array (0 .. Str'Length);
1609 To_C (Str, Txt, Length);
1610 if Winsnstr (Win, Txt (Txt'First)'Access, Len) = Curses_Err then
1611 raise Curses_Exception;
1616 (Win : in Window := Standard_Window;
1617 Line : in Line_Position;
1618 Column : in Column_Position;
1620 Len : in Integer := -1)
1622 type Char_Ptr is access all Interfaces.C.Char;
1623 function Mvwinsnstr (Win : Window;
1627 Len : C_Int) return C_Int;
1628 pragma Import (C, Mvwinsnstr, "mvwinsnstr");
1630 Txt : char_array (0 .. Str'Length);
1633 To_C (Str, Txt, Length);
1634 if Mvwinsnstr (Win, C_Int (Line), C_Int (Column),
1635 Txt (Txt'First)'Access, C_Int (Len))
1637 raise Curses_Exception;
1640 ------------------------------------------------------------------------------
1641 procedure Peek (Win : in Window := Standard_Window;
1643 Len : in Integer := -1)
1645 function Winnstr (Win : Window;
1647 Len : C_Int) return C_Int;
1648 pragma Import (C, Winnstr, "winnstr");
1651 Txt : char_array (0 .. Str'Length);
1657 if N > Str'Length then
1658 raise Constraint_Error;
1660 Txt (0) := Interfaces.C.char'First;
1661 if Winnstr (Win, Txt, C_Int (N)) = Curses_Err then
1662 raise Curses_Exception;
1664 To_Ada (Txt, Str, Cnt, True);
1665 if Cnt < Str'Length then
1666 Str ((Str'First + Cnt) .. Str'Last) := (others => ' ');
1671 (Win : in Window := Standard_Window;
1672 Line : in Line_Position;
1673 Column : in Column_Position;
1675 Len : in Integer := -1)
1678 Move_Cursor (Win, Line, Column);
1679 Peek (Win, Str, Len);
1681 ------------------------------------------------------------------------------
1683 (Win : in Window := Standard_Window;
1684 Str : out Attributed_String;
1685 Len : in Integer := -1)
1687 type Chtype_Ptr is access all Attributed_Character;
1688 function Winchnstr (Win : Window;
1690 Len : C_Int) return C_Int;
1691 pragma Import (C, Winchnstr, "winchnstr");
1694 Txt : chtype_array (0 .. Str'Length);
1700 if N > Str'Length then
1701 raise Constraint_Error;
1703 if Winchnstr (Win, Txt (Txt'First)'Access, C_Int (N)) = Curses_Err then
1704 raise Curses_Exception;
1706 for To in Str'Range loop
1707 exit when Txt (size_t (Cnt)) = Default_Character;
1708 Str (To) := Txt (size_t (Cnt));
1711 if Cnt < Str'Length then
1712 Str ((Str'First + Cnt) .. Str'Last) :=
1713 (others => (Ch => ' ',
1714 Color => Color_Pair'First,
1715 Attr => Normal_Video));
1720 (Win : in Window := Standard_Window;
1721 Line : in Line_Position;
1722 Column : in Column_Position;
1723 Str : out Attributed_String;
1724 Len : in Integer := -1)
1727 Move_Cursor (Win, Line, Column);
1728 Peek (Win, Str, Len);
1730 ------------------------------------------------------------------------------
1731 procedure Get (Win : in Window := Standard_Window;
1733 Len : in Integer := -1)
1735 function Wgetnstr (Win : Window;
1737 Len : C_Int) return C_Int;
1738 pragma Import (C, Wgetnstr, "wgetnstr");
1741 Txt : char_array (0 .. Str'Length);
1747 if N > Str'Length then
1748 raise Constraint_Error;
1750 Txt (0) := Interfaces.C.char'First;
1751 if Wgetnstr (Win, Txt, C_Int (N)) = Curses_Err then
1752 raise Curses_Exception;
1754 To_Ada (Txt, Str, Cnt, True);
1755 if Cnt < Str'Length then
1756 Str ((Str'First + Cnt) .. Str'Last) := (others => ' ');
1761 (Win : in Window := Standard_Window;
1762 Line : in Line_Position;
1763 Column : in Column_Position;
1765 Len : in Integer := -1)
1768 Move_Cursor (Win, Line, Column);
1769 Get (Win, Str, Len);
1771 ------------------------------------------------------------------------------
1772 procedure Init_Soft_Label_Keys
1773 (Format : in Soft_Label_Key_Format := Three_Two_Three)
1775 function Slk_Init (Fmt : C_Int) return C_Int;
1776 pragma Import (C, Slk_Init, "slk_init");
1778 if Slk_Init (Soft_Label_Key_Format'Pos (Format)) = Curses_Err then
1779 raise Curses_Exception;
1781 end Init_Soft_Label_Keys;
1783 procedure Set_Soft_Label_Key (Label : in Label_Number;
1785 Fmt : in Label_Justification := Left)
1787 type Char_Ptr is access all Interfaces.C.Char;
1788 function Slk_Set (Label : C_Int;
1790 Fmt : C_Int) return C_Int;
1791 pragma Import (C, Slk_Set, "slk_set");
1793 Txt : char_array (0 .. Text'Length);
1796 To_C (Text, Txt, Len);
1797 if Slk_Set (C_Int (Label),
1798 Txt (Txt'First)'Access,
1799 C_Int (Label_Justification'Pos (Fmt)))
1801 raise Curses_Exception;
1803 end Set_Soft_Label_Key;
1805 procedure Refresh_Soft_Label_Keys
1807 function Slk_Refresh return C_Int;
1808 pragma Import (C, Slk_Refresh, "slk_refresh");
1810 if Slk_Refresh = Curses_Err then
1811 raise Curses_Exception;
1813 end Refresh_Soft_Label_Keys;
1815 procedure Refresh_Soft_Label_Keys_Without_Update
1817 function Slk_Noutrefresh return C_Int;
1818 pragma Import (C, Slk_Noutrefresh, "slk_noutrefresh");
1820 if Slk_Noutrefresh = Curses_Err then
1821 raise Curses_Exception;
1823 end Refresh_Soft_Label_Keys_Without_Update;
1825 procedure Get_Soft_Label_Key (Label : in Label_Number;
1828 function Slk_Label (Label : C_Int) return chars_ptr;
1829 pragma Import (C, Slk_Label, "slk_label");
1831 Fill_String (Slk_Label (C_Int (Label)), Text);
1832 end Get_Soft_Label_Key;
1834 function Get_Soft_Label_Key (Label : in Label_Number) return String
1836 function Slk_Label (Label : C_Int) return chars_ptr;
1837 pragma Import (C, Slk_Label, "slk_label");
1839 return Fill_String (Slk_Label (C_Int (Label)));
1840 end Get_Soft_Label_Key;
1842 procedure Clear_Soft_Label_Keys
1844 function Slk_Clear return C_Int;
1845 pragma Import (C, Slk_Clear, "slk_clear");
1847 if Slk_Clear = Curses_Err then
1848 raise Curses_Exception;
1850 end Clear_Soft_Label_Keys;
1852 procedure Restore_Soft_Label_Keys
1854 function Slk_Restore return C_Int;
1855 pragma Import (C, Slk_Restore, "slk_restore");
1857 if Slk_Restore = Curses_Err then
1858 raise Curses_Exception;
1860 end Restore_Soft_Label_Keys;
1862 procedure Touch_Soft_Label_Keys
1864 function Slk_Touch return C_Int;
1865 pragma Import (C, Slk_Touch, "slk_touch");
1867 if Slk_Touch = Curses_Err then
1868 raise Curses_Exception;
1870 end Touch_Soft_Label_Keys;
1872 procedure Switch_Soft_Label_Key_Attributes
1873 (Attr : in Character_Attribute_Set;
1874 On : in Boolean := True)
1876 function Slk_Attron (Ch : C_Int) return C_Int;
1877 pragma Import (C, Slk_Attron, "slk_attron");
1878 function Slk_Attroff (Ch : C_Int) return C_Int;
1879 pragma Import (C, Slk_Attroff, "slk_attroff");
1882 Ch : constant Attributed_Character := (Ch => Character'First,
1884 Color => Color_Pair'First);
1887 Err := Slk_Attron (Chtype_To_CInt (Ch));
1889 Err := Slk_Attroff (Chtype_To_CInt (Ch));
1891 if Err = Curses_Err then
1892 raise Curses_Exception;
1894 end Switch_Soft_Label_Key_Attributes;
1896 procedure Set_Soft_Label_Key_Attributes
1897 (Attr : in Character_Attribute_Set := Normal_Video;
1898 Color : in Color_Pair := Color_Pair'First)
1900 function Slk_Attrset (Ch : C_Int) return C_Int;
1901 pragma Import (C, Slk_Attrset, "slk_attrset");
1903 Ch : constant Attributed_Character := (Ch => Character'First,
1907 if Slk_Attrset (Chtype_To_CInt (Ch)) = Curses_Err then
1908 raise Curses_Exception;
1910 end Set_Soft_Label_Key_Attributes;
1912 function Get_Soft_Label_Key_Attributes return Character_Attribute_Set
1914 function Slk_Attr return C_Int;
1915 pragma Import (C, Slk_Attr, "slk_attr");
1917 Attr : constant C_Int := Slk_Attr;
1919 return CInt_To_Chtype (Attr).Attr;
1920 end Get_Soft_Label_Key_Attributes;
1922 function Get_Soft_Label_Key_Attributes return Color_Pair
1924 function Slk_Attr return C_Int;
1925 pragma Import (C, Slk_Attr, "slk_attr");
1927 Attr : constant C_Int := Slk_Attr;
1929 return CInt_To_Chtype (Attr).Color;
1930 end Get_Soft_Label_Key_Attributes;
1931 ------------------------------------------------------------------------------
1932 procedure Enable_Key (Key : in Special_Key_Code;
1933 Enable : in Boolean := True)
1935 function Keyok (Keycode : C_Int;
1936 On_Off : C_Int) return C_Int;
1937 pragma Import (C, Keyok, "keyok");
1939 if Keyok (C_Int (Key), Boolean'Pos (Enable)) = Curses_Err then
1940 raise Curses_Exception;
1943 ------------------------------------------------------------------------------
1944 procedure Define_Key (Definition : in String;
1945 Key : in Special_Key_Code)
1947 type Char_Ptr is access all Interfaces.C.Char;
1948 function Defkey (Def : Char_Ptr;
1949 Key : C_Int) return C_Int;
1950 pragma Import (C, Defkey, "define_key");
1952 Txt : char_array (0 .. Definition'Length);
1955 To_C (Definition, Txt, Length);
1956 if Defkey (Txt (Txt'First)'Access, C_Int (Key)) = Curses_Err then
1957 raise Curses_Exception;
1960 ------------------------------------------------------------------------------
1961 procedure Un_Control (Ch : in Attributed_Character;
1964 function Unctrl (Ch : C_Int) return chars_ptr;
1965 pragma Import (C, Unctrl, "unctrl");
1967 Fill_String (Unctrl (Chtype_To_CInt (Ch)), Str);
1970 function Un_Control (Ch : in Attributed_Character) return String
1972 function Unctrl (Ch : C_Int) return chars_ptr;
1973 pragma Import (C, Unctrl, "unctrl");
1975 return Fill_String (Unctrl (Chtype_To_CInt (Ch)));
1978 procedure Delay_Output (Msecs : in Natural)
1980 function Delayoutput (Msecs : C_Int) return C_Int;
1981 pragma Import (C, Delayoutput, "delay_output");
1983 if Delayoutput (C_Int (Msecs)) = Curses_Err then
1984 raise Curses_Exception;
1988 procedure Flush_Input
1990 function Flushinp return C_Int;
1991 pragma Import (C, Flushinp, "flushinp");
1993 if Flushinp = Curses_Err then -- docu says that never happens, but...
1994 raise Curses_Exception;
1997 ------------------------------------------------------------------------------
1998 function Baudrate return Natural
2000 function Baud return C_Int;
2001 pragma Import (C, Baud, "baudrate");
2003 return Natural (Baud);
2006 function Erase_Character return Character
2008 function Erasechar return C_Int;
2009 pragma Import (C, Erasechar, "erasechar");
2011 return Character'Val (Erasechar);
2012 end Erase_Character;
2014 function Kill_Character return Character
2016 function Killchar return C_Int;
2017 pragma Import (C, Killchar, "killchar");
2019 return Character'Val (Killchar);
2022 function Has_Insert_Character return Boolean
2024 function Has_Ic return C_Int;
2025 pragma Import (C, Has_Ic, "has_ic");
2027 if Has_Ic = Curses_False then
2032 end Has_Insert_Character;
2034 function Has_Insert_Line return Boolean
2036 function Has_Il return C_Int;
2037 pragma Import (C, Has_Il, "has_il");
2039 if Has_Il = Curses_False then
2044 end Has_Insert_Line;
2046 function Supported_Attributes return Character_Attribute_Set
2048 function Termattrs return C_Int;
2049 pragma Import (C, Termattrs, "termattrs");
2051 Ch : constant Attributed_Character := CInt_To_Chtype (Termattrs);
2054 end Supported_Attributes;
2056 procedure Long_Name (Name : out String)
2058 function Longname return chars_ptr;
2059 pragma Import (C, Longname, "longname");
2061 Fill_String (Longname, Name);
2064 function Long_Name return String
2066 function Longname return chars_ptr;
2067 pragma Import (C, Longname, "longname");
2069 return Fill_String (Longname);
2072 procedure Terminal_Name (Name : out String)
2074 function Termname return chars_ptr;
2075 pragma Import (C, Termname, "termname");
2077 Fill_String (Termname, Name);
2080 function Terminal_Name return String
2082 function Termname return chars_ptr;
2083 pragma Import (C, Termname, "termname");
2085 return Fill_String (Termname);
2087 ------------------------------------------------------------------------------
2088 procedure Init_Pair (Pair : in Redefinable_Color_Pair;
2089 Fore : in Color_Number;
2090 Back : in Color_Number)
2092 function Initpair (Pair : C_Short;
2094 Back : C_Short) return C_Int;
2095 pragma Import (C, Initpair, "init_pair");
2097 if Integer (Pair) >= Number_Of_Color_Pairs then
2098 raise Constraint_Error;
2100 if Integer (Fore) >= Number_Of_Colors or else
2101 Integer (Back) >= Number_Of_Colors then raise Constraint_Error;
2103 if Initpair (C_Short (Pair), C_Short (Fore), C_Short (Back))
2105 raise Curses_Exception;
2109 procedure Pair_Content (Pair : in Color_Pair;
2110 Fore : out Color_Number;
2111 Back : out Color_Number)
2113 type C_Short_Access is access all C_Short;
2114 function Paircontent (Pair : C_Short;
2115 Fp : C_Short_Access;
2116 Bp : C_Short_Access) return C_Int;
2117 pragma Import (C, Paircontent, "pair_content");
2119 F, B : aliased C_Short;
2121 if Paircontent (C_Short (Pair), F'Access, B'Access) = Curses_Err then
2122 raise Curses_Exception;
2124 Fore := Color_Number (F);
2125 Back := Color_Number (B);
2129 function Has_Colors return Boolean
2131 function Hascolors return C_Int;
2132 pragma Import (C, Hascolors, "has_colors");
2134 if Hascolors = Curses_False then
2141 procedure Init_Color (Color : in Color_Number;
2143 Green : in RGB_Value;
2144 Blue : in RGB_Value)
2146 function Initcolor (Col : C_Short;
2149 Blue : C_Short) return C_Int;
2150 pragma Import (C, Initcolor, "init_color");
2152 if Initcolor (C_Short (Color), C_Short (Red), C_Short (Green),
2153 C_Short (Blue)) = Curses_Err then
2154 raise Curses_Exception;
2158 function Can_Change_Color return Boolean
2160 function Canchangecolor return C_Int;
2161 pragma Import (C, Canchangecolor, "can_change_color");
2163 if Canchangecolor = Curses_False then
2168 end Can_Change_Color;
2170 procedure Color_Content (Color : in Color_Number;
2171 Red : out RGB_Value;
2172 Green : out RGB_Value;
2173 Blue : out RGB_Value)
2175 type C_Short_Access is access all C_Short;
2177 function Colorcontent (Color : C_Short; R, G, B : C_Short_Access)
2179 pragma Import (C, Colorcontent, "color_content");
2181 R, G, B : aliased C_Short;
2183 if Colorcontent (C_Short (Color), R'Access, G'Access, B'Access) =
2185 raise Curses_Exception;
2187 Red := RGB_Value (R);
2188 Green := RGB_Value (G);
2189 Blue := RGB_Value (B);
2193 ------------------------------------------------------------------------------
2194 procedure Save_Curses_Mode (Mode : in Curses_Mode)
2196 function Def_Prog_Mode return C_Int;
2197 pragma Import (C, Def_Prog_Mode, "def_prog_mode");
2198 function Def_Shell_Mode return C_Int;
2199 pragma Import (C, Def_Shell_Mode, "def_shell_mode");
2204 when Curses => Err := Def_Prog_Mode;
2205 when Shell => Err := Def_Shell_Mode;
2207 if Err = Curses_Err then
2208 raise Curses_Exception;
2210 end Save_Curses_Mode;
2212 procedure Reset_Curses_Mode (Mode : in Curses_Mode)
2214 function Reset_Prog_Mode return C_Int;
2215 pragma Import (C, Reset_Prog_Mode, "reset_prog_mode");
2216 function Reset_Shell_Mode return C_Int;
2217 pragma Import (C, Reset_Shell_Mode, "reset_shell_mode");
2222 when Curses => Err := Reset_Prog_Mode;
2223 when Shell => Err := Reset_Shell_Mode;
2225 if Err = Curses_Err then
2226 raise Curses_Exception;
2228 end Reset_Curses_Mode;
2230 procedure Save_Terminal_State
2232 function Savetty return C_Int;
2233 pragma Import (C, Savetty, "savetty");
2235 if Savetty = Curses_Err then
2236 raise Curses_Exception;
2238 end Save_Terminal_State;
2240 procedure Reset_Terminal_State
2242 function Resetty return C_Int;
2243 pragma Import (C, Resetty, "resetty");
2245 if Resetty = Curses_Err then
2246 raise Curses_Exception;
2248 end Reset_Terminal_State;
2250 procedure Rip_Off_Lines (Lines : in Integer;
2251 Proc : in Stdscr_Init_Proc)
2253 function Ripoffline (Lines : C_Int;
2254 Proc : Stdscr_Init_Proc) return C_Int;
2255 pragma Import (C, Ripoffline, "_nc_ripoffline");
2257 if Ripoffline (C_Int (Lines), Proc) = Curses_Err then
2258 raise Curses_Exception;
2262 procedure Set_Cursor_Visibility (Visibility : in out Cursor_Visibility)
2264 function Curs_Set (Curs : C_Int) return C_Int;
2265 pragma Import (C, Curs_Set, "curs_set");
2269 Res := Curs_Set (Cursor_Visibility'Pos (Visibility));
2270 if Res /= Curses_Err then
2271 Visibility := Cursor_Visibility'Val (Res);
2273 end Set_Cursor_Visibility;
2275 procedure Nap_Milli_Seconds (Ms : in Natural)
2277 function Napms (Ms : C_Int) return C_Int;
2278 pragma Import (C, Napms, "napms");
2280 if Napms (C_Int (Ms)) = Curses_Err then
2281 raise Curses_Exception;
2283 end Nap_Milli_Seconds;
2284 ------------------------------------------------------------------------------
2286 function Standard_Window return Window
2289 pragma Import (C, Stdscr, "stdscr");
2292 end Standard_Window;
2294 function Lines return Line_Count
2297 pragma Import (C, C_Lines, "LINES");
2299 return Line_Count (C_Lines);
2302 function Columns return Column_Count
2305 pragma Import (C, C_Columns, "COLS");
2307 return Column_Count (C_Columns);
2310 function Tab_Size return Natural
2313 pragma Import (C, C_Tab_Size, "TABSIZE");
2315 return Natural (C_Tab_Size);
2318 function Number_Of_Colors return Natural
2320 C_Number_Of_Colors : C_Int;
2321 pragma Import (C, C_Number_Of_Colors, "COLORS");
2323 return Natural (C_Number_Of_Colors);
2324 end Number_Of_Colors;
2326 function Number_Of_Color_Pairs return Natural
2328 C_Number_Of_Color_Pairs : C_Int;
2329 pragma Import (C, C_Number_Of_Color_Pairs, "COLOR_PAIRS");
2331 return Natural (C_Number_Of_Color_Pairs);
2332 end Number_Of_Color_Pairs;
2333 ------------------------------------------------------------------------------
2334 procedure Transform_Coordinates
2335 (W : in Window := Standard_Window;
2336 Line : in out Line_Position;
2337 Column : in out Column_Position;
2338 Dir : in Transform_Direction := From_Screen)
2340 type Int_Access is access all C_Int;
2341 function Transform (W : Window;
2343 Dir : C_Int) return C_Int;
2344 pragma Import (C, Transform, "_nc_ada_coord_transform");
2346 X : aliased C_Int := C_Int (Column);
2347 Y : aliased C_Int := C_Int (Line);
2351 if Dir = To_Screen then
2354 R := Transform (W, Y'Access, X'Access, D);
2355 if R = Curses_False then
2356 raise Curses_Exception;
2358 Line := Line_Position (Y);
2359 Column := Column_Position (X);
2361 end Transform_Coordinates;
2363 end Terminal_Interface.Curses;