septum_0.0.8_6dbc8e6b/src/common/sp-terminal.ads

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
-------------------------------------------------------------------------------
-- Copyright 2021, The Septum Developers (see AUTHORS file)

-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at

--     http://www.apache.org/licenses/LICENSE-2.0

-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-------------------------------------------------------------------------------

with Ada.Strings.Unbounded;
with ANSI;

with Trendy_Terminal.IO;
with Trendy_Terminal.VT100;

package SP.Terminal is
    -- Functions for operations to the terminal. This hides the usage of Ada.Text_IO and may silently ignore
    -- capabilities if the terminal does not support them, such as if coloring text or line clearing is added.
    --
    -- This module also hides dependencies on unbounded IO.

    procedure Put (C : Character) renames Trendy_Terminal.IO.Put;
    procedure Put (Str : String) renames Trendy_Terminal.IO.Put;
    procedure Put (Str : Ada.Strings.Unbounded.Unbounded_String) renames Trendy_Terminal.IO.Put;

    procedure Put_Line (Str : String) renames Trendy_Terminal.IO.Put_Line;
    procedure Put_Line (Str : Ada.Strings.Unbounded.Unbounded_String) renames Trendy_Terminal.IO.Put_Line;

    procedure New_Line (Spacing : Positive := 1) renames Trendy_Terminal.IO.New_Line;

    procedure Set_Col (Spacing : Positive) renames Trendy_Terminal.IO.Set_Col;

    procedure Beginning_Of_Line renames Trendy_Terminal.VT100.Beginning_Of_Line;
    procedure Clear_Line renames Trendy_Terminal.VT100.Clear_Line;

    function Colorize (S : String; Color : ANSI.Colors) return String;
    function Colorize (US : Ada.Strings.Unbounded.Unbounded_String; Color : ANSI.Colors)
        return Ada.Strings.Unbounded.Unbounded_String;

    -- I'm not convinced that these aren't useful. I haven't figured out how best to deal with the really long and
    -- verbose terminology of Ada.Strings.Unbounded.Unbounded_String.

    --  function "&" (A : String; B : Unbounded_String) return Unbounded_String renames Ada.Strings.Unbounded."&";
    --  function "&" (Ada : Unbounded_String; B : String) return Unbounded_String renames Ada.Strings.Unbounded."&";

    protected type Cancellation_Gate is
        entry Closed;
        procedure Finish;
        procedure Cancel;
        function Is_Cancelled return Boolean;
        function Is_Finished return Boolean;
    private
        Cancelled : Boolean := False;
        Finished  : Boolean := False;
    end Cancellation_Gate;

    task type Terminal_Cancellation_Monitor(Gate : not null access Cancellation_Gate) is
        entry Cancel;
        entry Stop;
    end;
end SP.Terminal;