1 ------------------------------------------------------------------------------
3 -- GNAT ncurses Binding --
5 -- Terminal_Interface.Curses --
11 -- The ncurses Ada95 binding is copyrighted 1996 by --
12 -- Juergen Pfeifer, Email: Juergen.Pfeifer@T-Online.de --
14 -- Permission is hereby granted to reproduce and distribute this --
15 -- binding by any means and for any fee, whether alone or as part --
16 -- of a larger distribution, in source or in binary form, PROVIDED --
17 -- this notice is included with any such distribution, and is not --
18 -- removed from any of its header files. Mention of ncurses and the --
19 -- author of this binding in any applications linked with it is --
20 -- highly appreciated. --
22 -- This binding comes AS IS with no warranty, implied or expressed. --
23 ------------------------------------------------------------------------------
26 ------------------------------------------------------------------------------
29 with Terminal_Interface.Curses.Aux; use Terminal_Interface.Curses.Aux;
30 with Interfaces.C; use Interfaces.C;
31 with Interfaces.C.Strings; use Interfaces.C.Strings;
32 with Ada.Characters.Handling; use Ada.Characters.Handling;
33 with Unchecked_Conversion;
35 package body Terminal_Interface.Curses is
37 use type System.Bit_Order;
39 type chtype_array is array (size_t range <>)
40 of aliased Attributed_Character;
41 pragma Pack (chtype_array);
42 pragma Convention (C, chtype_array);
44 ------------------------------------------------------------------------------
45 procedure Key_Name (Key : in Real_Key_Code;
48 function Keyname (K : C_Int) return chars_ptr;
49 pragma Import (C, Keyname, "keyname");
53 if Key <= Character'Pos (Character'Last) then
54 Ch := Character'Val (Key);
55 if Is_Control (Ch) then
56 Un_Control (Attributed_Character'(Ch => Ch,
57 Color => Color_Pair'First,
58 Attr => Normal_Video),
60 elsif Is_Graphic (Ch) then
61 Fill_String (Null_Ptr, Name);
62 Name (Name'First) := Ch;
64 Fill_String (Null_Ptr, Name);
67 Fill_String (Keyname (C_Int (Key)), Name);
70 ------------------------------------------------------------------------------
73 function Initscr return Window;
74 pragma Import (C, Initscr, "initscr");
79 if W = Null_Window then
80 raise Curses_Exception;
86 function Endwin return C_Int;
87 pragma Import (C, Endwin, "endwin");
89 if Endwin = Curses_Err then
90 raise Curses_Exception;
94 function Is_End_Window return Boolean
96 function Isendwin return C_Int;
97 pragma Import (C, Isendwin, "isendwin");
99 if Isendwin = Curses_False then
105 ------------------------------------------------------------------------------
106 procedure Move_Cursor (Win : in Window := Standard_Window;
107 Line : in Line_Position;
108 Column : in Column_Position)
110 function Wmove (Win : Window;
114 pragma Import (C, Wmove, "wmove");
116 if Wmove (Win, C_Int (Line), C_Int (Column)) = Curses_Err then
117 raise Curses_Exception;
120 ------------------------------------------------------------------------------
121 procedure Add (Win : in Window := Standard_Window;
122 Ch : in Attributed_Character)
124 function Waddch (W : Window;
125 Ch : C_Int) return C_Int;
126 pragma Import (C, Waddch, "waddch");
128 if Waddch (Win, Chtype_To_Cint (Ch)) = Curses_Err then
129 raise Curses_Exception;
133 procedure Add (Win : in Window := Standard_Window;
138 Attributed_Character'(Ch => Ch,
139 Color => Color_Pair'First,
140 Attr => Normal_Video));
144 (Win : in Window := Standard_Window;
145 Line : in Line_Position;
146 Column : in Column_Position;
147 Ch : in Attributed_Character)
149 function mvwaddch (W : Window;
152 Ch : C_Int) return C_Int;
153 pragma Import (C, mvwaddch, "mvwaddch");
155 if mvwaddch (Win, C_Int (Line),
157 Chtype_To_CInt (Ch)) = Curses_Err then
158 raise Curses_Exception;
163 (Win : in Window := Standard_Window;
164 Line : in Line_Position;
165 Column : in Column_Position;
172 Attributed_Character'(Ch => Ch,
173 Color => Color_Pair'First,
174 Attr => Normal_Video));
177 procedure Add_With_Immediate_Echo
178 (Win : in Window := Standard_Window;
179 Ch : in Attributed_Character)
181 function Wechochar (W : Window;
182 Ch : C_Int) return C_Int;
183 pragma Import (C, Wechochar, "wechochar");
185 if Wechochar (Win, Chtype_To_CInt (Ch)) = Curses_Err then
186 raise Curses_Exception;
188 end Add_With_Immediate_Echo;
190 procedure Add_With_Immediate_Echo
191 (Win : in Window := Standard_Window;
195 Add_With_Immediate_Echo
197 Attributed_Character'(Ch => Ch,
198 Color => Color_Pair'First,
199 Attr => Normal_Video));
200 end Add_With_Immediate_Echo;
201 ------------------------------------------------------------------------------
202 function Create (Number_Of_Lines : Line_Count;
203 Number_Of_Columns : Column_Count;
204 First_Line_Position : Line_Position;
205 First_Column_Position : Column_Position) return Window
207 function Newwin (Number_Of_Lines : C_Int;
208 Number_Of_Columns : C_Int;
209 First_Line_Position : C_Int;
210 First_Column_Position : C_Int) return Window;
211 pragma Import (C, Newwin, "newwin");
215 W := Newwin (C_Int (Number_Of_Lines),
216 C_Int (Number_Of_Columns),
217 C_Int (First_Line_Position),
218 C_Int (First_Column_Position));
219 if W = Null_Window then
220 raise Curses_Exception;
225 procedure Delete (Win : in out Window)
227 function Wdelwin (W : Window) return C_Int;
228 pragma Import (C, Wdelwin, "delwin");
230 if Wdelwin (Win) = Curses_Err then
231 raise Curses_Exception;
237 (Win : Window := Standard_Window;
238 Number_Of_Lines : Line_Count;
239 Number_Of_Columns : Column_Count;
240 First_Line_Position : Line_Position;
241 First_Column_Position : Column_Position) return Window
245 Number_Of_Lines : C_Int;
246 Number_Of_Columns : C_Int;
247 First_Line_Position : C_Int;
248 First_Column_Position : C_Int) return Window;
249 pragma Import (C, Subwin, "subwin");
254 C_Int (Number_Of_Lines),
255 C_Int (Number_Of_Columns),
256 C_Int (First_Line_Position),
257 C_Int (First_Column_Position));
258 if W = Null_Window then
259 raise Curses_Exception;
264 function Derived_Window
265 (Win : Window := Standard_Window;
266 Number_Of_Lines : Line_Count;
267 Number_Of_Columns : Column_Count;
268 First_Line_Position : Line_Position;
269 First_Column_Position : Column_Position) return Window
273 Number_Of_Lines : C_Int;
274 Number_Of_Columns : C_Int;
275 First_Line_Position : C_Int;
276 First_Column_Position : C_Int) return Window;
277 pragma Import (C, Derwin, "derwin");
282 C_Int (Number_Of_Lines),
283 C_Int (Number_Of_Columns),
284 C_Int (First_Line_Position),
285 C_Int (First_Column_Position));
286 if W = Null_Window then
287 raise Curses_Exception;
292 function Duplicate (Win : Window) return Window
294 function Dupwin (Win : Window) return Window;
295 pragma Import (C, Dupwin, "dupwin");
297 W : Window := Dupwin (Win);
299 if W = Null_Window then
300 raise Curses_Exception;
305 procedure Move_Window (Win : in Window;
306 Line : in Line_Position;
307 Column : in Column_Position)
309 function Mvwin (Win : Window;
311 Column : C_Int) return C_Int;
312 pragma Import (C, Mvwin, "mvwin");
314 if Mvwin (Win, C_Int (Line), C_Int (Column)) = Curses_Err then
315 raise Curses_Exception;
319 procedure Move_Derived_Window (Win : in Window;
320 Line : in Line_Position;
321 Column : in Column_Position)
323 function Mvderwin (Win : Window;
325 Column : C_Int) return C_Int;
326 pragma Import (C, Mvderwin, "mvderwin");
328 if Mvderwin (Win, C_Int (Line), C_Int (Column)) = Curses_Err then
329 raise Curses_Exception;
331 end Move_Derived_Window;
333 procedure Set_Synch_Mode (Win : in Window := Standard_Window;
334 Mode : in Boolean := False)
336 function Syncok (Win : Window;
337 Mode : C_Int) return C_Int;
338 pragma Import (C, Syncok, "syncok");
340 if Syncok (Win, Boolean'Pos (Mode)) = Curses_Err then
341 raise Curses_Exception;
344 ------------------------------------------------------------------------------
345 procedure Add (Win : in Window := Standard_Window;
347 Len : in Integer := -1)
349 type Char_Ptr is access all Interfaces.C.Char;
350 function Waddnstr (Win : Window;
352 Len : Integer := -1) return C_Int;
353 pragma Import (C, Waddnstr, "waddnstr");
355 Txt : char_array (0 .. Str'Length);
358 To_C (Str, Txt, Length);
359 if Waddnstr (Win, Txt (Txt'First)'Access, Len) = Curses_Err then
360 raise Curses_Exception;
365 (Win : in Window := Standard_Window;
366 Line : in Line_Position;
367 Column : in Column_Position;
369 Len : in Integer := -1)
372 Move_Cursor (Win, Line, Column);
375 ------------------------------------------------------------------------------
377 (Win : in Window := Standard_Window;
378 Str : in Attributed_String;
379 Len : in Integer := -1)
381 type Chtype_Ptr is access all Attributed_Character;
382 function Waddchnstr (Win : Window;
384 Len : Integer := -1) return C_Int;
385 pragma Import (C, Waddchnstr, "waddchnstr");
387 Txt : chtype_array (0 .. Str'Length);
389 for Length in 1 .. size_t (Str'Length) loop
390 Txt (Length - 1) := Str (Natural (Length));
392 Txt (Str'Length) := Default_Character;
393 if Waddchnstr (Win, Txt (Txt'First)'Access, Len) = Curses_Err then
394 raise Curses_Exception;
399 (Win : in Window := Standard_Window;
400 Line : in Line_Position;
401 Column : in Column_Position;
402 Str : in Attributed_String;
403 Len : in Integer := -1)
406 Move_Cursor (Win, Line, Column);
409 ------------------------------------------------------------------------------
411 (Win : in Window := Standard_Window;
412 Left_Side_Symbol : in Attributed_Character := Default_Character;
413 Right_Side_Symbol : in Attributed_Character := Default_Character;
414 Top_Side_Symbol : in Attributed_Character := Default_Character;
415 Bottom_Side_Symbol : in Attributed_Character := Default_Character;
416 Upper_Left_Corner_Symbol : in Attributed_Character := Default_Character;
417 Upper_Right_Corner_Symbol : in Attributed_Character := Default_Character;
418 Lower_Left_Corner_Symbol : in Attributed_Character := Default_Character;
419 Lower_Right_Corner_Symbol : in Attributed_Character := Default_Character)
421 function Wborder (W : Window;
429 LRC : C_Int) return C_Int;
430 pragma Import (C, Wborder, "wborder");
433 Chtype_To_CInt (Left_Side_Symbol),
434 Chtype_To_CInt (Right_Side_Symbol),
435 Chtype_To_CInt (Top_Side_Symbol),
436 Chtype_To_CInt (Bottom_Side_Symbol),
437 Chtype_To_CInt (Upper_Left_Corner_Symbol),
438 Chtype_To_CInt (Upper_Right_Corner_Symbol),
439 Chtype_To_CInt (Lower_Left_Corner_Symbol),
440 Chtype_To_CInt (Lower_Right_Corner_Symbol)
443 raise Curses_Exception;
448 (Win : in Window := Standard_Window;
449 Vertical_Symbol : in Attributed_Character := Default_Character;
450 Horizontal_Symbol : in Attributed_Character := Default_Character)
454 Vertical_Symbol, Vertical_Symbol,
455 Horizontal_Symbol, Horizontal_Symbol);
458 procedure Horizontal_Line
459 (Win : in Window := Standard_Window;
460 Line_Size : in Natural;
461 Line_Symbol : in Attributed_Character := Default_Character)
463 function Whline (W : Window;
465 Len : C_Int) return C_Int;
466 pragma Import (C, Whline, "whline");
469 Chtype_To_CInt (Line_Symbol),
470 C_Int (Line_Size)) = Curses_Err then
471 raise Curses_Exception;
475 procedure Vertical_Line
476 (Win : in Window := Standard_Window;
477 Line_Size : in Natural;
478 Line_Symbol : in Attributed_Character := Default_Character)
480 function Wvline (W : Window;
482 Len : C_Int) return C_Int;
483 pragma Import (C, Wvline, "wvline");
486 Chtype_To_CInt (Line_Symbol),
487 C_Int (Line_Size)) = Curses_Err then
488 raise Curses_Exception;
492 ------------------------------------------------------------------------------
493 function Get_Keystroke (Win : Window := Standard_Window)
496 function Wgetch (W : Window) return C_Int;
497 pragma Import (C, Wgetch, "wgetch");
499 C : constant C_Int := Wgetch (Win);
501 if C = Curses_Err then
504 return Real_Key_Code (C);
508 procedure Undo_Keystroke (Key : in Real_Key_Code)
510 function Ungetch (Ch : C_Int) return C_Int;
511 pragma Import (C, Ungetch, "ungetch");
513 if Ungetch (C_Int (Key)) = Curses_Err then
514 raise Curses_Exception;
518 function Has_Key (Key : Special_Key_Code) return Boolean
520 function Haskey (Key : C_Int) return C_Int;
521 pragma Import (C, Haskey, "has_key");
523 if Haskey (C_Int (Key)) = Curses_False then
530 function Is_Function_Key (Key : Special_Key_Code) return Boolean
532 L : constant Special_Key_Code := Special_Key_Code (Natural (Key_F0) +
533 Natural (Function_Key_Number'Last));
535 if (Key >= Key_F0) and then (Key <= L) then
542 function Function_Key (Key : Real_Key_Code)
543 return Function_Key_Number
546 if Is_Function_Key (Key) then
547 return Function_Key_Number (Key - Key_F0);
549 raise Constraint_Error;
553 function Function_Key_Code (Key : Function_Key_Number) return Real_Key_Code
556 return Real_Key_Code (Natural (Key_F0) + Natural (Key));
557 end Function_Key_Code;
558 ------------------------------------------------------------------------------
559 procedure Switch_Character_Attribute
560 (Win : in Window := Standard_Window;
561 Attr : in Character_Attribute_Set := Normal_Video;
562 On : in Boolean := True)
564 function Wattron (Win : Window;
565 C_Attr : C_Int) return C_Int;
566 pragma Import (C, Wattron, "wattr_on");
567 function Wattroff (Win : Window;
568 C_Attr : C_Int) return C_Int;
569 pragma Import (C, Wattroff, "wattr_off");
570 -- In Ada we use the On Boolean to control whether or not we want to
571 -- switch on or off the attributes in the set.
573 AC : constant Attributed_Character := (Ch => Character'First,
574 Color => Color_Pair'First,
578 Err := Wattron (Win, Chtype_To_CInt (AC));
580 Err := Wattroff (Win, Chtype_To_CInt (AC));
582 if Err = Curses_Err then
583 raise Curses_Exception;
585 end Switch_Character_Attribute;
587 procedure Set_Character_Attributes
588 (Win : in Window := Standard_Window;
589 Attr : in Character_Attribute_Set := Normal_Video;
590 Color : in Color_Pair := Color_Pair'First)
592 function Wattrset (Win : Window;
593 C_Attr : C_Int) return C_Int;
594 pragma Import (C, Wattrset, "wattrset"); -- ??? wattr_set
597 Chtype_To_CInt (Attributed_Character'
598 (Ch => Character'First,
600 Attr => Attr))) = Curses_Err then
601 raise Curses_Exception;
603 end Set_Character_Attributes;
605 function Get_Character_Attribute (Win : Window := Standard_Window)
606 return Character_Attribute_Set
608 function Wattrget (Win : Window) return C_Int;
609 pragma Import (C, Wattrget, "wattr_get");
611 Ch : Attributed_Character := CInt_To_Chtype (Wattrget (Win));
614 end Get_Character_Attribute;
616 function Get_Character_Attribute (Win : Window := Standard_Window)
619 function Wattrget (Win : Window) return C_Int;
620 pragma Import (C, Wattrget, "wattr_get");
622 Ch : Attributed_Character := CInt_To_Chtype (Wattrget (Win));
625 end Get_Character_Attribute;
627 procedure Change_Attributes
628 (Win : in Window := Standard_Window;
629 Count : in Integer := -1;
630 Attr : in Character_Attribute_Set := Normal_Video;
631 Color : in Color_Pair := Color_Pair'First)
633 function Wchgat (Win : Window;
637 Opts : System.Address := System.Null_Address)
639 pragma Import (C, Wchgat, "wchgat");
641 Ch : constant Attributed_Character :=
642 (Ch => Character'First, Color => Color_Pair'First, Attr => Attr);
644 if Wchgat (Win, C_Int (Count), Chtype_To_CInt (Ch),
645 C_Short (Color)) = Curses_Err then
646 raise Curses_Exception;
648 end Change_Attributes;
650 procedure Change_Attributes
651 (Win : in Window := Standard_Window;
652 Line : in Line_Position := Line_Position'First;
653 Column : in Column_Position := Column_Position'First;
654 Count : in Integer := -1;
655 Attr : in Character_Attribute_Set := Normal_Video;
656 Color : in Color_Pair := Color_Pair'First)
659 Move_Cursor (Win, Line, Column);
660 Change_Attributes (Win, Count, Attr, Color);
661 end Change_Attributes;
662 ------------------------------------------------------------------------------
665 function Beeper return C_Int;
666 pragma Import (C, Beeper, "beep");
668 if Beeper = Curses_Err then
669 raise Curses_Exception;
673 procedure Flash_Screen
675 function Flash return C_Int;
676 pragma Import (C, Flash, "flash");
678 if Flash = Curses_Err then
679 raise Curses_Exception;
682 ------------------------------------------------------------------------------
683 procedure Set_Cbreak_Mode (SwitchOn : in Boolean := True)
685 function Cbreak return C_Int;
686 pragma Import (C, Cbreak, "cbreak");
687 function NoCbreak return C_Int;
688 pragma Import (C, NoCbreak, "nocbreak");
697 if Err = Curses_Err then
698 raise Curses_Exception;
702 procedure Set_Raw_Mode (SwitchOn : in Boolean := True)
704 function Raw return C_Int;
705 pragma Import (C, Raw, "raw");
706 function NoRaw return C_Int;
707 pragma Import (C, NoRaw, "noraw");
716 if Err = Curses_Err then
717 raise Curses_Exception;
721 procedure Set_Echo_Mode (SwitchOn : in Boolean := True)
723 function Echo return C_Int;
724 pragma Import (C, Echo, "echo");
725 function NoEcho return C_Int;
726 pragma Import (C, NoEcho, "noecho");
735 if Err = Curses_Err then
736 raise Curses_Exception;
740 procedure Set_Meta_Mode (Win : in Window := Standard_Window;
741 SwitchOn : in Boolean := True)
743 function Meta (W : Window; Mode : C_Int) return C_Int;
744 pragma Import (C, Meta, "meta");
746 if Meta (Win, Boolean'Pos (SwitchOn)) = Curses_Err then
747 raise Curses_Exception;
751 procedure Set_KeyPad_Mode (Win : in Window := Standard_Window;
752 SwitchOn : in Boolean := True)
754 function Keypad (W : Window; Mode : C_Int) return C_Int;
755 pragma Import (C, Keypad, "keypad");
757 if Keypad (Win, Boolean'Pos (SwitchOn)) = Curses_Err then
758 raise Curses_Exception;
762 procedure Half_Delay (Amount : in Half_Delay_Amount)
764 function Halfdelay (Amount : C_Int) return C_Int;
765 pragma Import (C, Halfdelay, "halfdelay");
767 if Halfdelay (C_Int (Amount)) = Curses_Err then
768 raise Curses_Exception;
772 procedure Set_Flush_On_Interrupt_Mode
773 (Win : in Window := Standard_Window;
774 Mode : in Boolean := True)
776 function Intrflush (Win : Window; Mode : C_Int) return C_Int;
777 pragma Import (C, Intrflush, "intrflush");
779 if Intrflush (Win, Boolean'Pos (Mode)) = Curses_Err then
780 raise Curses_Exception;
782 end Set_Flush_On_Interrupt_Mode;
784 procedure Set_Queue_Interrupt_Mode
785 (Win : in Window := Standard_Window;
786 Flush : in Boolean := True)
789 pragma Import (C, Qiflush, "qiflush");
790 procedure No_Qiflush;
791 pragma Import (C, No_Qiflush, "noqiflush");
798 end Set_Queue_Interrupt_Mode;
800 procedure Set_NoDelay_Mode
801 (Win : in Window := Standard_Window;
802 Mode : in Boolean := False)
804 function Nodelay (Win : Window; Mode : C_Int) return C_Int;
805 pragma Import (C, Nodelay, "nodelay");
807 if Nodelay (Win, Boolean'Pos (Mode)) = Curses_Err then
808 raise Curses_Exception;
810 end Set_NoDelay_Mode;
812 procedure Set_Timeout_Mode (Win : in Window := Standard_Window;
813 Mode : in Timeout_Mode;
816 function Wtimeout (Win : Window; Amount : C_Int) return C_Int;
817 pragma Import (C, Wtimeout, "wtimeout");
822 when Blocking => Time := -1;
823 when Non_Blocking => Time := 0;
826 raise CONSTRAINT_ERROR;
828 Time := C_Int (Amount);
830 if Wtimeout (Win, Time) = Curses_Err then
831 raise Curses_Exception;
833 end Set_Timeout_Mode;
835 procedure Set_Escape_Timer_Mode
836 (Win : in Window := Standard_Window;
837 Timer_Off : in Boolean := False)
839 function Notimeout (Win : Window; Mode : C_Int) return C_Int;
840 pragma Import (C, Notimeout, "notimeout");
842 if Notimeout (Win, Boolean'Pos (Timer_Off)) = Curses_Err then
843 raise Curses_Exception;
845 end Set_Escape_Timer_Mode;
847 ------------------------------------------------------------------------------
848 procedure Set_NL_Mode (SwitchOn : in Boolean := True)
850 function NL return C_Int;
851 pragma Import (C, NL, "nl");
852 function NoNL return C_Int;
853 pragma Import (C, NoNL, "nonl");
862 if Err = Curses_Err then
863 raise Curses_Exception;
867 procedure Clear_On_Next_Update
868 (Win : in Window := Standard_Window;
869 Do_Clear : in Boolean := True)
871 function Clear_Ok (W : Window; Flag : C_Int) return C_Int;
872 pragma Import (C, Clear_Ok, "clearok");
874 if Clear_Ok (Win, Boolean'Pos (Do_Clear)) = Curses_Err then
875 raise Curses_Exception;
877 end Clear_On_Next_Update;
879 procedure Use_Insert_Delete_Line
880 (Win : in Window := Standard_Window;
881 Do_Idl : in Boolean := True)
883 function IDL_Ok (W : Window; Flag : C_Int) return C_Int;
884 pragma Import (C, IDL_Ok, "idlok");
886 if IDL_Ok (Win, Boolean'Pos (Do_Idl)) = Curses_Err then
887 raise Curses_Exception;
889 end Use_Insert_Delete_Line;
891 procedure Use_Insert_Delete_Character
892 (Win : in Window := Standard_Window;
893 Do_Idc : in Boolean := True)
895 function IDC_Ok (W : Window; Flag : C_Int) return C_Int;
896 pragma Import (C, IDC_Ok, "idcok");
898 if IDC_Ok (Win, Boolean'Pos (Do_Idc)) = Curses_Err then
899 raise Curses_Exception;
901 end Use_Insert_Delete_Character;
903 procedure Leave_Cursor_After_Update
904 (Win : in Window := Standard_Window;
905 Do_Leave : in Boolean := True)
907 function Leave_Ok (W : Window; Flag : C_Int) return C_Int;
908 pragma Import (C, Leave_Ok, "leaveok");
910 if Leave_Ok (Win, Boolean'Pos (Do_Leave)) = Curses_Err then
911 raise Curses_Exception;
913 end Leave_Cursor_After_Update;
915 procedure Immediate_Update_Mode
916 (Win : in Window := Standard_Window;
917 Mode : in Boolean := False)
919 function Immedok (Win : Window; Mode : C_Int) return C_Int;
920 pragma Import (C, Immedok, "immedok");
922 if Immedok (Win, Boolean'Pos (Mode)) = Curses_Err then
923 raise Curses_Exception;
925 end Immediate_Update_Mode;
927 procedure Allow_Scrolling
928 (Win : in Window := Standard_Window;
929 Mode : in Boolean := False)
931 function Scrollok (Win : Window; Mode : C_Int) return C_Int;
932 pragma Import (C, Scrollok, "scrollok");
934 if Scrollok (Win, Boolean'Pos (Mode)) = Curses_Err then
935 raise Curses_Exception;
939 function Scrolling_Allowed (Win : Window := Standard_Window) return Boolean
941 function Is_Scroll (Win : Window) return C_Int;
942 pragma Import (C, Is_Scroll, "_nc_ada_isscroll");
944 Res : constant C_Int := Is_Scroll (Win);
947 when Curses_True => return True;
948 when Curses_False => return False;
949 when others => raise Curses_Exception;
951 end Scrolling_Allowed;
953 procedure Set_Scroll_Region
954 (Win : in Window := Standard_Window;
955 Top_Line : in Line_Position;
956 Bottom_Line : in Line_Position)
958 function Wsetscrreg (Win : Window;
960 Col : C_Int) return C_Int;
961 pragma Import (C, Wsetscrreg, "wsetscrreg");
963 if Wsetscrreg (Win, C_Int (Top_Line), C_Int (Bottom_Line))
965 raise Curses_Exception;
967 end Set_Scroll_Region;
968 ------------------------------------------------------------------------------
969 procedure Update_Screen
971 function Do_Update return C_Int;
972 pragma Import (C, Do_Update, "doupdate");
974 if Do_Update = Curses_Err then
975 raise Curses_Exception;
979 procedure Refresh (Win : in Window := Standard_Window)
981 function Wrefresh (W : Window) return C_Int;
982 pragma Import (C, Wrefresh, "wrefresh");
984 if Wrefresh (Win) = Curses_Err then
985 raise Curses_Exception;
989 procedure Refresh_Without_Update
990 (Win : in Window := Standard_Window)
992 function Wnoutrefresh (W : Window) return C_Int;
993 pragma Import (C, Wnoutrefresh, "wnoutrefresh");
995 if Wnoutrefresh (Win) = Curses_Err then
996 raise Curses_Exception;
998 end Refresh_Without_Update;
1000 procedure Redraw (Win : in Window := Standard_Window)
1002 function Redrawwin (Win : Window) return C_Int;
1003 pragma Import (C, Redrawwin, "redrawwin");
1005 if Redrawwin (Win) = Curses_Err then
1006 raise Curses_Exception;
1011 (Win : in Window := Standard_Window;
1012 Begin_Line : in Line_Position;
1013 Line_Count : in Positive)
1015 function Wredrawln (Win : Window; First : C_Int; Cnt : C_Int)
1017 pragma Import (C, Wredrawln, "wredrawln");
1021 C_Int (Line_Count)) = Curses_Err then
1022 raise Curses_Exception;
1026 ------------------------------------------------------------------------------
1027 procedure Erase (Win : in Window := Standard_Window)
1029 function Werase (W : Window) return C_Int;
1030 pragma Import (C, Werase, "werase");
1032 if Werase (Win) = Curses_Err then
1033 raise Curses_Exception;
1037 procedure Clear (Win : in Window := Standard_Window)
1039 function Wclear (W : Window) return C_Int;
1040 pragma Import (C, Wclear, "wclear");
1042 if Wclear (Win) = Curses_Err then
1043 raise Curses_Exception;
1047 procedure Clear_To_End_Of_Screen (Win : in Window := Standard_Window)
1049 function Wclearbot (W : Window) return C_Int;
1050 pragma Import (C, Wclearbot, "wclrtobot");
1052 if Wclearbot (Win) = Curses_Err then
1053 raise Curses_Exception;
1055 end Clear_To_End_Of_Screen;
1057 procedure Clear_To_End_Of_Line (Win : in Window := Standard_Window)
1059 function Wcleareol (W : Window) return C_Int;
1060 pragma Import (C, Wcleareol, "wclrtoeol");
1062 if Wcleareol (Win) = Curses_Err then
1063 raise Curses_Exception;
1065 end Clear_To_End_Of_Line;
1066 ------------------------------------------------------------------------------
1067 procedure Set_Background
1068 (Win : in Window := Standard_Window;
1069 Ch : in Attributed_Character)
1071 procedure WBackground (W : in Window; Ch : in C_Int);
1072 pragma Import (C, WBackground, "wbkgdset");
1074 WBackground (Win, Chtype_To_CInt (Ch));
1077 procedure Change_Background
1078 (Win : in Window := Standard_Window;
1079 Ch : in Attributed_Character)
1081 function WChangeBkgd (W : Window; Ch : C_Int)
1083 pragma Import (C, WChangeBkgd, "wbkgd");
1085 if WChangeBkgd (Win, Chtype_To_CInt (Ch)) = Curses_Err then
1086 raise Curses_Exception;
1088 end Change_Background;
1090 function Get_Background (Win : Window := Standard_Window)
1091 return Attributed_Character
1093 function Wgetbkgd (Win : Window) return C_Int;
1094 pragma Import (C, Wgetbkgd, "getbkgd");
1096 return CInt_To_Chtype (Wgetbkgd (Win));
1098 ------------------------------------------------------------------------------
1099 procedure Change_Lines_Status (Win : in Window := Standard_Window;
1100 Start : in Line_Position;
1101 Count : in Positive;
1104 function Wtouchln (Win : Window;
1107 Chg : C_Int) return C_Int;
1108 pragma Import (C, Wtouchln, "wtouchln");
1110 if Wtouchln (Win, C_Int (Start), C_Int (Count),
1111 C_Int (Boolean'Pos (State))) = Curses_Err then
1112 raise Curses_Exception;
1114 end Change_Lines_Status;
1116 procedure Touch (Win : in Window := Standard_Window)
1119 X : Column_Position;
1121 Get_Size (Win, Y, X);
1122 Change_Lines_Status (Win, 0, Positive (Y), True);
1125 procedure Untouch (Win : in Window := Standard_Window)
1128 X : Column_Position;
1130 Get_Size (Win, Y, X);
1131 Change_Lines_Status (Win, 0, Positive (Y), False);
1134 procedure Touch (Win : in Window := Standard_Window;
1135 Start : in Line_Position;
1136 Count : in Positive)
1139 Change_Lines_Status (Win, Start, Count, True);
1143 (Win : Window := Standard_Window;
1144 Line : Line_Position) return Boolean
1146 function WLineTouched (W : Window; L : C_Int) return C_Int;
1147 pragma Import (C, WLineTouched, "is_linetouched");
1149 if WLineTouched (Win, C_Int (Line)) = Curses_False then
1157 (Win : Window := Standard_Window) return Boolean
1159 function WWinTouched (W : Window) return C_Int;
1160 pragma Import (C, WWinTouched, "is_wintouched");
1162 if WWinTouched (Win) = Curses_False then
1168 ------------------------------------------------------------------------------
1170 (Source_Window : in Window;
1171 Destination_Window : in Window;
1172 Source_Top_Row : in Line_Position;
1173 Source_Left_Column : in Column_Position;
1174 Destination_Top_Row : in Line_Position;
1175 Destination_Left_Column : in Column_Position;
1176 Destination_Bottom_Row : in Line_Position;
1177 Destination_Right_Column : in Column_Position;
1178 Non_Destructive_Mode : in Boolean := True)
1180 function Copywin (Src : Window;
1188 Ndm : C_Int) return C_Int;
1189 pragma Import (C, Copywin, "copywin");
1191 if Copywin (Source_Window,
1193 C_Int (Source_Top_Row),
1194 C_Int (Source_Left_Column),
1195 C_Int (Destination_Top_Row),
1196 C_Int (Destination_Left_Column),
1197 C_Int (Destination_Bottom_Row),
1198 C_Int (Destination_Right_Column),
1199 Boolean'Pos (Non_Destructive_Mode)
1201 raise Curses_Exception;
1206 (Source_Window : in Window;
1207 Destination_Window : in Window)
1209 function Overwrite (Src : Window; Dst : Window) return C_Int;
1210 pragma Import (C, Overwrite, "overwrite");
1212 if Overwrite (Source_Window, Destination_Window) = Curses_Err then
1213 raise Curses_Exception;
1218 (Source_Window : in Window;
1219 Destination_Window : in Window)
1221 function Overlay (Src : Window; Dst : Window) return C_Int;
1222 pragma Import (C, Overlay, "overlay");
1224 if Overlay (Source_Window, Destination_Window) = Curses_Err then
1225 raise Curses_Exception;
1229 ------------------------------------------------------------------------------
1230 procedure Insert_Delete_Lines
1231 (Win : in Window := Standard_Window;
1232 Lines : in Integer := 1) -- default is to insert one line above
1234 function Winsdelln (W : Window; N : C_Int) return C_Int;
1235 pragma Import (C, Winsdelln, "winsdelln");
1237 if Winsdelln (Win, C_Int (Lines)) = Curses_Err then
1238 raise Curses_Exception;
1240 end Insert_Delete_Lines;
1242 procedure Delete_Line (Win : in Window := Standard_Window)
1245 Insert_Delete_Lines (Win, -1);
1248 procedure Insert_Line (Win : in Window := Standard_Window)
1251 Insert_Delete_Lines (Win, 1);
1253 ------------------------------------------------------------------------------
1255 (Win : in Window := Standard_Window;
1256 Number_Of_Lines : out Line_Count;
1257 Number_Of_Columns : out Column_Count)
1259 type Int_Access is access all C_Int;
1260 function Getmaxyx (W : Window; Y, X : Int_Access) return C_Int;
1261 pragma Import (C, Getmaxyx, "_nc_ada_getmaxyx");
1263 Y, X : aliased C_Int;
1264 Err : constant C_Int := Getmaxyx (Win, Y'Access, X'Access);
1266 if Err = Curses_Err then
1267 raise Curses_Exception;
1269 Number_Of_Lines := Line_Count (Y);
1270 Number_Of_Columns := Column_Count (X);
1274 procedure Get_Window_Position
1275 (Win : in Window := Standard_Window;
1276 Top_Left_Line : out Line_Position;
1277 Top_Left_Column : out Column_Position)
1279 type Int_Access is access all C_Int;
1280 function Getbegyx (W : Window; Y, X : Int_Access) return C_Int;
1281 pragma Import (C, Getbegyx, "_nc_ada_getbegyx");
1283 Y, X : aliased C_Int;
1284 Err : constant C_Int := Getbegyx (Win, Y'Access, X'Access);
1286 if Err = Curses_Err then
1287 raise Curses_Exception;
1289 Top_Left_Line := Line_Position (Y);
1290 Top_Left_Column := Column_Position (X);
1292 end Get_Window_Position;
1294 procedure Get_Cursor_Position
1295 (Win : in Window := Standard_Window;
1296 Line : out Line_Position;
1297 Column : out Column_Position)
1299 type Int_Access is access all C_Int;
1300 function Getyx (W : Window; Y, X : Int_Access) return C_Int;
1301 pragma Import (C, Getyx, "_nc_ada_getyx");
1303 Y, X : aliased C_Int;
1304 Err : constant C_Int := Getyx (Win, Y'Access, X'Access);
1306 if Err = Curses_Err then
1307 raise Curses_Exception;
1309 Line := Line_Position (Y);
1310 Column := Column_Position (X);
1312 end Get_Cursor_Position;
1314 procedure Get_Origin_Relative_To_Parent
1316 Top_Left_Line : out Line_Position;
1317 Top_Left_Column : out Column_Position;
1318 Is_Not_A_Subwindow : out Boolean)
1320 type Int_Access is access all C_Int;
1321 function Getparyx (W : Window; Y, X : Int_Access) return C_Int;
1322 pragma Import (C, Getparyx, "_nc_ada_getparyx");
1324 Y, X : aliased C_Int;
1325 Err : constant C_Int := Getparyx (Win, Y'Access, X'Access);
1327 if Err = Curses_Err then
1328 raise Curses_Exception;
1331 Top_Left_Line := Line_Position'Last;
1332 Top_Left_Column := Column_Position'Last;
1333 Is_Not_A_Subwindow := True;
1335 Top_Left_Line := Line_Position (Y);
1336 Top_Left_Column := Column_Position (X);
1337 Is_Not_A_Subwindow := False;
1340 end Get_Origin_Relative_To_Parent;
1341 ------------------------------------------------------------------------------
1342 function New_Pad (Lines : Line_Count;
1343 Columns : Column_Count) return Window
1345 function Newpad (Lines : C_Int; Columns : C_Int) return Window;
1346 pragma Import (C, Newpad, "newpad");
1350 W := Newpad (C_Int (Lines), C_Int (Columns));
1351 if W = Null_Window then
1352 raise Curses_Exception;
1359 Number_Of_Lines : Line_Count;
1360 Number_Of_Columns : Column_Count;
1361 First_Line_Position : Line_Position;
1362 First_Column_Position : Column_Position) return Window
1366 Number_Of_Lines : C_Int;
1367 Number_Of_Columns : C_Int;
1368 First_Line_Position : C_Int;
1369 First_Column_Position : C_Int) return Window;
1370 pragma Import (C, Subpad, "subpad");
1375 C_Int (Number_Of_Lines),
1376 C_Int (Number_Of_Columns),
1377 C_Int (First_Line_Position),
1378 C_Int (First_Column_Position));
1379 if W = Null_Window then
1380 raise Curses_Exception;
1387 Source_Top_Row : in Line_Position;
1388 Source_Left_Column : in Column_Position;
1389 Destination_Top_Row : in Line_Position;
1390 Destination_Left_Column : in Column_Position;
1391 Destination_Bottom_Row : in Line_Position;
1392 Destination_Right_Column : in Column_Position)
1396 Source_Top_Row : C_Int;
1397 Source_Left_Column : C_Int;
1398 Destination_Top_Row : C_Int;
1399 Destination_Left_Column : C_Int;
1400 Destination_Bottom_Row : C_Int;
1401 Destination_Right_Column : C_Int) return C_Int;
1402 pragma Import (C, Prefresh, "prefresh");
1405 C_Int (Source_Top_Row),
1406 C_Int (Source_Left_Column),
1407 C_Int (Destination_Top_Row),
1408 C_Int (Destination_Left_Column),
1409 C_Int (Destination_Bottom_Row),
1410 C_Int (Destination_Right_Column)) = Curses_Err then
1411 raise Curses_Exception;
1415 procedure Refresh_Without_Update
1417 Source_Top_Row : in Line_Position;
1418 Source_Left_Column : in Column_Position;
1419 Destination_Top_Row : in Line_Position;
1420 Destination_Left_Column : in Column_Position;
1421 Destination_Bottom_Row : in Line_Position;
1422 Destination_Right_Column : in Column_Position)
1424 function Pnoutrefresh
1426 Source_Top_Row : C_Int;
1427 Source_Left_Column : C_Int;
1428 Destination_Top_Row : C_Int;
1429 Destination_Left_Column : C_Int;
1430 Destination_Bottom_Row : C_Int;
1431 Destination_Right_Column : C_Int) return C_Int;
1432 pragma Import (C, Pnoutrefresh, "pnoutrefresh");
1434 if Pnoutrefresh (Pad,
1435 C_Int (Source_Top_Row),
1436 C_Int (Source_Left_Column),
1437 C_Int (Destination_Top_Row),
1438 C_Int (Destination_Left_Column),
1439 C_Int (Destination_Bottom_Row),
1440 C_Int (Destination_Right_Column)) = Curses_Err then
1441 raise Curses_Exception;
1443 end Refresh_Without_Update;
1445 procedure Add_Character_To_Pad_And_Echo_It
1447 Ch : in Attributed_Character)
1449 function Pechochar (Pad : Window; Ch : C_Int)
1451 pragma Import (C, Pechochar, "pechochar");
1453 if Pechochar (Pad, Chtype_To_CInt (Ch)) = Curses_Err then
1454 raise Curses_Exception;
1456 end Add_Character_To_Pad_And_Echo_It;
1458 procedure Add_Character_To_Pad_And_Echo_It
1463 Add_Character_To_Pad_And_Echo_It
1465 Attributed_Character'(Ch => Ch,
1466 Color => Color_Pair'First,
1467 Attr => Normal_Video));
1468 end Add_Character_To_Pad_And_Echo_It;
1469 ------------------------------------------------------------------------------
1470 procedure Scroll (Win : in Window := Standard_Window;
1471 Amount : in Integer := 1)
1473 function Wscrl (Win : Window; N : C_Int) return C_Int;
1474 pragma Import (C, Wscrl, "wscrl");
1477 if Wscrl (Win, C_Int (Amount)) = Curses_Err then
1478 raise Curses_Exception;
1482 ------------------------------------------------------------------------------
1483 procedure Delete_Character (Win : in Window := Standard_Window)
1485 function Wdelch (Win : Window) return C_Int;
1486 pragma Import (C, Wdelch, "wdelch");
1488 if Wdelch (Win) = Curses_Err then
1489 raise Curses_Exception;
1491 end Delete_Character;
1493 procedure Delete_Character
1494 (Win : in Window := Standard_Window;
1495 Line : in Line_Position;
1496 Column : in Column_Position)
1498 function Mvwdelch (Win : Window;
1500 Col : C_Int) return C_Int;
1501 pragma Import (C, Mvwdelch, "mvwdelch");
1503 if Mvwdelch (Win, C_Int (Line), C_Int (Column)) = Curses_Err then
1504 raise Curses_Exception;
1506 end Delete_Character;
1507 ------------------------------------------------------------------------------
1508 function Peek (Win : Window := Standard_Window)
1509 return Attributed_Character
1511 function Winch (Win : Window) return C_Int;
1512 pragma Import (C, Winch, "winch");
1514 return CInt_To_Chtype (Winch (Win));
1518 (Win : Window := Standard_Window;
1519 Line : Line_Position;
1520 Column : Column_Position) return Attributed_Character
1522 function Mvwinch (Win : Window;
1524 Col : C_Int) return C_Int;
1525 pragma Import (C, Mvwinch, "mvwinch");
1527 return CInt_To_Chtype (Mvwinch (Win, C_Int (Line), C_Int (Column)));
1529 ------------------------------------------------------------------------------
1530 procedure Insert (Win : in Window := Standard_Window;
1531 Ch : in Attributed_Character)
1533 function Winsch (Win : Window; Ch : C_Int) return C_Int;
1534 pragma Import (C, Winsch, "winsch");
1536 if Winsch (Win, Chtype_To_CInt (Ch)) = Curses_Err then
1537 raise Curses_Exception;
1542 (Win : in Window := Standard_Window;
1543 Line : in Line_Position;
1544 Column : in Column_Position;
1545 Ch : in Attributed_Character)
1547 function Mvwinsch (Win : Window;
1550 Ch : C_Int) return C_Int;
1551 pragma Import (C, Mvwinsch, "mvwinsch");
1556 Chtype_To_CInt (Ch)) = Curses_Err then
1557 raise Curses_Exception;
1560 ------------------------------------------------------------------------------
1561 procedure Insert (Win : in Window := Standard_Window;
1563 Len : in Integer := -1)
1565 type Char_Ptr is access all Interfaces.C.Char;
1566 function Winsnstr (Win : Window;
1568 Len : Integer := -1) return C_Int;
1569 pragma Import (C, Winsnstr, "winsnstr");
1571 Txt : char_array (0 .. Str'Length);
1574 To_C (Str, Txt, Length);
1575 if Winsnstr (Win, Txt (Txt'First)'Access, Len) = Curses_Err then
1576 raise Curses_Exception;
1581 (Win : in Window := Standard_Window;
1582 Line : in Line_Position;
1583 Column : in Column_Position;
1585 Len : in Integer := -1)
1587 type Char_Ptr is access all Interfaces.C.Char;
1588 function Mvwinsnstr (Win : Window;
1592 Len : C_Int) return C_Int;
1593 pragma Import (C, Mvwinsnstr, "mvwinsnstr");
1595 Txt : char_array (0 .. Str'Length);
1598 To_C (Str, Txt, Length);
1599 if Mvwinsnstr (Win, C_Int (Line), C_Int (Column),
1600 Txt (Txt'First)'Access, C_Int (Len))
1602 raise Curses_Exception;
1605 ------------------------------------------------------------------------------
1606 procedure Peek (Win : in Window := Standard_Window;
1608 Len : in Integer := -1)
1610 function Winnstr (Win : Window;
1612 Len : C_Int) return C_Int;
1613 pragma Import (C, Winnstr, "winnstr");
1616 Txt : char_array (0 .. Str'Length);
1622 if N > Str'Length then
1623 raise Constraint_Error;
1625 Txt (0) := Interfaces.C.char'First;
1626 if Winnstr (Win, Txt, C_Int (N)) = Curses_Err then
1627 raise Curses_Exception;
1629 To_Ada (Txt, Str, Cnt, True);
1630 if Cnt < Str'Length then
1631 Str ((Str'First + Cnt) .. Str'Last) := (others => ' ');
1636 (Win : in Window := Standard_Window;
1637 Line : in Line_Position;
1638 Column : in Column_Position;
1640 Len : in Integer := -1)
1643 Move_Cursor (Win, Line, Column);
1644 Peek (Win, Str, Len);
1646 ------------------------------------------------------------------------------
1648 (Win : in Window := Standard_Window;
1649 Str : out Attributed_String;
1650 Len : in Integer := -1)
1652 type Chtype_Ptr is access all Attributed_Character;
1653 function Winchnstr (Win : Window;
1655 Len : C_Int) return C_Int;
1656 pragma Import (C, Winchnstr, "winchnstr");
1659 Txt : chtype_array (0 .. Str'Length);
1665 if N > Str'Length then
1666 raise Constraint_Error;
1668 if Winchnstr (Win, Txt (Txt'First)'Access, C_Int (N)) = Curses_Err then
1669 raise Curses_Exception;
1671 for To in Str'Range loop
1672 exit when Txt (size_t (Cnt)) = Default_Character;
1673 Str (To) := Txt (size_t (Cnt));
1676 if Cnt < Str'Length then
1677 Str ((Str'First + Cnt) .. Str'Last) :=
1678 (others => (Ch => ' ',
1679 Color => Color_Pair'First,
1680 Attr => Normal_Video));
1685 (Win : in Window := Standard_Window;
1686 Line : in Line_Position;
1687 Column : in Column_Position;
1688 Str : out Attributed_String;
1689 Len : in Integer := -1)
1692 Move_Cursor (Win, Line, Column);
1693 Peek (Win, Str, Len);
1695 ------------------------------------------------------------------------------
1696 procedure Get (Win : in Window := Standard_Window;
1698 Len : in Integer := -1)
1700 function Wgetnstr (Win : Window;
1702 Len : C_Int) return C_Int;
1703 pragma Import (C, Wgetnstr, "wgetnstr");
1706 Txt : char_array (0 .. Str'Length);
1712 if N > Str'Length then
1713 raise Constraint_Error;
1715 Txt (0) := Interfaces.C.char'First;
1716 if Wgetnstr (Win, Txt, C_Int (N)) = Curses_Err then
1717 raise Curses_Exception;
1719 To_Ada (Txt, Str, Cnt, True);
1720 if Cnt < Str'Length then
1721 Str ((Str'First + Cnt) .. Str'Last) := (others => ' ');
1726 (Win : in Window := Standard_Window;
1727 Line : in Line_Position;
1728 Column : in Column_Position;
1730 Len : in Integer := -1)
1733 Move_Cursor (Win, Line, Column);
1734 Get (Win, Str, Len);
1736 ------------------------------------------------------------------------------
1737 procedure Init_Soft_Label_Keys
1738 (Format : in Soft_Label_Key_Format := Three_Two_Three)
1740 function Slk_Init (Fmt : C_Int) return C_Int;
1741 pragma Import (C, Slk_Init, "slk_init");
1743 if Slk_Init (Soft_Label_Key_Format'Pos (Format)) = Curses_Err then
1744 raise Curses_Exception;
1746 end Init_Soft_Label_Keys;
1748 procedure Set_Soft_Label_Key (Label : in Label_Number;
1750 Fmt : in Label_Justification := Left)
1752 type Char_Ptr is access all Interfaces.C.Char;
1753 function Slk_Set (Label : C_Int;
1755 Fmt : C_Int) return C_Int;
1756 pragma Import (C, Slk_Set, "slk_set");
1758 Txt : char_array (0 .. Text'Length);
1761 To_C (Text, Txt, Len);
1762 if Slk_Set (C_Int (Label),
1763 Txt (Txt'First)'Access,
1764 C_Int (Label_Justification'Pos (Fmt)))
1766 raise Curses_Exception;
1768 end Set_Soft_Label_Key;
1770 procedure Refresh_Soft_Label_Keys
1772 function Slk_Refresh return C_Int;
1773 pragma Import (C, Slk_Refresh, "slk_refresh");
1775 if Slk_Refresh = Curses_Err then
1776 raise Curses_Exception;
1778 end Refresh_Soft_Label_Keys;
1780 procedure Refresh_Soft_Label_Keys_Without_Update
1782 function Slk_Noutrefresh return C_Int;
1783 pragma Import (C, Slk_Noutrefresh, "slk_noutrefresh");
1785 if Slk_Noutrefresh = Curses_Err then
1786 raise Curses_Exception;
1788 end Refresh_Soft_Label_Keys_Without_Update;
1790 procedure Get_Soft_Label_Key (Label : in Label_Number;
1793 function Slk_Label (Label : C_Int) return chars_ptr;
1794 pragma Import (C, Slk_Label, "slk_label");
1796 Fill_String (Slk_Label (C_Int (Label)), Text);
1797 end Get_Soft_Label_Key;
1799 procedure Clear_Soft_Label_Keys
1801 function Slk_Clear return C_Int;
1802 pragma Import (C, Slk_Clear, "slk_clear");
1804 if Slk_Clear = Curses_Err then
1805 raise Curses_Exception;
1807 end Clear_Soft_Label_Keys;
1809 procedure Restore_Soft_Label_Keys
1811 function Slk_Restore return C_Int;
1812 pragma Import (C, Slk_Restore, "slk_restore");
1814 if Slk_Restore = Curses_Err then
1815 raise Curses_Exception;
1817 end Restore_Soft_Label_Keys;
1819 procedure Touch_Soft_Label_Keys
1821 function Slk_Touch return C_Int;
1822 pragma Import (C, Slk_Touch, "slk_touch");
1824 if Slk_Touch = Curses_Err then
1825 raise Curses_Exception;
1827 end Touch_Soft_Label_Keys;
1829 procedure Switch_Soft_Label_Key_Attributes
1830 (Attr : in Character_Attribute_Set;
1831 On : in Boolean := True)
1833 function Slk_Attron (Ch : C_Int) return C_Int;
1834 pragma Import (C, Slk_Attron, "slk_attron");
1835 function Slk_Attroff (Ch : C_Int) return C_Int;
1836 pragma Import (C, Slk_Attroff, "slk_attroff");
1839 Ch : constant Attributed_Character := (Ch => Character'First,
1841 Color => Color_Pair'First);
1844 Err := Slk_Attron (Chtype_To_CInt (Ch));
1846 Err := Slk_Attroff (Chtype_To_CInt (Ch));
1848 if Err = Curses_Err then
1849 raise Curses_Exception;
1851 end Switch_Soft_Label_Key_Attributes;
1853 procedure Set_Soft_Label_Key_Attributes
1854 (Attr : in Character_Attribute_Set := Normal_Video;
1855 Color : in Color_Pair := Color_Pair'First)
1857 function Slk_Attrset (Ch : C_Int) return C_Int;
1858 pragma Import (C, Slk_Attrset, "slk_attrset");
1860 Ch : constant Attributed_Character := (Ch => Character'First,
1864 if Slk_Attrset (Chtype_To_CInt (Ch)) = Curses_Err then
1865 raise Curses_Exception;
1867 end Set_Soft_Label_Key_Attributes;
1869 function Get_Soft_Label_Key_Attributes return Character_Attribute_Set
1871 function Slk_Attr return C_Int;
1872 pragma Import (C, Slk_Attr, "slk_attr");
1874 Attr : constant C_Int := Slk_Attr;
1876 return CInt_To_Chtype (Attr).Attr;
1877 end Get_Soft_Label_Key_Attributes;
1879 function Get_Soft_Label_Key_Attributes return Color_Pair
1881 function Slk_Attr return C_Int;
1882 pragma Import (C, Slk_Attr, "slk_attr");
1884 Attr : constant C_Int := Slk_Attr;
1886 return CInt_To_Chtype (Attr).Color;
1887 end Get_Soft_Label_Key_Attributes;
1888 ------------------------------------------------------------------------------
1889 procedure Un_Control (Ch : in Attributed_Character;
1892 function Unctrl (Ch : C_Int) return chars_ptr;
1893 pragma Import (C, Unctrl, "unctrl");
1895 Fill_String (Unctrl (Chtype_To_CInt (Ch)), Str);
1898 procedure Delay_Output (Msecs : in Natural)
1900 function Delayoutput (Msecs : C_Int) return C_Int;
1901 pragma Import (C, Delayoutput, "delay_output");
1903 if Delayoutput (C_Int (Msecs)) = Curses_Err then
1904 raise Curses_Exception;
1908 procedure Flush_Input
1910 function Flushinp return C_Int;
1911 pragma Import (C, Flushinp, "flushinp");
1913 if Flushinp = Curses_Err then -- docu says that never happens, but...
1914 raise Curses_Exception;
1917 ------------------------------------------------------------------------------
1918 function Baudrate return Natural
1920 function Baud return C_Int;
1921 pragma Import (C, Baud, "baudrate");
1923 return Natural (Baud);
1926 function Erase_Character return Character
1928 function Erasechar return C_Int;
1929 pragma Import (C, Erasechar, "erasechar");
1931 return Character'Val (Erasechar);
1932 end Erase_Character;
1934 function Kill_Character return Character
1936 function Killchar return C_Int;
1937 pragma Import (C, Killchar, "killchar");
1939 return Character'Val (Killchar);
1942 function Has_Insert_Character return Boolean
1944 function Has_Ic return C_Int;
1945 pragma Import (C, Has_Ic, "has_ic");
1947 if Has_Ic = Curses_False then
1952 end Has_Insert_Character;
1954 function Has_Insert_Line return Boolean
1956 function Has_Il return C_Int;
1957 pragma Import (C, Has_Il, "has_il");
1959 if Has_Il = Curses_False then
1964 end Has_Insert_Line;
1966 function Supported_Attributes return Character_Attribute_Set
1968 function Termattrs return C_Int;
1969 pragma Import (C, Termattrs, "termattrs");
1971 Ch : constant Attributed_Character := CInt_To_Chtype (Termattrs);
1974 end Supported_Attributes;
1976 procedure Long_Name (Name : out String)
1978 function Longname return chars_ptr;
1979 pragma Import (C, Longname, "longname");
1981 Fill_String (Longname, Name);
1984 procedure Terminal_Name (Name : out String)
1986 function Termname return chars_ptr;
1987 pragma Import (C, Termname, "termname");
1989 Fill_String (Termname, Name);
1991 ------------------------------------------------------------------------------
1992 procedure Init_Pair (Pair : in Redefinable_Color_Pair;
1993 Fore : in Color_Number;
1994 Back : in Color_Number)
1996 function Initpair (Pair : C_Short;
1998 Back : C_Short) return C_Int;
1999 pragma Import (C, Initpair, "init_pair");
2001 if Integer (Pair) >= Number_Of_Color_Pairs then
2002 raise Constraint_Error;
2004 if Integer (Fore) >= Number_Of_Colors or else
2005 Integer (Back) >= Number_Of_Colors then raise Constraint_Error;
2007 if Initpair (C_Short (Pair), C_Short (Fore), C_Short (Back))
2009 raise Curses_Exception;
2013 procedure Pair_Content (Pair : in Color_Pair;
2014 Fore : out Color_Number;
2015 Back : out Color_Number)
2017 type C_Short_Access is access all C_Short;
2018 function Paircontent (Pair : C_Short;
2019 Fp : C_Short_Access;
2020 Bp : C_Short_Access) return C_Int;
2021 pragma Import (C, Paircontent, "pair_content");
2023 F, B : aliased C_Short;
2025 if Paircontent (C_Short (Pair), F'Access, B'Access) = Curses_Err then
2026 raise Curses_Exception;
2028 Fore := Color_Number (F);
2029 Back := Color_Number (B);
2033 function Has_Colors return Boolean
2035 function Hascolors return C_Int;
2036 pragma Import (C, Hascolors, "has_colors");
2038 if Hascolors = Curses_False then
2045 procedure Init_Color (Color : in Color_Number;
2047 Green : in RGB_Value;
2048 Blue : in RGB_Value)
2050 function Initcolor (Col : C_Short;
2053 Blue : C_Short) return C_Int;
2054 pragma Import (C, Initcolor, "init_color");
2056 if Initcolor (C_Short (Color), C_Short (Red), C_Short (Green),
2057 C_Short (Blue)) = Curses_Err then
2058 raise Curses_Exception;
2062 function Can_Change_Color return Boolean
2064 function Canchangecolor return C_Int;
2065 pragma Import (C, Canchangecolor, "can_change_color");
2067 if Canchangecolor = Curses_False then
2072 end Can_Change_Color;
2074 procedure Color_Content (Color : in Color_Number;
2075 Red : out RGB_Value;
2076 Green : out RGB_Value;
2077 Blue : out RGB_Value)
2079 type C_Short_Access is access all C_Short;
2081 function Colorcontent (Color : C_Short; R, G, B : C_Short_Access)
2083 pragma Import (C, Colorcontent, "color_content");
2085 R, G, B : aliased C_Short;
2087 if Colorcontent (C_Short (Color), R'Access, G'Access, B'Access) =
2089 raise Curses_Exception;
2091 Red := RGB_Value (R);
2092 Green := RGB_Value (G);
2093 Blue := RGB_Value (B);
2097 ------------------------------------------------------------------------------
2098 procedure Save_Curses_Mode (Mode : in Curses_Mode)
2100 function Def_Prog_Mode return C_Int;
2101 pragma Import (C, Def_Prog_Mode, "def_prog_mode");
2102 function Def_Shell_Mode return C_Int;
2103 pragma Import (C, Def_Shell_Mode, "def_shell_mode");
2108 when Curses => Err := Def_Prog_Mode;
2109 when Shell => Err := Def_Shell_Mode;
2111 if Err = Curses_Err then
2112 raise Curses_Exception;
2114 end Save_Curses_Mode;
2116 procedure Reset_Curses_Mode (Mode : in Curses_Mode)
2118 function Reset_Prog_Mode return C_Int;
2119 pragma Import (C, Reset_Prog_Mode, "reset_prog_mode");
2120 function Reset_Shell_Mode return C_Int;
2121 pragma Import (C, Reset_Shell_Mode, "reset_shell_mode");
2126 when Curses => Err := Reset_Prog_Mode;
2127 when Shell => Err := Reset_Shell_Mode;
2129 if Err = Curses_Err then
2130 raise Curses_Exception;
2132 end Reset_Curses_Mode;
2134 procedure Save_Terminal_State
2136 function Savetty return C_Int;
2137 pragma Import (C, Savetty, "savetty");
2139 if Savetty = Curses_Err then
2140 raise Curses_Exception;
2142 end Save_Terminal_State;
2144 procedure Reset_Terminal_State
2146 function Resetty return C_Int;
2147 pragma Import (C, Resetty, "resetty");
2149 if Resetty = Curses_Err then
2150 raise Curses_Exception;
2152 end Reset_Terminal_State;
2154 procedure Rip_Off_Lines (Lines : in Integer;
2155 Proc : in Stdscr_Init_Proc)
2157 function Ripoffline (Lines : C_Int;
2158 Proc : Stdscr_Init_Proc) return C_Int;
2159 pragma Import (C, Ripoffline, "_nc_ripoffline");
2161 if Ripoffline (C_Int (Lines), Proc) = Curses_Err then
2162 raise Curses_Exception;
2166 procedure Set_Cursor_Visibility (Visibility : in out Cursor_Visibility)
2168 function Curs_Set (Curs : C_Int) return C_Int;
2169 pragma Import (C, Curs_Set, "curs_set");
2173 Res := Curs_Set (Cursor_Visibility'Pos (Visibility));
2174 if Res /= Curses_Err then
2175 Visibility := Cursor_Visibility'Val (Res);
2177 end Set_Cursor_Visibility;
2179 procedure Nap_Milli_Seconds (Ms : in Natural)
2181 function Napms (Ms : C_Int) return C_Int;
2182 pragma Import (C, Napms, "napms");
2184 if Napms (C_Int (Ms)) = Curses_Err then
2185 raise Curses_Exception;
2187 end Nap_Milli_Seconds;
2188 ------------------------------------------------------------------------------
2190 function Standard_Window return Window
2193 pragma Import (C, Stdscr, "stdscr");
2196 end Standard_Window;
2198 function Lines return Line_Count
2201 pragma Import (C, C_Lines, "LINES");
2203 return Line_Count (C_Lines);
2206 function Columns return Column_Count
2209 pragma Import (C, C_Columns, "COLS");
2211 return Column_Count (C_Columns);
2214 function Tab_Size return Natural
2217 pragma Import (C, C_Tab_Size, "TABSIZE");
2219 return Natural (C_Tab_Size);
2222 function Number_Of_Colors return Natural
2224 C_Number_Of_Colors : C_Int;
2225 pragma Import (C, C_Number_Of_Colors, "COLORS");
2227 return Natural (C_Number_Of_Colors);
2228 end Number_Of_Colors;
2230 function Number_Of_Color_Pairs return Natural
2232 C_Number_Of_Color_Pairs : C_Int;
2233 pragma Import (C, C_Number_Of_Color_Pairs, "COLOR_PAIRS");
2235 return Natural (C_Number_Of_Color_Pairs);
2236 end Number_Of_Color_Pairs;
2237 ------------------------------------------------------------------------------
2238 procedure Transform_Coordinates
2239 (W : in Window := Standard_Window;
2240 Line : in out Line_Position;
2241 Column : in out Column_Position;
2242 Dir : in Transform_Direction := From_Screen)
2244 type Int_Access is access all C_Int;
2245 function Transform (W : Window;
2247 Dir : C_Int) return C_Int;
2248 pragma Import (C, Transform, "_nc_ada_coord_transform");
2250 X : aliased C_Int := C_Int (Column);
2251 Y : aliased C_Int := C_Int (Line);
2255 if Dir = To_Screen then
2258 R := Transform (W, Y'Access, X'Access, D);
2259 if R = Curses_False then
2260 raise Curses_Exception;
2262 Line := Line_Position (Y);
2263 Column := Column_Position (X);
2265 end Transform_Coordinates;
2268 if Generation_Bit_Order /= System.Default_Bit_Order then
2269 raise Constraint_Error;
2271 end Terminal_Interface.Curses;