2 define(`HTMLNAME',`terminal_interface-curses__adb.htm')dnl
3 include(M4MACRO)------------------------------------------------------------------------------
5 -- GNAT ncurses Binding --
7 -- Terminal_Interface.Curses --
11 ------------------------------------------------------------------------------
12 -- Copyright (c) 1998-2009,2011 Free Software Foundation, Inc. --
14 -- Permission is hereby granted, free of charge, to any person obtaining a --
15 -- copy of this software and associated documentation files (the --
16 -- "Software"), to deal in the Software without restriction, including --
17 -- without limitation the rights to use, copy, modify, merge, publish, --
18 -- distribute, distribute with modifications, sublicense, and/or sell --
19 -- copies of the Software, and to permit persons to whom the Software is --
20 -- furnished to do so, subject to the following conditions: --
22 -- The above copyright notice and this permission notice shall be included --
23 -- in all copies or substantial portions of the Software. --
25 -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS --
26 -- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF --
27 -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. --
28 -- IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, --
29 -- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR --
30 -- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR --
31 -- THE USE OR OTHER DEALINGS IN THE SOFTWARE. --
33 -- Except as contained in this notice, the name(s) of the above copyright --
34 -- holders shall not be used in advertising or otherwise to promote the --
35 -- sale, use or other dealings in this Software without prior written --
37 ------------------------------------------------------------------------------
38 -- Author: Juergen Pfeifer, 1996
41 -- $Date: 2011/03/22 23:02:14 $
42 -- Binding Version 01.00
43 ------------------------------------------------------------------------------
46 with Terminal_Interface.Curses.Aux;
47 with Interfaces.C; use Interfaces.C;
48 with Interfaces.C.Strings; use Interfaces.C.Strings;
49 with Ada.Characters.Handling; use Ada.Characters.Handling;
50 with Ada.Strings.Fixed;
52 package body Terminal_Interface.Curses is
55 use type System.Bit_Order;
57 package ASF renames Ada.Strings.Fixed;
59 type chtype_array is array (size_t range <>)
60 of aliased Attributed_Character;
61 pragma Convention (C, chtype_array);
63 ------------------------------------------------------------------------------
64 function Key_Name (Key : Real_Key_Code) return String
66 function Keyname (K : C_Int) return chars_ptr;
67 pragma Import (C, Keyname, "keyname");
71 if Key <= Character'Pos (Character'Last) then
72 Ch := Character'Val (Key);
73 if Is_Control (Ch) then
74 return Un_Control (Attributed_Character'(Ch => Ch,
75 Color => Color_Pair'First,
76 Attr => Normal_Video));
77 elsif Is_Graphic (Ch) then
88 return Fill_String (Keyname (C_Int (Key)));
92 procedure Key_Name (Key : Real_Key_Code;
96 ASF.Move (Key_Name (Key), Name);
99 ------------------------------------------------------------------------------
100 procedure Init_Screen
102 function Initscr return Window;
103 pragma Import (C, Initscr, "initscr");
108 if W = Null_Window then
109 raise Curses_Exception;
113 procedure End_Windows
115 function Endwin return C_Int;
116 pragma Import (C, Endwin, "endwin");
118 if Endwin = Curses_Err then
119 raise Curses_Exception;
123 function Is_End_Window return Boolean
125 function Isendwin return Curses_Bool;
126 pragma Import (C, Isendwin, "isendwin");
128 if Isendwin = Curses_Bool_False then
134 ------------------------------------------------------------------------------
135 procedure Move_Cursor (Win : Window := Standard_Window;
136 Line : Line_Position;
137 Column : Column_Position)
139 function Wmove (Win : Window;
143 pragma Import (C, Wmove, "wmove");
145 if Wmove (Win, C_Int (Line), C_Int (Column)) = Curses_Err then
146 raise Curses_Exception;
149 ------------------------------------------------------------------------------
150 procedure Add (Win : Window := Standard_Window;
151 Ch : Attributed_Character)
153 function Waddch (W : Window;
154 Ch : C_Chtype) return C_Int;
155 pragma Import (C, Waddch, "waddch");
157 if Waddch (Win, AttrChar_To_Chtype (Ch)) = Curses_Err then
158 raise Curses_Exception;
162 procedure Add (Win : Window := Standard_Window;
167 Attributed_Character'(Ch => Ch,
168 Color => Color_Pair'First,
169 Attr => Normal_Video));
173 (Win : Window := Standard_Window;
174 Line : Line_Position;
175 Column : Column_Position;
176 Ch : Attributed_Character)
178 function mvwaddch (W : Window;
181 Ch : C_Chtype) return C_Int;
182 pragma Import (C, mvwaddch, "mvwaddch");
184 if mvwaddch (Win, C_Int (Line),
186 AttrChar_To_Chtype (Ch)) = Curses_Err then
187 raise Curses_Exception;
192 (Win : Window := Standard_Window;
193 Line : Line_Position;
194 Column : Column_Position;
201 Attributed_Character'(Ch => Ch,
202 Color => Color_Pair'First,
203 Attr => Normal_Video));
206 procedure Add_With_Immediate_Echo
207 (Win : Window := Standard_Window;
208 Ch : Attributed_Character)
210 function Wechochar (W : Window;
211 Ch : C_Chtype) return C_Int;
212 pragma Import (C, Wechochar, "wechochar");
214 if Wechochar (Win, AttrChar_To_Chtype (Ch)) = Curses_Err then
215 raise Curses_Exception;
217 end Add_With_Immediate_Echo;
219 procedure Add_With_Immediate_Echo
220 (Win : Window := Standard_Window;
224 Add_With_Immediate_Echo
226 Attributed_Character'(Ch => Ch,
227 Color => Color_Pair'First,
228 Attr => Normal_Video));
229 end Add_With_Immediate_Echo;
230 ------------------------------------------------------------------------------
231 function Create (Number_Of_Lines : Line_Count;
232 Number_Of_Columns : Column_Count;
233 First_Line_Position : Line_Position;
234 First_Column_Position : Column_Position) return Window
236 function Newwin (Number_Of_Lines : C_Int;
237 Number_Of_Columns : C_Int;
238 First_Line_Position : C_Int;
239 First_Column_Position : C_Int) return Window;
240 pragma Import (C, Newwin, "newwin");
244 W := Newwin (C_Int (Number_Of_Lines),
245 C_Int (Number_Of_Columns),
246 C_Int (First_Line_Position),
247 C_Int (First_Column_Position));
248 if W = Null_Window then
249 raise Curses_Exception;
254 procedure Delete (Win : in out Window)
256 function Wdelwin (W : Window) return C_Int;
257 pragma Import (C, Wdelwin, "delwin");
259 if Wdelwin (Win) = Curses_Err then
260 raise Curses_Exception;
266 (Win : Window := Standard_Window;
267 Number_Of_Lines : Line_Count;
268 Number_Of_Columns : Column_Count;
269 First_Line_Position : Line_Position;
270 First_Column_Position : Column_Position) return Window
274 Number_Of_Lines : C_Int;
275 Number_Of_Columns : C_Int;
276 First_Line_Position : C_Int;
277 First_Column_Position : C_Int) return Window;
278 pragma Import (C, Subwin, "subwin");
283 C_Int (Number_Of_Lines),
284 C_Int (Number_Of_Columns),
285 C_Int (First_Line_Position),
286 C_Int (First_Column_Position));
287 if W = Null_Window then
288 raise Curses_Exception;
293 function Derived_Window
294 (Win : Window := Standard_Window;
295 Number_Of_Lines : Line_Count;
296 Number_Of_Columns : Column_Count;
297 First_Line_Position : Line_Position;
298 First_Column_Position : Column_Position) return Window
302 Number_Of_Lines : C_Int;
303 Number_Of_Columns : C_Int;
304 First_Line_Position : C_Int;
305 First_Column_Position : C_Int) return Window;
306 pragma Import (C, Derwin, "derwin");
311 C_Int (Number_Of_Lines),
312 C_Int (Number_Of_Columns),
313 C_Int (First_Line_Position),
314 C_Int (First_Column_Position));
315 if W = Null_Window then
316 raise Curses_Exception;
321 function Duplicate (Win : Window) return Window
323 function Dupwin (Win : Window) return Window;
324 pragma Import (C, Dupwin, "dupwin");
326 W : constant Window := Dupwin (Win);
328 if W = Null_Window then
329 raise Curses_Exception;
334 procedure Move_Window (Win : Window;
335 Line : Line_Position;
336 Column : Column_Position)
338 function Mvwin (Win : Window;
340 Column : C_Int) return C_Int;
341 pragma Import (C, Mvwin, "mvwin");
343 if Mvwin (Win, C_Int (Line), C_Int (Column)) = Curses_Err then
344 raise Curses_Exception;
348 procedure Move_Derived_Window (Win : Window;
349 Line : Line_Position;
350 Column : Column_Position)
352 function Mvderwin (Win : Window;
354 Column : C_Int) return C_Int;
355 pragma Import (C, Mvderwin, "mvderwin");
357 if Mvderwin (Win, C_Int (Line), C_Int (Column)) = Curses_Err then
358 raise Curses_Exception;
360 end Move_Derived_Window;
362 procedure Set_Synch_Mode (Win : Window := Standard_Window;
363 Mode : Boolean := False)
365 function Syncok (Win : Window;
366 Mode : Curses_Bool) return C_Int;
367 pragma Import (C, Syncok, "syncok");
369 if Syncok (Win, Curses_Bool (Boolean'Pos (Mode))) = Curses_Err then
370 raise Curses_Exception;
373 ------------------------------------------------------------------------------
374 procedure Add (Win : Window := Standard_Window;
378 function Waddnstr (Win : Window;
380 Len : C_Int := -1) return C_Int;
381 pragma Import (C, Waddnstr, "waddnstr");
383 Txt : char_array (0 .. Str'Length);
386 To_C (Str, Txt, Length);
387 if Waddnstr (Win, Txt, C_Int (Len)) = Curses_Err then
388 raise Curses_Exception;
393 (Win : Window := Standard_Window;
394 Line : Line_Position;
395 Column : Column_Position;
400 Move_Cursor (Win, Line, Column);
403 ------------------------------------------------------------------------------
405 (Win : Window := Standard_Window;
406 Str : Attributed_String;
409 function Waddchnstr (Win : Window;
411 Len : C_Int := -1) return C_Int;
412 pragma Import (C, Waddchnstr, "waddchnstr");
414 Txt : chtype_array (0 .. Str'Length);
416 for Length in 1 .. size_t (Str'Length) loop
417 Txt (Length - 1) := Str (Natural (Length));
419 Txt (Str'Length) := Default_Character;
422 C_Int (Len)) = Curses_Err then
423 raise Curses_Exception;
428 (Win : Window := Standard_Window;
429 Line : Line_Position;
430 Column : Column_Position;
431 Str : Attributed_String;
435 Move_Cursor (Win, Line, Column);
438 ------------------------------------------------------------------------------
440 (Win : Window := Standard_Window;
441 Left_Side_Symbol : Attributed_Character := Default_Character;
442 Right_Side_Symbol : Attributed_Character := Default_Character;
443 Top_Side_Symbol : Attributed_Character := Default_Character;
444 Bottom_Side_Symbol : Attributed_Character := Default_Character;
445 Upper_Left_Corner_Symbol : Attributed_Character := Default_Character;
446 Upper_Right_Corner_Symbol : Attributed_Character := Default_Character;
447 Lower_Left_Corner_Symbol : Attributed_Character := Default_Character;
448 Lower_Right_Corner_Symbol : Attributed_Character := Default_Character)
450 function Wborder (W : Window;
458 LRC : C_Chtype) return C_Int;
459 pragma Import (C, Wborder, "wborder");
462 AttrChar_To_Chtype (Left_Side_Symbol),
463 AttrChar_To_Chtype (Right_Side_Symbol),
464 AttrChar_To_Chtype (Top_Side_Symbol),
465 AttrChar_To_Chtype (Bottom_Side_Symbol),
466 AttrChar_To_Chtype (Upper_Left_Corner_Symbol),
467 AttrChar_To_Chtype (Upper_Right_Corner_Symbol),
468 AttrChar_To_Chtype (Lower_Left_Corner_Symbol),
469 AttrChar_To_Chtype (Lower_Right_Corner_Symbol)
472 raise Curses_Exception;
477 (Win : Window := Standard_Window;
478 Vertical_Symbol : Attributed_Character := Default_Character;
479 Horizontal_Symbol : Attributed_Character := Default_Character)
483 Vertical_Symbol, Vertical_Symbol,
484 Horizontal_Symbol, Horizontal_Symbol);
487 procedure Horizontal_Line
488 (Win : Window := Standard_Window;
490 Line_Symbol : Attributed_Character := Default_Character)
492 function Whline (W : Window;
494 Len : C_Int) return C_Int;
495 pragma Import (C, Whline, "whline");
498 AttrChar_To_Chtype (Line_Symbol),
499 C_Int (Line_Size)) = Curses_Err then
500 raise Curses_Exception;
504 procedure Vertical_Line
505 (Win : Window := Standard_Window;
507 Line_Symbol : Attributed_Character := Default_Character)
509 function Wvline (W : Window;
511 Len : C_Int) return C_Int;
512 pragma Import (C, Wvline, "wvline");
515 AttrChar_To_Chtype (Line_Symbol),
516 C_Int (Line_Size)) = Curses_Err then
517 raise Curses_Exception;
521 ------------------------------------------------------------------------------
522 function Get_Keystroke (Win : Window := Standard_Window)
525 function Wgetch (W : Window) return C_Int;
526 pragma Import (C, Wgetch, "wgetch");
528 C : constant C_Int := Wgetch (Win);
530 if C = Curses_Err then
533 return Real_Key_Code (C);
537 procedure Undo_Keystroke (Key : Real_Key_Code)
539 function Ungetch (Ch : C_Int) return C_Int;
540 pragma Import (C, Ungetch, "ungetch");
542 if Ungetch (C_Int (Key)) = Curses_Err then
543 raise Curses_Exception;
547 function Has_Key (Key : Special_Key_Code) return Boolean
549 function Haskey (Key : C_Int) return C_Int;
550 pragma Import (C, Haskey, "has_key");
552 if Haskey (C_Int (Key)) = Curses_False then
559 function Is_Function_Key (Key : Special_Key_Code) return Boolean
561 L : constant Special_Key_Code := Special_Key_Code (Natural (Key_F0) +
562 Natural (Function_Key_Number'Last));
564 if (Key >= Key_F0) and then (Key <= L) then
571 function Function_Key (Key : Real_Key_Code)
572 return Function_Key_Number
575 if Is_Function_Key (Key) then
576 return Function_Key_Number (Key - Key_F0);
578 raise Constraint_Error;
582 function Function_Key_Code (Key : Function_Key_Number) return Real_Key_Code
585 return Real_Key_Code (Natural (Key_F0) + Natural (Key));
586 end Function_Key_Code;
587 ------------------------------------------------------------------------------
588 procedure Standout (Win : Window := Standard_Window;
589 On : Boolean := True)
591 function wstandout (Win : Window) return C_Int;
592 pragma Import (C, wstandout, "wstandout");
593 function wstandend (Win : Window) return C_Int;
594 pragma Import (C, wstandend, "wstandend");
599 Err := wstandout (Win);
601 Err := wstandend (Win);
603 if Err = Curses_Err then
604 raise Curses_Exception;
608 procedure Switch_Character_Attribute
609 (Win : Window := Standard_Window;
610 Attr : Character_Attribute_Set := Normal_Video;
611 On : Boolean := True)
613 function Wattron (Win : Window;
614 C_Attr : C_AttrType) return C_Int;
615 pragma Import (C, Wattron, "wattr_on");
616 function Wattroff (Win : Window;
617 C_Attr : C_AttrType) return C_Int;
618 pragma Import (C, Wattroff, "wattr_off");
619 -- In Ada we use the On Boolean to control whether or not we want to
620 -- switch on or off the attributes in the set.
622 AC : constant Attributed_Character := (Ch => Character'First,
623 Color => Color_Pair'First,
627 Err := Wattron (Win, AttrChar_To_AttrType (AC));
629 Err := Wattroff (Win, AttrChar_To_AttrType (AC));
631 if Err = Curses_Err then
632 raise Curses_Exception;
634 end Switch_Character_Attribute;
636 procedure Set_Character_Attributes
637 (Win : Window := Standard_Window;
638 Attr : Character_Attribute_Set := Normal_Video;
639 Color : Color_Pair := Color_Pair'First)
641 function Wattrset (Win : Window;
642 C_Attr : C_AttrType) return C_Int;
643 pragma Import (C, Wattrset, "wattrset"); -- ??? wattr_set
646 AttrChar_To_AttrType (Attributed_Character'
647 (Ch => Character'First,
649 Attr => Attr))) = Curses_Err then
650 raise Curses_Exception;
652 end Set_Character_Attributes;
654 function Get_Character_Attribute (Win : Window := Standard_Window)
655 return Character_Attribute_Set
657 function Wattrget (Win : Window;
658 Atr : access C_AttrType;
659 Col : access C_Short;
660 Opt : System.Address) return C_Int;
661 pragma Import (C, Wattrget, "wattr_get");
663 Attr : aliased C_AttrType;
664 Col : aliased C_Short;
665 Res : constant C_Int := Wattrget (Win, Attr'Access, Col'Access,
666 System.Null_Address);
667 Ch : Attributed_Character;
669 if Res = Curses_Ok then
670 Ch := AttrType_To_AttrChar (Attr);
673 raise Curses_Exception;
675 end Get_Character_Attribute;
677 function Get_Character_Attribute (Win : Window := Standard_Window)
680 function Wattrget (Win : Window;
681 Atr : access C_AttrType;
682 Col : access C_Short;
683 Opt : System.Address) return C_Int;
684 pragma Import (C, Wattrget, "wattr_get");
686 Attr : aliased C_AttrType;
687 Col : aliased C_Short;
688 Res : constant C_Int := Wattrget (Win, Attr'Access, Col'Access,
689 System.Null_Address);
690 Ch : Attributed_Character;
692 if Res = Curses_Ok then
693 Ch := AttrType_To_AttrChar (Attr);
696 raise Curses_Exception;
698 end Get_Character_Attribute;
700 procedure Set_Color (Win : Window := Standard_Window;
703 function Wset_Color (Win : Window;
705 Opts : C_Void_Ptr) return C_Int;
706 pragma Import (C, Wset_Color, "wcolor_set");
710 C_Void_Ptr (System.Null_Address)) = Curses_Err then
711 raise Curses_Exception;
715 procedure Change_Attributes
716 (Win : Window := Standard_Window;
717 Count : Integer := -1;
718 Attr : Character_Attribute_Set := Normal_Video;
719 Color : Color_Pair := Color_Pair'First)
721 function Wchgat (Win : Window;
725 Opts : System.Address := System.Null_Address)
727 pragma Import (C, Wchgat, "wchgat");
729 Ch : constant Attributed_Character :=
730 (Ch => Character'First, Color => Color_Pair'First, Attr => Attr);
732 if Wchgat (Win, C_Int (Count), AttrChar_To_AttrType (Ch),
733 C_Short (Color)) = Curses_Err then
734 raise Curses_Exception;
736 end Change_Attributes;
738 procedure Change_Attributes
739 (Win : Window := Standard_Window;
740 Line : Line_Position := Line_Position'First;
741 Column : Column_Position := Column_Position'First;
742 Count : Integer := -1;
743 Attr : Character_Attribute_Set := Normal_Video;
744 Color : Color_Pair := Color_Pair'First)
747 Move_Cursor (Win, Line, Column);
748 Change_Attributes (Win, Count, Attr, Color);
749 end Change_Attributes;
750 ------------------------------------------------------------------------------
753 function Beeper return C_Int;
754 pragma Import (C, Beeper, "beep");
756 if Beeper = Curses_Err then
757 raise Curses_Exception;
761 procedure Flash_Screen
763 function Flash return C_Int;
764 pragma Import (C, Flash, "flash");
766 if Flash = Curses_Err then
767 raise Curses_Exception;
770 ------------------------------------------------------------------------------
771 procedure Set_Cbreak_Mode (SwitchOn : Boolean := True)
773 function Cbreak return C_Int;
774 pragma Import (C, Cbreak, "cbreak");
775 function NoCbreak return C_Int;
776 pragma Import (C, NoCbreak, "nocbreak");
785 if Err = Curses_Err then
786 raise Curses_Exception;
790 procedure Set_Raw_Mode (SwitchOn : Boolean := True)
792 function Raw return C_Int;
793 pragma Import (C, Raw, "raw");
794 function NoRaw return C_Int;
795 pragma Import (C, NoRaw, "noraw");
804 if Err = Curses_Err then
805 raise Curses_Exception;
809 procedure Set_Echo_Mode (SwitchOn : Boolean := True)
811 function Echo return C_Int;
812 pragma Import (C, Echo, "echo");
813 function NoEcho return C_Int;
814 pragma Import (C, NoEcho, "noecho");
823 if Err = Curses_Err then
824 raise Curses_Exception;
828 procedure Set_Meta_Mode (Win : Window := Standard_Window;
829 SwitchOn : Boolean := True)
831 function Meta (W : Window; Mode : Curses_Bool) return C_Int;
832 pragma Import (C, Meta, "meta");
834 if Meta (Win, Curses_Bool (Boolean'Pos (SwitchOn))) = Curses_Err then
835 raise Curses_Exception;
839 procedure Set_KeyPad_Mode (Win : Window := Standard_Window;
840 SwitchOn : Boolean := True)
842 function Keypad (W : Window; Mode : Curses_Bool) return C_Int;
843 pragma Import (C, Keypad, "keypad");
845 if Keypad (Win, Curses_Bool (Boolean'Pos (SwitchOn))) = Curses_Err then
846 raise Curses_Exception;
850 function Get_KeyPad_Mode (Win : Window := Standard_Window)
853 function Is_Keypad (W : Window) return Curses_Bool;
854 pragma Import (C, Is_Keypad, "is_keypad");
856 return (Is_Keypad (Win) /= Curses_Bool_False);
859 procedure Half_Delay (Amount : Half_Delay_Amount)
861 function Halfdelay (Amount : C_Int) return C_Int;
862 pragma Import (C, Halfdelay, "halfdelay");
864 if Halfdelay (C_Int (Amount)) = Curses_Err then
865 raise Curses_Exception;
869 procedure Set_Flush_On_Interrupt_Mode
870 (Win : Window := Standard_Window;
871 Mode : Boolean := True)
873 function Intrflush (Win : Window; Mode : Curses_Bool) return C_Int;
874 pragma Import (C, Intrflush, "intrflush");
876 if Intrflush (Win, Curses_Bool (Boolean'Pos (Mode))) = Curses_Err then
877 raise Curses_Exception;
879 end Set_Flush_On_Interrupt_Mode;
881 procedure Set_Queue_Interrupt_Mode
882 (Win : Window := Standard_Window;
883 Flush : Boolean := True)
886 pragma Import (C, Qiflush, "qiflush");
887 procedure No_Qiflush;
888 pragma Import (C, No_Qiflush, "noqiflush");
890 if Win = Null_Window then
891 raise Curses_Exception;
898 end Set_Queue_Interrupt_Mode;
900 procedure Set_NoDelay_Mode
901 (Win : Window := Standard_Window;
902 Mode : Boolean := False)
904 function Nodelay (Win : Window; Mode : Curses_Bool) return C_Int;
905 pragma Import (C, Nodelay, "nodelay");
907 if Nodelay (Win, Curses_Bool (Boolean'Pos (Mode))) = Curses_Err then
908 raise Curses_Exception;
910 end Set_NoDelay_Mode;
912 procedure Set_Timeout_Mode (Win : Window := Standard_Window;
916 procedure Wtimeout (Win : Window; Amount : C_Int);
917 pragma Import (C, Wtimeout, "wtimeout");
922 when Blocking => Time := -1;
923 when Non_Blocking => Time := 0;
926 raise Constraint_Error;
928 Time := C_Int (Amount);
930 Wtimeout (Win, Time);
931 end Set_Timeout_Mode;
933 procedure Set_Escape_Timer_Mode
934 (Win : Window := Standard_Window;
935 Timer_Off : Boolean := False)
937 function Notimeout (Win : Window; Mode : Curses_Bool) return C_Int;
938 pragma Import (C, Notimeout, "notimeout");
940 if Notimeout (Win, Curses_Bool (Boolean'Pos (Timer_Off)))
942 raise Curses_Exception;
944 end Set_Escape_Timer_Mode;
946 ------------------------------------------------------------------------------
947 procedure Set_NL_Mode (SwitchOn : Boolean := True)
949 function NL return C_Int;
950 pragma Import (C, NL, "nl");
951 function NoNL return C_Int;
952 pragma Import (C, NoNL, "nonl");
961 if Err = Curses_Err then
962 raise Curses_Exception;
966 procedure Clear_On_Next_Update
967 (Win : Window := Standard_Window;
968 Do_Clear : Boolean := True)
970 function Clear_Ok (W : Window; Flag : Curses_Bool) return C_Int;
971 pragma Import (C, Clear_Ok, "clearok");
973 if Clear_Ok (Win, Curses_Bool (Boolean'Pos (Do_Clear))) = Curses_Err then
974 raise Curses_Exception;
976 end Clear_On_Next_Update;
978 procedure Use_Insert_Delete_Line
979 (Win : Window := Standard_Window;
980 Do_Idl : Boolean := True)
982 function IDL_Ok (W : Window; Flag : Curses_Bool) return C_Int;
983 pragma Import (C, IDL_Ok, "idlok");
985 if IDL_Ok (Win, Curses_Bool (Boolean'Pos (Do_Idl))) = Curses_Err then
986 raise Curses_Exception;
988 end Use_Insert_Delete_Line;
990 procedure Use_Insert_Delete_Character
991 (Win : Window := Standard_Window;
992 Do_Idc : Boolean := True)
994 procedure IDC_Ok (W : Window; Flag : Curses_Bool);
995 pragma Import (C, IDC_Ok, "idcok");
997 IDC_Ok (Win, Curses_Bool (Boolean'Pos (Do_Idc)));
998 end Use_Insert_Delete_Character;
1000 procedure Leave_Cursor_After_Update
1001 (Win : Window := Standard_Window;
1002 Do_Leave : Boolean := True)
1004 function Leave_Ok (W : Window; Flag : Curses_Bool) return C_Int;
1005 pragma Import (C, Leave_Ok, "leaveok");
1007 if Leave_Ok (Win, Curses_Bool (Boolean'Pos (Do_Leave))) = Curses_Err then
1008 raise Curses_Exception;
1010 end Leave_Cursor_After_Update;
1012 procedure Immediate_Update_Mode
1013 (Win : Window := Standard_Window;
1014 Mode : Boolean := False)
1016 procedure Immedok (Win : Window; Mode : Curses_Bool);
1017 pragma Import (C, Immedok, "immedok");
1019 Immedok (Win, Curses_Bool (Boolean'Pos (Mode)));
1020 end Immediate_Update_Mode;
1022 procedure Allow_Scrolling
1023 (Win : Window := Standard_Window;
1024 Mode : Boolean := False)
1026 function Scrollok (Win : Window; Mode : Curses_Bool) return C_Int;
1027 pragma Import (C, Scrollok, "scrollok");
1029 if Scrollok (Win, Curses_Bool (Boolean'Pos (Mode))) = Curses_Err then
1030 raise Curses_Exception;
1032 end Allow_Scrolling;
1034 function Scrolling_Allowed (Win : Window := Standard_Window)
1037 function Is_Scroll_Ok (W : Window) return Curses_Bool;
1038 pragma Import (C, Is_Scroll_Ok, "is_scrollok");
1040 return (Is_Scroll_Ok (Win) /= Curses_Bool_False);
1041 end Scrolling_Allowed;
1043 procedure Set_Scroll_Region
1044 (Win : Window := Standard_Window;
1045 Top_Line : Line_Position;
1046 Bottom_Line : Line_Position)
1048 function Wsetscrreg (Win : Window;
1050 Col : C_Int) return C_Int;
1051 pragma Import (C, Wsetscrreg, "wsetscrreg");
1053 if Wsetscrreg (Win, C_Int (Top_Line), C_Int (Bottom_Line))
1055 raise Curses_Exception;
1057 end Set_Scroll_Region;
1058 ------------------------------------------------------------------------------
1059 procedure Update_Screen
1061 function Do_Update return C_Int;
1062 pragma Import (C, Do_Update, "doupdate");
1064 if Do_Update = Curses_Err then
1065 raise Curses_Exception;
1069 procedure Refresh (Win : Window := Standard_Window)
1071 function Wrefresh (W : Window) return C_Int;
1072 pragma Import (C, Wrefresh, "wrefresh");
1074 if Wrefresh (Win) = Curses_Err then
1075 raise Curses_Exception;
1079 procedure Refresh_Without_Update
1080 (Win : Window := Standard_Window)
1082 function Wnoutrefresh (W : Window) return C_Int;
1083 pragma Import (C, Wnoutrefresh, "wnoutrefresh");
1085 if Wnoutrefresh (Win) = Curses_Err then
1086 raise Curses_Exception;
1088 end Refresh_Without_Update;
1090 procedure Redraw (Win : Window := Standard_Window)
1092 function Redrawwin (Win : Window) return C_Int;
1093 pragma Import (C, Redrawwin, "redrawwin");
1095 if Redrawwin (Win) = Curses_Err then
1096 raise Curses_Exception;
1101 (Win : Window := Standard_Window;
1102 Begin_Line : Line_Position;
1103 Line_Count : Positive)
1105 function Wredrawln (Win : Window; First : C_Int; Cnt : C_Int)
1107 pragma Import (C, Wredrawln, "wredrawln");
1111 C_Int (Line_Count)) = Curses_Err then
1112 raise Curses_Exception;
1116 ------------------------------------------------------------------------------
1117 procedure Erase (Win : Window := Standard_Window)
1119 function Werase (W : Window) return C_Int;
1120 pragma Import (C, Werase, "werase");
1122 if Werase (Win) = Curses_Err then
1123 raise Curses_Exception;
1127 procedure Clear (Win : Window := Standard_Window)
1129 function Wclear (W : Window) return C_Int;
1130 pragma Import (C, Wclear, "wclear");
1132 if Wclear (Win) = Curses_Err then
1133 raise Curses_Exception;
1137 procedure Clear_To_End_Of_Screen (Win : Window := Standard_Window)
1139 function Wclearbot (W : Window) return C_Int;
1140 pragma Import (C, Wclearbot, "wclrtobot");
1142 if Wclearbot (Win) = Curses_Err then
1143 raise Curses_Exception;
1145 end Clear_To_End_Of_Screen;
1147 procedure Clear_To_End_Of_Line (Win : Window := Standard_Window)
1149 function Wcleareol (W : Window) return C_Int;
1150 pragma Import (C, Wcleareol, "wclrtoeol");
1152 if Wcleareol (Win) = Curses_Err then
1153 raise Curses_Exception;
1155 end Clear_To_End_Of_Line;
1156 ------------------------------------------------------------------------------
1157 procedure Set_Background
1158 (Win : Window := Standard_Window;
1159 Ch : Attributed_Character)
1161 procedure WBackground (W : Window; Ch : C_Chtype);
1162 pragma Import (C, WBackground, "wbkgdset");
1164 WBackground (Win, AttrChar_To_Chtype (Ch));
1167 procedure Change_Background
1168 (Win : Window := Standard_Window;
1169 Ch : Attributed_Character)
1171 function WChangeBkgd (W : Window; Ch : C_Chtype) return C_Int;
1172 pragma Import (C, WChangeBkgd, "wbkgd");
1174 if WChangeBkgd (Win, AttrChar_To_Chtype (Ch)) = Curses_Err then
1175 raise Curses_Exception;
1177 end Change_Background;
1179 function Get_Background (Win : Window := Standard_Window)
1180 return Attributed_Character
1182 function Wgetbkgd (Win : Window) return C_Chtype;
1183 pragma Import (C, Wgetbkgd, "getbkgd");
1185 return Chtype_To_AttrChar (Wgetbkgd (Win));
1187 ------------------------------------------------------------------------------
1188 procedure Change_Lines_Status (Win : Window := Standard_Window;
1189 Start : Line_Position;
1193 function Wtouchln (Win : Window;
1196 Chg : C_Int) return C_Int;
1197 pragma Import (C, Wtouchln, "wtouchln");
1199 if Wtouchln (Win, C_Int (Start), C_Int (Count),
1200 C_Int (Boolean'Pos (State))) = Curses_Err then
1201 raise Curses_Exception;
1203 end Change_Lines_Status;
1205 procedure Touch (Win : Window := Standard_Window)
1208 X : Column_Position;
1210 Get_Size (Win, Y, X);
1211 pragma Unreferenced (X);
1212 Change_Lines_Status (Win, 0, Positive (Y), True);
1215 procedure Untouch (Win : Window := Standard_Window)
1218 X : Column_Position;
1220 Get_Size (Win, Y, X);
1221 pragma Unreferenced (X);
1222 Change_Lines_Status (Win, 0, Positive (Y), False);
1225 procedure Touch (Win : Window := Standard_Window;
1226 Start : Line_Position;
1230 Change_Lines_Status (Win, Start, Count, True);
1234 (Win : Window := Standard_Window;
1235 Line : Line_Position) return Boolean
1237 function WLineTouched (W : Window; L : C_Int) return Curses_Bool;
1238 pragma Import (C, WLineTouched, "is_linetouched");
1240 if WLineTouched (Win, C_Int (Line)) = Curses_Bool_False then
1248 (Win : Window := Standard_Window) return Boolean
1250 function WWinTouched (W : Window) return Curses_Bool;
1251 pragma Import (C, WWinTouched, "is_wintouched");
1253 if WWinTouched (Win) = Curses_Bool_False then
1259 ------------------------------------------------------------------------------
1261 (Source_Window : Window;
1262 Destination_Window : Window;
1263 Source_Top_Row : Line_Position;
1264 Source_Left_Column : Column_Position;
1265 Destination_Top_Row : Line_Position;
1266 Destination_Left_Column : Column_Position;
1267 Destination_Bottom_Row : Line_Position;
1268 Destination_Right_Column : Column_Position;
1269 Non_Destructive_Mode : Boolean := True)
1271 function Copywin (Src : Window;
1279 Ndm : C_Int) return C_Int;
1280 pragma Import (C, Copywin, "copywin");
1282 if Copywin (Source_Window,
1284 C_Int (Source_Top_Row),
1285 C_Int (Source_Left_Column),
1286 C_Int (Destination_Top_Row),
1287 C_Int (Destination_Left_Column),
1288 C_Int (Destination_Bottom_Row),
1289 C_Int (Destination_Right_Column),
1290 Boolean'Pos (Non_Destructive_Mode)
1292 raise Curses_Exception;
1297 (Source_Window : Window;
1298 Destination_Window : Window)
1300 function Overwrite (Src : Window; Dst : Window) return C_Int;
1301 pragma Import (C, Overwrite, "overwrite");
1303 if Overwrite (Source_Window, Destination_Window) = Curses_Err then
1304 raise Curses_Exception;
1309 (Source_Window : Window;
1310 Destination_Window : Window)
1312 function Overlay (Src : Window; Dst : Window) return C_Int;
1313 pragma Import (C, Overlay, "overlay");
1315 if Overlay (Source_Window, Destination_Window) = Curses_Err then
1316 raise Curses_Exception;
1320 ------------------------------------------------------------------------------
1321 procedure Insert_Delete_Lines
1322 (Win : Window := Standard_Window;
1323 Lines : Integer := 1) -- default is to insert one line above
1325 function Winsdelln (W : Window; N : C_Int) return C_Int;
1326 pragma Import (C, Winsdelln, "winsdelln");
1328 if Winsdelln (Win, C_Int (Lines)) = Curses_Err then
1329 raise Curses_Exception;
1331 end Insert_Delete_Lines;
1333 procedure Delete_Line (Win : Window := Standard_Window)
1336 Insert_Delete_Lines (Win, -1);
1339 procedure Insert_Line (Win : Window := Standard_Window)
1342 Insert_Delete_Lines (Win, 1);
1344 ------------------------------------------------------------------------------
1347 (Win : Window := Standard_Window;
1348 Number_Of_Lines : out Line_Count;
1349 Number_Of_Columns : out Column_Count)
1351 function GetMaxY (W : Window) return C_Int;
1352 pragma Import (C, GetMaxY, "getmaxy");
1354 function GetMaxX (W : Window) return C_Int;
1355 pragma Import (C, GetMaxX, "getmaxx");
1357 Y : constant C_Int := GetMaxY (Win);
1358 X : constant C_Int := GetMaxX (Win);
1360 Number_Of_Lines := Line_Count (Y);
1361 Number_Of_Columns := Column_Count (X);
1364 procedure Get_Window_Position
1365 (Win : Window := Standard_Window;
1366 Top_Left_Line : out Line_Position;
1367 Top_Left_Column : out Column_Position)
1369 function GetBegY (W : Window) return C_Int;
1370 pragma Import (C, GetBegY, "getbegy");
1372 function GetBegX (W : Window) return C_Int;
1373 pragma Import (C, GetBegX, "getbegx");
1375 Y : constant C_Short := C_Short (GetBegY (Win));
1376 X : constant C_Short := C_Short (GetBegX (Win));
1378 Top_Left_Line := Line_Position (Y);
1379 Top_Left_Column := Column_Position (X);
1380 end Get_Window_Position;
1382 procedure Get_Cursor_Position
1383 (Win : Window := Standard_Window;
1384 Line : out Line_Position;
1385 Column : out Column_Position)
1387 function GetCurY (W : Window) return C_Int;
1388 pragma Import (C, GetCurY, "getcury");
1390 function GetCurX (W : Window) return C_Int;
1391 pragma Import (C, GetCurX, "getcurx");
1393 Y : constant C_Short := C_Short (GetCurY (Win));
1394 X : constant C_Short := C_Short (GetCurX (Win));
1396 Line := Line_Position (Y);
1397 Column := Column_Position (X);
1398 end Get_Cursor_Position;
1400 procedure Get_Origin_Relative_To_Parent
1402 Top_Left_Line : out Line_Position;
1403 Top_Left_Column : out Column_Position;
1404 Is_Not_A_Subwindow : out Boolean)
1406 function GetParY (W : Window) return C_Int;
1407 pragma Import (C, GetParY, "getpary");
1409 function GetParX (W : Window) return C_Int;
1410 pragma Import (C, GetParX, "getparx");
1412 Y : constant C_Int := GetParY (Win);
1413 X : constant C_Int := GetParX (Win);
1416 Top_Left_Line := Line_Position'Last;
1417 Top_Left_Column := Column_Position'Last;
1418 Is_Not_A_Subwindow := True;
1420 Top_Left_Line := Line_Position (Y);
1421 Top_Left_Column := Column_Position (X);
1422 Is_Not_A_Subwindow := False;
1424 end Get_Origin_Relative_To_Parent;
1425 ------------------------------------------------------------------------------
1426 function New_Pad (Lines : Line_Count;
1427 Columns : Column_Count) return Window
1429 function Newpad (Lines : C_Int; Columns : C_Int) return Window;
1430 pragma Import (C, Newpad, "newpad");
1434 W := Newpad (C_Int (Lines), C_Int (Columns));
1435 if W = Null_Window then
1436 raise Curses_Exception;
1443 Number_Of_Lines : Line_Count;
1444 Number_Of_Columns : Column_Count;
1445 First_Line_Position : Line_Position;
1446 First_Column_Position : Column_Position) return Window
1450 Number_Of_Lines : C_Int;
1451 Number_Of_Columns : C_Int;
1452 First_Line_Position : C_Int;
1453 First_Column_Position : C_Int) return Window;
1454 pragma Import (C, Subpad, "subpad");
1459 C_Int (Number_Of_Lines),
1460 C_Int (Number_Of_Columns),
1461 C_Int (First_Line_Position),
1462 C_Int (First_Column_Position));
1463 if W = Null_Window then
1464 raise Curses_Exception;
1471 Source_Top_Row : Line_Position;
1472 Source_Left_Column : Column_Position;
1473 Destination_Top_Row : Line_Position;
1474 Destination_Left_Column : Column_Position;
1475 Destination_Bottom_Row : Line_Position;
1476 Destination_Right_Column : Column_Position)
1480 Source_Top_Row : C_Int;
1481 Source_Left_Column : C_Int;
1482 Destination_Top_Row : C_Int;
1483 Destination_Left_Column : C_Int;
1484 Destination_Bottom_Row : C_Int;
1485 Destination_Right_Column : C_Int) return C_Int;
1486 pragma Import (C, Prefresh, "prefresh");
1489 C_Int (Source_Top_Row),
1490 C_Int (Source_Left_Column),
1491 C_Int (Destination_Top_Row),
1492 C_Int (Destination_Left_Column),
1493 C_Int (Destination_Bottom_Row),
1494 C_Int (Destination_Right_Column)) = Curses_Err then
1495 raise Curses_Exception;
1499 procedure Refresh_Without_Update
1501 Source_Top_Row : Line_Position;
1502 Source_Left_Column : Column_Position;
1503 Destination_Top_Row : Line_Position;
1504 Destination_Left_Column : Column_Position;
1505 Destination_Bottom_Row : Line_Position;
1506 Destination_Right_Column : Column_Position)
1508 function Pnoutrefresh
1510 Source_Top_Row : C_Int;
1511 Source_Left_Column : C_Int;
1512 Destination_Top_Row : C_Int;
1513 Destination_Left_Column : C_Int;
1514 Destination_Bottom_Row : C_Int;
1515 Destination_Right_Column : C_Int) return C_Int;
1516 pragma Import (C, Pnoutrefresh, "pnoutrefresh");
1518 if Pnoutrefresh (Pad,
1519 C_Int (Source_Top_Row),
1520 C_Int (Source_Left_Column),
1521 C_Int (Destination_Top_Row),
1522 C_Int (Destination_Left_Column),
1523 C_Int (Destination_Bottom_Row),
1524 C_Int (Destination_Right_Column)) = Curses_Err then
1525 raise Curses_Exception;
1527 end Refresh_Without_Update;
1529 procedure Add_Character_To_Pad_And_Echo_It
1531 Ch : Attributed_Character)
1533 function Pechochar (Pad : Window; Ch : C_Chtype)
1535 pragma Import (C, Pechochar, "pechochar");
1537 if Pechochar (Pad, AttrChar_To_Chtype (Ch)) = Curses_Err then
1538 raise Curses_Exception;
1540 end Add_Character_To_Pad_And_Echo_It;
1542 procedure Add_Character_To_Pad_And_Echo_It
1547 Add_Character_To_Pad_And_Echo_It
1549 Attributed_Character'(Ch => Ch,
1550 Color => Color_Pair'First,
1551 Attr => Normal_Video));
1552 end Add_Character_To_Pad_And_Echo_It;
1553 ------------------------------------------------------------------------------
1554 procedure Scroll (Win : Window := Standard_Window;
1555 Amount : Integer := 1)
1557 function Wscrl (Win : Window; N : C_Int) return C_Int;
1558 pragma Import (C, Wscrl, "wscrl");
1561 if Wscrl (Win, C_Int (Amount)) = Curses_Err then
1562 raise Curses_Exception;
1566 ------------------------------------------------------------------------------
1567 procedure Delete_Character (Win : Window := Standard_Window)
1569 function Wdelch (Win : Window) return C_Int;
1570 pragma Import (C, Wdelch, "wdelch");
1572 if Wdelch (Win) = Curses_Err then
1573 raise Curses_Exception;
1575 end Delete_Character;
1577 procedure Delete_Character
1578 (Win : Window := Standard_Window;
1579 Line : Line_Position;
1580 Column : Column_Position)
1582 function Mvwdelch (Win : Window;
1584 Col : C_Int) return C_Int;
1585 pragma Import (C, Mvwdelch, "mvwdelch");
1587 if Mvwdelch (Win, C_Int (Line), C_Int (Column)) = Curses_Err then
1588 raise Curses_Exception;
1590 end Delete_Character;
1591 ------------------------------------------------------------------------------
1592 function Peek (Win : Window := Standard_Window)
1593 return Attributed_Character
1595 function Winch (Win : Window) return C_Chtype;
1596 pragma Import (C, Winch, "winch");
1598 return Chtype_To_AttrChar (Winch (Win));
1602 (Win : Window := Standard_Window;
1603 Line : Line_Position;
1604 Column : Column_Position) return Attributed_Character
1606 function Mvwinch (Win : Window;
1608 Col : C_Int) return C_Chtype;
1609 pragma Import (C, Mvwinch, "mvwinch");
1611 return Chtype_To_AttrChar (Mvwinch (Win, C_Int (Line), C_Int (Column)));
1613 ------------------------------------------------------------------------------
1614 procedure Insert (Win : Window := Standard_Window;
1615 Ch : Attributed_Character)
1617 function Winsch (Win : Window; Ch : C_Chtype) return C_Int;
1618 pragma Import (C, Winsch, "winsch");
1620 if Winsch (Win, AttrChar_To_Chtype (Ch)) = Curses_Err then
1621 raise Curses_Exception;
1626 (Win : Window := Standard_Window;
1627 Line : Line_Position;
1628 Column : Column_Position;
1629 Ch : Attributed_Character)
1631 function Mvwinsch (Win : Window;
1634 Ch : C_Chtype) return C_Int;
1635 pragma Import (C, Mvwinsch, "mvwinsch");
1640 AttrChar_To_Chtype (Ch)) = Curses_Err then
1641 raise Curses_Exception;
1644 ------------------------------------------------------------------------------
1645 procedure Insert (Win : Window := Standard_Window;
1647 Len : Integer := -1)
1649 function Winsnstr (Win : Window;
1651 Len : Integer := -1) return C_Int;
1652 pragma Import (C, Winsnstr, "winsnstr");
1654 Txt : char_array (0 .. Str'Length);
1657 To_C (Str, Txt, Length);
1658 if Winsnstr (Win, Txt, Len) = Curses_Err then
1659 raise Curses_Exception;
1664 (Win : Window := Standard_Window;
1665 Line : Line_Position;
1666 Column : Column_Position;
1668 Len : Integer := -1)
1670 function Mvwinsnstr (Win : Window;
1674 Len : C_Int) return C_Int;
1675 pragma Import (C, Mvwinsnstr, "mvwinsnstr");
1677 Txt : char_array (0 .. Str'Length);
1680 To_C (Str, Txt, Length);
1681 if Mvwinsnstr (Win, C_Int (Line), C_Int (Column), Txt, C_Int (Len))
1683 raise Curses_Exception;
1686 ------------------------------------------------------------------------------
1687 procedure Peek (Win : Window := Standard_Window;
1689 Len : Integer := -1)
1691 function Winnstr (Win : Window;
1693 Len : C_Int) return C_Int;
1694 pragma Import (C, Winnstr, "winnstr");
1697 Txt : char_array (0 .. Str'Length);
1703 if N > Str'Length then
1704 raise Constraint_Error;
1706 Txt (0) := Interfaces.C.char'First;
1707 if Winnstr (Win, Txt, C_Int (N)) = Curses_Err then
1708 raise Curses_Exception;
1710 To_Ada (Txt, Str, Cnt, True);
1711 if Cnt < Str'Length then
1712 Str ((Str'First + Cnt) .. Str'Last) := (others => ' ');
1717 (Win : Window := Standard_Window;
1718 Line : Line_Position;
1719 Column : Column_Position;
1721 Len : Integer := -1)
1724 Move_Cursor (Win, Line, Column);
1725 Peek (Win, Str, Len);
1727 ------------------------------------------------------------------------------
1729 (Win : Window := Standard_Window;
1730 Str : out Attributed_String;
1731 Len : Integer := -1)
1733 function Winchnstr (Win : Window;
1734 Str : chtype_array; -- out
1735 Len : C_Int) return C_Int;
1736 pragma Import (C, Winchnstr, "winchnstr");
1739 Txt : constant chtype_array (0 .. Str'Length)
1740 := (0 => Default_Character);
1746 if N > Str'Length then
1747 raise Constraint_Error;
1749 if Winchnstr (Win, Txt, C_Int (N)) = Curses_Err then
1750 raise Curses_Exception;
1752 for To in Str'Range loop
1753 exit when Txt (size_t (Cnt)) = Default_Character;
1754 Str (To) := Txt (size_t (Cnt));
1757 if Cnt < Str'Length then
1758 Str ((Str'First + Cnt) .. Str'Last) :=
1759 (others => (Ch => ' ',
1760 Color => Color_Pair'First,
1761 Attr => Normal_Video));
1766 (Win : Window := Standard_Window;
1767 Line : Line_Position;
1768 Column : Column_Position;
1769 Str : out Attributed_String;
1770 Len : Integer := -1)
1773 Move_Cursor (Win, Line, Column);
1774 Peek (Win, Str, Len);
1776 ------------------------------------------------------------------------------
1777 procedure Get (Win : Window := Standard_Window;
1779 Len : Integer := -1)
1781 function Wgetnstr (Win : Window;
1783 Len : C_Int) return C_Int;
1784 pragma Import (C, Wgetnstr, "wgetnstr");
1787 Txt : char_array (0 .. Str'Length);
1793 if N > Str'Length then
1794 raise Constraint_Error;
1796 Txt (0) := Interfaces.C.char'First;
1797 if Wgetnstr (Win, Txt, C_Int (N)) = Curses_Err then
1798 raise Curses_Exception;
1800 To_Ada (Txt, Str, Cnt, True);
1801 if Cnt < Str'Length then
1802 Str ((Str'First + Cnt) .. Str'Last) := (others => ' ');
1807 (Win : Window := Standard_Window;
1808 Line : Line_Position;
1809 Column : Column_Position;
1811 Len : Integer := -1)
1814 Move_Cursor (Win, Line, Column);
1815 Get (Win, Str, Len);
1817 ------------------------------------------------------------------------------
1818 procedure Init_Soft_Label_Keys
1819 (Format : Soft_Label_Key_Format := Three_Two_Three)
1821 function Slk_Init (Fmt : C_Int) return C_Int;
1822 pragma Import (C, Slk_Init, "slk_init");
1824 if Slk_Init (Soft_Label_Key_Format'Pos (Format)) = Curses_Err then
1825 raise Curses_Exception;
1827 end Init_Soft_Label_Keys;
1829 procedure Set_Soft_Label_Key (Label : Label_Number;
1831 Fmt : Label_Justification := Left)
1833 function Slk_Set (Label : C_Int;
1835 Fmt : C_Int) return C_Int;
1836 pragma Import (C, Slk_Set, "slk_set");
1838 Txt : char_array (0 .. Text'Length);
1841 To_C (Text, Txt, Len);
1842 if Slk_Set (C_Int (Label), Txt,
1843 C_Int (Label_Justification'Pos (Fmt))) = Curses_Err then
1844 raise Curses_Exception;
1846 end Set_Soft_Label_Key;
1848 procedure Refresh_Soft_Label_Keys
1850 function Slk_Refresh return C_Int;
1851 pragma Import (C, Slk_Refresh, "slk_refresh");
1853 if Slk_Refresh = Curses_Err then
1854 raise Curses_Exception;
1856 end Refresh_Soft_Label_Keys;
1858 procedure Refresh_Soft_Label_Keys_Without_Update
1860 function Slk_Noutrefresh return C_Int;
1861 pragma Import (C, Slk_Noutrefresh, "slk_noutrefresh");
1863 if Slk_Noutrefresh = Curses_Err then
1864 raise Curses_Exception;
1866 end Refresh_Soft_Label_Keys_Without_Update;
1868 procedure Get_Soft_Label_Key (Label : Label_Number;
1871 function Slk_Label (Label : C_Int) return chars_ptr;
1872 pragma Import (C, Slk_Label, "slk_label");
1874 Fill_String (Slk_Label (C_Int (Label)), Text);
1875 end Get_Soft_Label_Key;
1877 function Get_Soft_Label_Key (Label : Label_Number) return String
1879 function Slk_Label (Label : C_Int) return chars_ptr;
1880 pragma Import (C, Slk_Label, "slk_label");
1882 return Fill_String (Slk_Label (C_Int (Label)));
1883 end Get_Soft_Label_Key;
1885 procedure Clear_Soft_Label_Keys
1887 function Slk_Clear return C_Int;
1888 pragma Import (C, Slk_Clear, "slk_clear");
1890 if Slk_Clear = Curses_Err then
1891 raise Curses_Exception;
1893 end Clear_Soft_Label_Keys;
1895 procedure Restore_Soft_Label_Keys
1897 function Slk_Restore return C_Int;
1898 pragma Import (C, Slk_Restore, "slk_restore");
1900 if Slk_Restore = Curses_Err then
1901 raise Curses_Exception;
1903 end Restore_Soft_Label_Keys;
1905 procedure Touch_Soft_Label_Keys
1907 function Slk_Touch return C_Int;
1908 pragma Import (C, Slk_Touch, "slk_touch");
1910 if Slk_Touch = Curses_Err then
1911 raise Curses_Exception;
1913 end Touch_Soft_Label_Keys;
1915 procedure Switch_Soft_Label_Key_Attributes
1916 (Attr : Character_Attribute_Set;
1917 On : Boolean := True)
1919 function Slk_Attron (Ch : C_Chtype) return C_Int;
1920 pragma Import (C, Slk_Attron, "slk_attron");
1921 function Slk_Attroff (Ch : C_Chtype) return C_Int;
1922 pragma Import (C, Slk_Attroff, "slk_attroff");
1925 Ch : constant Attributed_Character := (Ch => Character'First,
1927 Color => Color_Pair'First);
1930 Err := Slk_Attron (AttrChar_To_Chtype (Ch));
1932 Err := Slk_Attroff (AttrChar_To_Chtype (Ch));
1934 if Err = Curses_Err then
1935 raise Curses_Exception;
1937 end Switch_Soft_Label_Key_Attributes;
1939 procedure Set_Soft_Label_Key_Attributes
1940 (Attr : Character_Attribute_Set := Normal_Video;
1941 Color : Color_Pair := Color_Pair'First)
1943 function Slk_Attrset (Ch : C_Chtype) return C_Int;
1944 pragma Import (C, Slk_Attrset, "slk_attrset");
1946 Ch : constant Attributed_Character := (Ch => Character'First,
1950 if Slk_Attrset (AttrChar_To_Chtype (Ch)) = Curses_Err then
1951 raise Curses_Exception;
1953 end Set_Soft_Label_Key_Attributes;
1955 function Get_Soft_Label_Key_Attributes return Character_Attribute_Set
1957 function Slk_Attr return C_Chtype;
1958 pragma Import (C, Slk_Attr, "slk_attr");
1960 Attr : constant C_Chtype := Slk_Attr;
1962 return Chtype_To_AttrChar (Attr).Attr;
1963 end Get_Soft_Label_Key_Attributes;
1965 function Get_Soft_Label_Key_Attributes return Color_Pair
1967 function Slk_Attr return C_Chtype;
1968 pragma Import (C, Slk_Attr, "slk_attr");
1970 Attr : constant C_Chtype := Slk_Attr;
1972 return Chtype_To_AttrChar (Attr).Color;
1973 end Get_Soft_Label_Key_Attributes;
1975 procedure Set_Soft_Label_Key_Color (Pair : Color_Pair)
1977 function Slk_Color (Color : C_Short) return C_Int;
1978 pragma Import (C, Slk_Color, "slk_color");
1980 if Slk_Color (C_Short (Pair)) = Curses_Err then
1981 raise Curses_Exception;
1983 end Set_Soft_Label_Key_Color;
1985 ------------------------------------------------------------------------------
1986 procedure Enable_Key (Key : Special_Key_Code;
1987 Enable : Boolean := True)
1989 function Keyok (Keycode : C_Int;
1990 On_Off : Curses_Bool) return C_Int;
1991 pragma Import (C, Keyok, "keyok");
1993 if Keyok (C_Int (Key), Curses_Bool (Boolean'Pos (Enable)))
1995 raise Curses_Exception;
1998 ------------------------------------------------------------------------------
1999 procedure Define_Key (Definition : String;
2000 Key : Special_Key_Code)
2002 function Defkey (Def : char_array;
2003 Key : C_Int) return C_Int;
2004 pragma Import (C, Defkey, "define_key");
2006 Txt : char_array (0 .. Definition'Length);
2009 To_C (Definition, Txt, Length);
2010 if Defkey (Txt, C_Int (Key)) = Curses_Err then
2011 raise Curses_Exception;
2014 ------------------------------------------------------------------------------
2015 procedure Un_Control (Ch : Attributed_Character;
2018 function Unctrl (Ch : C_Chtype) return chars_ptr;
2019 pragma Import (C, Unctrl, "unctrl");
2021 Fill_String (Unctrl (AttrChar_To_Chtype (Ch)), Str);
2024 function Un_Control (Ch : Attributed_Character) return String
2026 function Unctrl (Ch : C_Chtype) return chars_ptr;
2027 pragma Import (C, Unctrl, "unctrl");
2029 return Fill_String (Unctrl (AttrChar_To_Chtype (Ch)));
2032 procedure Delay_Output (Msecs : Natural)
2034 function Delayoutput (Msecs : C_Int) return C_Int;
2035 pragma Import (C, Delayoutput, "delay_output");
2037 if Delayoutput (C_Int (Msecs)) = Curses_Err then
2038 raise Curses_Exception;
2042 procedure Flush_Input
2044 function Flushinp return C_Int;
2045 pragma Import (C, Flushinp, "flushinp");
2047 if Flushinp = Curses_Err then -- docu says that never happens, but...
2048 raise Curses_Exception;
2051 ------------------------------------------------------------------------------
2052 function Baudrate return Natural
2054 function Baud return C_Int;
2055 pragma Import (C, Baud, "baudrate");
2057 return Natural (Baud);
2060 function Erase_Character return Character
2062 function Erasechar return C_Int;
2063 pragma Import (C, Erasechar, "erasechar");
2065 return Character'Val (Erasechar);
2066 end Erase_Character;
2068 function Kill_Character return Character
2070 function Killchar return C_Int;
2071 pragma Import (C, Killchar, "killchar");
2073 return Character'Val (Killchar);
2076 function Has_Insert_Character return Boolean
2078 function Has_Ic return Curses_Bool;
2079 pragma Import (C, Has_Ic, "has_ic");
2081 if Has_Ic = Curses_Bool_False then
2086 end Has_Insert_Character;
2088 function Has_Insert_Line return Boolean
2090 function Has_Il return Curses_Bool;
2091 pragma Import (C, Has_Il, "has_il");
2093 if Has_Il = Curses_Bool_False then
2098 end Has_Insert_Line;
2100 function Supported_Attributes return Character_Attribute_Set
2102 function Termattrs return C_Chtype;
2103 pragma Import (C, Termattrs, "termattrs");
2105 Ch : constant Attributed_Character := Chtype_To_AttrChar (Termattrs);
2108 end Supported_Attributes;
2110 procedure Long_Name (Name : out String)
2112 function Longname return chars_ptr;
2113 pragma Import (C, Longname, "longname");
2115 Fill_String (Longname, Name);
2118 function Long_Name return String
2120 function Longname return chars_ptr;
2121 pragma Import (C, Longname, "longname");
2123 return Fill_String (Longname);
2126 procedure Terminal_Name (Name : out String)
2128 function Termname return chars_ptr;
2129 pragma Import (C, Termname, "termname");
2131 Fill_String (Termname, Name);
2134 function Terminal_Name return String
2136 function Termname return chars_ptr;
2137 pragma Import (C, Termname, "termname");
2139 return Fill_String (Termname);
2141 ------------------------------------------------------------------------------
2142 procedure Init_Pair (Pair : Redefinable_Color_Pair;
2143 Fore : Color_Number;
2144 Back : Color_Number)
2146 function Initpair (Pair : C_Short;
2148 Back : C_Short) return C_Int;
2149 pragma Import (C, Initpair, "init_pair");
2151 if Integer (Pair) >= Number_Of_Color_Pairs then
2152 raise Constraint_Error;
2154 if Integer (Fore) >= Number_Of_Colors or else
2155 Integer (Back) >= Number_Of_Colors then
2156 raise Constraint_Error;
2158 if Initpair (C_Short (Pair), C_Short (Fore), C_Short (Back))
2160 raise Curses_Exception;
2164 procedure Pair_Content (Pair : Color_Pair;
2165 Fore : out Color_Number;
2166 Back : out Color_Number)
2168 type C_Short_Access is access all C_Short;
2169 function Paircontent (Pair : C_Short;
2170 Fp : C_Short_Access;
2171 Bp : C_Short_Access) return C_Int;
2172 pragma Import (C, Paircontent, "pair_content");
2174 F, B : aliased C_Short;
2176 if Paircontent (C_Short (Pair), F'Access, B'Access) = Curses_Err then
2177 raise Curses_Exception;
2179 Fore := Color_Number (F);
2180 Back := Color_Number (B);
2184 function Has_Colors return Boolean
2186 function Hascolors return Curses_Bool;
2187 pragma Import (C, Hascolors, "has_colors");
2189 if Hascolors = Curses_Bool_False then
2196 procedure Init_Color (Color : Color_Number;
2201 function Initcolor (Col : C_Short;
2204 Blue : C_Short) return C_Int;
2205 pragma Import (C, Initcolor, "init_color");
2207 if Initcolor (C_Short (Color), C_Short (Red), C_Short (Green),
2208 C_Short (Blue)) = Curses_Err then
2209 raise Curses_Exception;
2213 function Can_Change_Color return Boolean
2215 function Canchangecolor return Curses_Bool;
2216 pragma Import (C, Canchangecolor, "can_change_color");
2218 if Canchangecolor = Curses_Bool_False then
2223 end Can_Change_Color;
2225 procedure Color_Content (Color : Color_Number;
2226 Red : out RGB_Value;
2227 Green : out RGB_Value;
2228 Blue : out RGB_Value)
2230 type C_Short_Access is access all C_Short;
2232 function Colorcontent (Color : C_Short; R, G, B : C_Short_Access)
2234 pragma Import (C, Colorcontent, "color_content");
2236 R, G, B : aliased C_Short;
2238 if Colorcontent (C_Short (Color), R'Access, G'Access, B'Access) =
2240 raise Curses_Exception;
2242 Red := RGB_Value (R);
2243 Green := RGB_Value (G);
2244 Blue := RGB_Value (B);
2248 ------------------------------------------------------------------------------
2249 procedure Save_Curses_Mode (Mode : Curses_Mode)
2251 function Def_Prog_Mode return C_Int;
2252 pragma Import (C, Def_Prog_Mode, "def_prog_mode");
2253 function Def_Shell_Mode return C_Int;
2254 pragma Import (C, Def_Shell_Mode, "def_shell_mode");
2259 when Curses => Err := Def_Prog_Mode;
2260 when Shell => Err := Def_Shell_Mode;
2262 if Err = Curses_Err then
2263 raise Curses_Exception;
2265 end Save_Curses_Mode;
2267 procedure Reset_Curses_Mode (Mode : Curses_Mode)
2269 function Reset_Prog_Mode return C_Int;
2270 pragma Import (C, Reset_Prog_Mode, "reset_prog_mode");
2271 function Reset_Shell_Mode return C_Int;
2272 pragma Import (C, Reset_Shell_Mode, "reset_shell_mode");
2277 when Curses => Err := Reset_Prog_Mode;
2278 when Shell => Err := Reset_Shell_Mode;
2280 if Err = Curses_Err then
2281 raise Curses_Exception;
2283 end Reset_Curses_Mode;
2285 procedure Save_Terminal_State
2287 function Savetty return C_Int;
2288 pragma Import (C, Savetty, "savetty");
2290 if Savetty = Curses_Err then
2291 raise Curses_Exception;
2293 end Save_Terminal_State;
2295 procedure Reset_Terminal_State
2297 function Resetty return C_Int;
2298 pragma Import (C, Resetty, "resetty");
2300 if Resetty = Curses_Err then
2301 raise Curses_Exception;
2303 end Reset_Terminal_State;
2305 procedure Rip_Off_Lines (Lines : Integer;
2306 Proc : Stdscr_Init_Proc)
2308 function Ripoffline (Lines : C_Int;
2309 Proc : Stdscr_Init_Proc) return C_Int;
2310 pragma Import (C, Ripoffline, "_nc_ripoffline");
2312 if Ripoffline (C_Int (Lines), Proc) = Curses_Err then
2313 raise Curses_Exception;
2317 procedure Set_Cursor_Visibility (Visibility : in out Cursor_Visibility)
2319 function Curs_Set (Curs : C_Int) return C_Int;
2320 pragma Import (C, Curs_Set, "curs_set");
2324 Res := Curs_Set (Cursor_Visibility'Pos (Visibility));
2325 if Res /= Curses_Err then
2326 Visibility := Cursor_Visibility'Val (Res);
2328 end Set_Cursor_Visibility;
2330 procedure Nap_Milli_Seconds (Ms : Natural)
2332 function Napms (Ms : C_Int) return C_Int;
2333 pragma Import (C, Napms, "napms");
2335 if Napms (C_Int (Ms)) = Curses_Err then
2336 raise Curses_Exception;
2338 end Nap_Milli_Seconds;
2339 ------------------------------------------------------------------------------
2340 include(`Public_Variables')
2341 ------------------------------------------------------------------------------
2342 procedure Transform_Coordinates
2343 (W : Window := Standard_Window;
2344 Line : in out Line_Position;
2345 Column : in out Column_Position;
2346 Dir : Transform_Direction := From_Screen)
2348 type Int_Access is access all C_Int;
2349 function Transform (W : Window;
2351 Dir : Curses_Bool) return C_Int;
2352 pragma Import (C, Transform, "wmouse_trafo");
2354 X : aliased C_Int := C_Int (Column);
2355 Y : aliased C_Int := C_Int (Line);
2356 D : Curses_Bool := Curses_Bool_False;
2359 if Dir = To_Screen then
2362 R := Transform (W, Y'Access, X'Access, D);
2363 if R = Curses_False then
2364 raise Curses_Exception;
2366 Line := Line_Position (Y);
2367 Column := Column_Position (X);
2369 end Transform_Coordinates;
2370 ------------------------------------------------------------------------------
2371 procedure Use_Default_Colors is
2372 function C_Use_Default_Colors return C_Int;
2373 pragma Import (C, C_Use_Default_Colors, "use_default_colors");
2374 Err : constant C_Int := C_Use_Default_Colors;
2376 if Err = Curses_Err then
2377 raise Curses_Exception;
2379 end Use_Default_Colors;
2381 procedure Assume_Default_Colors (Fore : Color_Number := Default_Color;
2382 Back : Color_Number := Default_Color)
2384 function C_Assume_Default_Colors (Fore : C_Int;
2385 Back : C_Int) return C_Int;
2386 pragma Import (C, C_Assume_Default_Colors, "assume_default_colors");
2388 Err : constant C_Int := C_Assume_Default_Colors (C_Int (Fore),
2391 if Err = Curses_Err then
2392 raise Curses_Exception;
2394 end Assume_Default_Colors;
2395 ------------------------------------------------------------------------------
2396 function Curses_Version return String
2398 function curses_versionC return chars_ptr;
2399 pragma Import (C, curses_versionC, "curses_version");
2400 Result : constant chars_ptr := curses_versionC;
2402 return Fill_String (Result);
2404 ------------------------------------------------------------------------------
2405 procedure Curses_Free_All is
2406 procedure curses_freeall;
2407 pragma Import (C, curses_freeall, "_nc_freeall");
2409 -- Use this only for testing: you cannot use curses after calling it,
2410 -- so it has to be the "last" thing done before exiting the program.
2411 -- This will not really free ALL of memory used by curses. That is
2412 -- because it cannot free the memory used for stdout's setbuf. The
2413 -- _nc_free_and_exit() procedure can do that, but it can be invoked
2414 -- safely only from C - and again, that only as the "last" thing done
2415 -- before exiting the program.
2417 end Curses_Free_All;
2418 ------------------------------------------------------------------------------
2419 function Use_Extended_Names (Enable : Boolean) return Boolean
2421 function use_extended_namesC (e : Curses_Bool) return C_Int;
2422 pragma Import (C, use_extended_namesC, "use_extended_names");
2424 Res : constant C_Int :=
2425 use_extended_namesC (Curses_Bool (Boolean'Pos (Enable)));
2427 if Res = C_Int (Curses_Bool_False) then
2432 end Use_Extended_Names;
2433 ------------------------------------------------------------------------------
2434 procedure Screen_Dump_To_File (Filename : String)
2436 function scr_dump (f : char_array) return C_Int;
2437 pragma Import (C, scr_dump, "scr_dump");
2438 Txt : char_array (0 .. Filename'Length);
2441 To_C (Filename, Txt, Length);
2442 if Curses_Err = scr_dump (Txt) then
2443 raise Curses_Exception;
2445 end Screen_Dump_To_File;
2447 procedure Screen_Restore_From_File (Filename : String)
2449 function scr_restore (f : char_array) return C_Int;
2450 pragma Import (C, scr_restore, "scr_restore");
2451 Txt : char_array (0 .. Filename'Length);
2454 To_C (Filename, Txt, Length);
2455 if Curses_Err = scr_restore (Txt) then
2456 raise Curses_Exception;
2458 end Screen_Restore_From_File;
2460 procedure Screen_Init_From_File (Filename : String)
2462 function scr_init (f : char_array) return C_Int;
2463 pragma Import (C, scr_init, "scr_init");
2464 Txt : char_array (0 .. Filename'Length);
2467 To_C (Filename, Txt, Length);
2468 if Curses_Err = scr_init (Txt) then
2469 raise Curses_Exception;
2471 end Screen_Init_From_File;
2473 procedure Screen_Set_File (Filename : String)
2475 function scr_set (f : char_array) return C_Int;
2476 pragma Import (C, scr_set, "scr_set");
2477 Txt : char_array (0 .. Filename'Length);
2480 To_C (Filename, Txt, Length);
2481 if Curses_Err = scr_set (Txt) then
2482 raise Curses_Exception;
2484 end Screen_Set_File;
2485 ------------------------------------------------------------------------------
2486 procedure Resize (Win : Window := Standard_Window;
2487 Number_Of_Lines : Line_Count;
2488 Number_Of_Columns : Column_Count) is
2489 function wresize (win : Window;
2491 columns : C_Int) return C_Int;
2492 pragma Import (C, wresize);
2495 C_Int (Number_Of_Lines),
2496 C_Int (Number_Of_Columns)) = Curses_Err then
2497 raise Curses_Exception;
2500 ------------------------------------------------------------------------------
2502 end Terminal_Interface.Curses;