with Ada.Text_IO; use Ada.Text_IO;
pragma Warnings (Off);
with Terminal_Interface.Curses.Aux;
pragma Warnings (On);
with Terminal_Interface.Curses.Trace; use Terminal_Interface.Curses.Trace;
with Interfaces.C;
with Interfaces.C.Strings;
with Ada.Characters.Handling;
with ncurses2.genericPuts;
package body ncurses2.util is
function CTRL (c : Character) return Key_Code is
begin
return Character'Pos (c) mod 16#20#;
end CTRL;
function CTRL (c : Character) return Character is
begin
return Character'Val (Character'Pos (c) mod 16#20#);
end CTRL;
save_trace : Trace_Attribute_Set;
function Getchar (win : Window := Standard_Window) return Key_Code is
c : Key_Code;
begin
c := Get_Keystroke (win);
while c = CTRL ('T') loop
if Current_Trace_Setting /= Trace_Disable then
save_trace := Current_Trace_Setting;
Trace_Put ("TOGGLE-TRACING OFF");
Current_Trace_Setting := Trace_Disable;
else
Current_Trace_Setting := save_trace;
end if;
Trace_On (Current_Trace_Setting);
if Current_Trace_Setting /= Trace_Disable then
Trace_Put ("TOGGLE-TRACING ON");
end if;
end loop;
return c;
end Getchar;
procedure Getchar (win : Window := Standard_Window) is
begin
if Getchar (win) < 0 then
Beep;
end if;
end Getchar;
procedure Pause is
begin
Move_Cursor (Line => Lines - 1, Column => 0);
Add (Str => "Press any key to continue... ");
Getchar;
end Pause;
procedure Cannot (s : String) is
use Interfaces.C;
use Interfaces.C.Strings;
use Terminal_Interface.Curses.Aux;
function getenv (x : char_array) return chars_ptr;
pragma Import (C, getenv, "getenv");
tmp1 : char_array (0 .. 10);
package p is new ncurses2.genericPuts (1024);
use p;
use p.BS;
tmpb : BS.Bounded_String;
Length : size_t;
begin
To_C ("TERM", tmp1, Length);
Fill_String (getenv (tmp1), tmpb);
Add (Ch => newl);
myAdd (Str => "This " & tmpb & " terminal " & s);
Pause;
end Cannot;
procedure ShellOut (message : Boolean) is
use Interfaces.C;
Txt : char_array (0 .. 10);
Length : size_t;
procedure system (x : char_array);
pragma Import (C, system, "system");
begin
To_C ("sh", Txt, Length);
if message then
Add (Str => "Shelling out...");
end if;
Save_Curses_Mode (Mode => Curses);
End_Windows;
system (Txt);
if message then
Add (Str => "returned from shellout.");
Add (Ch => newl);
end if;
Refresh;
end ShellOut;
function Is_Digit (c : Key_Code) return Boolean is
begin
if c >= 16#100# then
return False;
else
return Ada.Characters.Handling.Is_Digit (Character'Val (c));
end if;
end Is_Digit;
procedure P (s : String) is
begin
Add (Str => s);
Add (Ch => newl);
end P;
function Code_To_Char (c : Key_Code) return Character is
begin
if c > Character'Pos (Character'Last) then
return Character'Val (0);
else
return Character'Val (c);
end if;
end Code_To_Char;
function ctoi (c : Character) return Integer is
begin
return Character'Pos (c) - Character'Pos ('0');
end ctoi;
end ncurses2.util;