Skip to content

Commit

Permalink
Version 0.3.0!
Browse files Browse the repository at this point in the history
  • Loading branch information
joseaverde committed Sep 7, 2021
1 parent 3e9bbf5 commit ac29968
Show file tree
Hide file tree
Showing 18 changed files with 336 additions and 30 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ build
__pycache__
logs
danger_zone
tags
32 changes: 23 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ Malef is a terminal/console-handling library written in Ada.
[![License: FDL 1.3](https://img.shields.io/badge/License-FDL%20v1.3-blue.svg)](http://www.gnu.org/licenses/fdl-1.3)

## Description
Malef is an open source and free library written in Ada (with some parts
written in C) that works similarly to the Ncurses library but with a new data
type called _Surfaces_.
**Malef** is an open source and free library written in Ada (with some parts
written in C) to create Terminal User Interfaces with an approach similar to
graphical libraries. It will also provide bindings to the C and Python3
programming languages (they haven't been implemented yet).

You can see examples in the [examples directory](examples/).


## Bindings
The Malef library will have bindings for other programming languages like C or
Python3 in the future, maybe before the first version release.
Python3 in the future, a few tests have been done in early versions where they
perfectly work. I'm putting them aside for now until I have a strong library
core and API.

## Compilation

Expand All @@ -24,25 +30,33 @@ Python3 in the future, maybe before the first version release.
| Subsystem | Status |
|:---------:|:------:|
| ANSI | ![ANSI](https://img.shields.io/badge/build-passing-success) |
| CMD | ![CMD](https://img.shields.io/badge/build-failing-critical) |
| CMD | ![CMD](https://img.shields.io/badge/build-passing-success) |

_There are some problems with colours in the CMD subsystem, everything else
works though. But the ANSI subsystem is still more robust._

## Tests
The test directory hasn't been updated recently, in future versions new tests
will be added.

| System | Status |
|:-------:|:------:|
| Linux | ![Linux](https://img.shields.io/badge/tests-passing-success) |
| Windows | ![Windows](https://img.shields.io/badge/tests-failing-critical) |
| Windows | ![Windows](https://img.shields.io/badge/tests-not_implemented-important) |

| Language | Status |
|:--------:|:------:|
| Ada | ![Ada](https://img.shields.io/badge/tests-passing-success) |
| C | ![C](https://img.shields.io/badge/tests-failing-critical) |
| Python3 | ![Python3](https://img.shields.io/badge/tests-failing-critical) |
| C | ![C](https://img.shields.io/badge/tests-not_implemented-critical) |
| Python3 | ![Python3](https://img.shields.io/badge/tests-not_implemented-critical) |


## How to build it?
Better instructions will be given in the future.
Better instructions will be given in the future. But basically download GNAT
and run
> gprbuild -p -Pmalef.gpr
With the options you want, a complete list can be seen in the
[shared.gpr](shared.gpr) source file.


## Licenses
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.4
0.3.0
2 changes: 2 additions & 0 deletions ada-malef/src-base/malef.ads
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,8 @@ package Malef is
--
type Str_Type is array (Positive range <>) of Char_Type;

type Str_Access is access Str_Type;


--====----------------------------====--
--====-- INITIALIZATION OPTIONS --====--
Expand Down
73 changes: 73 additions & 0 deletions ada-malef/src-sdk/malef-sdk-message_boxes.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
-------------------------------------------------------------------------------
-- --
-- M A L E F - S D K - M E S S A G E _ B O X E S . A D B --
-- --
-- M A L E F --
-- --
-- B O D Y --
-- --
-------------------------------------------------------------------------------
-- Copyright (c) 2021 José Antonio Verde Jiménez All Rights Reserved --
-------------------------------------------------------------------------------
-- This file is part of Malef. --
-- --
-- This program is free software: you can redistribute it and/or modify it --
-- under the terms of the GNU General License as published by the Free --
-- Software Foundation, either version 3 of the License, or (at your --
-- opinion) any later version. --
-- --
-- This program is distributed in the hope that it will be useful, but --
-- WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General --
-- Public License for more details. --
-- --
-- You should have received a copy of the GNU General Public License along --
-- with this program. If not, see <https://www.gnu.org/licenses/>. --
-- --
-------------------------------------------------------------------------------

package body Malef.SDK.Message_Boxes is

function Create (
Message : Str_Type;
Foreground_Color : Color_Type;
Background_Color : Color_Type;
Selected_Color : Color_Type;
Shadow_Color : Color_Type := Default_Shadow_Color;
Borders : String := "+-+| |+-+")
return Message_Box_Type is
begin

return Message_Box_Type'(Message_Boxes_Widgets.Widget_Type with
Message => new Str_Type'(Message),
others => <>);

end Create;

overriding
function Run (Message_Box : in out Message_Box_Type)
return Return_Type is
begin

pragma Unreferenced (Message_Box);

return Return_Type'First;

end Run;


overriding
procedure Finalize (Message_Box : in out Message_Box_Type) is
Upcast : constant access Base_Type := Base_Type(Message_Box)'Access;
begin

Upcast.Finalize;

end Finalize;


end Malef.SDK.Message_Boxes;

---=======================-------------------------=========================---
--=======================-- E N D O F F I L E --=========================--
---=======================-------------------------=========================---
76 changes: 76 additions & 0 deletions ada-malef/src-sdk/malef-sdk-message_boxes.ads
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
-------------------------------------------------------------------------------
-- --
-- M A L E F - S D K - M E S S A G E _ B O X E S . A D S --
-- --
-- M A L E F --
-- --
-- S P E C --
-- --
-------------------------------------------------------------------------------
-- Copyright (c) 2021 José Antonio Verde Jiménez All Rights Reserved --
-------------------------------------------------------------------------------
-- This file is part of Malef. --
-- --
-- This program is free software: you can redistribute it and/or modify it --
-- under the terms of the GNU General License as published by the Free --
-- Software Foundation, either version 3 of the License, or (at your --
-- opinion) any later version. --
-- --
-- This program is distributed in the hope that it will be useful, but --
-- WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General --
-- Public License for more details. --
-- --
-- You should have received a copy of the GNU General Public License along --
-- with this program. If not, see <https://www.gnu.org/licenses/>. --
-- --
-------------------------------------------------------------------------------

--
-- @summary
--
--
-- @description
--
generic
type Return_Type is (<>);
package Malef.SDK.Message_Boxes is

package Message_Boxes_Widgets is new Widgets (Return_Type);

type Message_Box_Type is
new Message_Boxes_Widgets.Widget_Type with
private;

function Create (
Message : Str_Type;
Foreground_Color : Color_Type;
Background_Color : Color_Type;
Selected_Color : Color_Type;
Shadow_Color : Color_Type := Default_Shadow_Color;
Borders : String := "+-+| |+-+")
return Message_Box_Type
with Pre => Borders'Length = 9 and Borders'First = 1;

overriding
function Run (Message_Box : in out Message_Box_Type)
return Return_Type;

private

type Message_Box_Type is
new Message_Boxes_Widgets.Widget_Type with
record
Message : Str_Access;
Position : Return_Type := Return_Type'First;
end record;

overriding
procedure Update (Message_Box : in out Message_Box_Type) is null;
procedure Finalize (Message_Box : in out Message_Box_Type);

end Malef.SDK.Message_Boxes;

---=======================-------------------------=========================---
--=======================-- E N D O F F I L E --=========================--
---=======================-------------------------=========================---
50 changes: 50 additions & 0 deletions ada-malef/src-sdk/malef-sdk.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
-------------------------------------------------------------------------------
-- --
-- M A L E F - S D K . A D B --
-- --
-- M A L E F --
-- --
-- B O D Y --
-- --
-------------------------------------------------------------------------------
-- Copyright (c) 2021 José Antonio Verde Jiménez All Rights Reserved --
-------------------------------------------------------------------------------
-- This file is part of Malef. --
-- --
-- This program is free software: you can redistribute it and/or modify it --
-- under the terms of the GNU General License as published by the Free --
-- Software Foundation, either version 3 of the License, or (at your --
-- opinion) any later version. --
-- --
-- This program is distributed in the hope that it will be useful, but --
-- WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General --
-- Public License for more details. --
-- --
-- You should have received a copy of the GNU General Public License along --
-- with this program. If not, see <https://www.gnu.org/licenses/>. --
-- --
-------------------------------------------------------------------------------

--with Ada.Unchecked_Deallocation;

package body Malef.SDK is

package body Widgets is

overriding
function Get_Reference (Widget : in Widget_Type)
return Surface_Reference is
begin

return Widget.Box.Get_Reference;

end Get_Reference;

end Widgets;

end Malef.SDK;

---=======================-------------------------=========================---
--=======================-- E N D O F F I L E --=========================--
---=======================-------------------------=========================---
75 changes: 75 additions & 0 deletions ada-malef/src-sdk/malef-sdk.ads
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
-------------------------------------------------------------------------------
-- --
-- M A L E F - S D K . A D S --
-- --
-- M A L E F --
-- --
-- S P E C --
-- --
-------------------------------------------------------------------------------
-- Copyright (c) 2021 José Antonio Verde Jiménez All Rights Reserved --
-------------------------------------------------------------------------------
-- This file is part of Malef. --
-- --
-- This program is free software: you can redistribute it and/or modify it --
-- under the terms of the GNU General License as published by the Free --
-- Software Foundation, either version 3 of the License, or (at your --
-- opinion) any later version. --
-- --
-- This program is distributed in the hope that it will be useful, but --
-- WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General --
-- Public License for more details. --
-- --
-- You should have received a copy of the GNU General Public License along --
-- with this program. If not, see <https://www.gnu.org/licenses/>. --
-- --
-------------------------------------------------------------------------------

with Malef.Boxes;
with Malef.Surfaces;

--
-- @summary
-- This package is meant to facilitate the creation of interactive porgrams
-- with the Malef API.
--
-- @description
-- This package declares a new type called Widget which is derived from the Box
-- type which helps with the creation of interactive applications such as
-- message boxes or other kind of things. This was planned to be added in
-- future versions but I needed it for a current project.
--
package Malef.SDK is

Default_Shadow_Color : constant Color_Type := (0, 0, 0, 128);

generic
type Return_Type is (<>);
package Widgets is

type Widget_Type is abstract new Base_Type with private;

function Run (Widget : in out Widget_Type)
return Return_Type is abstract;

private

type Widget_Type is abstract new Base_Type with
record
Box : Malef.Boxes.Box_Type;
Surface : Malef.Surfaces.Surface_Type;
Shadow : Malef.Surfaces.Surface_Type;
end record;

overriding
function Get_Reference (Widget : in Widget_Type)
return Surface_Reference;

end Widgets;

end Malef.SDK;

---=======================-------------------------=========================---
--=======================-- E N D O F F I L E --=========================--
---=======================-------------------------=========================---
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ package body Malef.Subsystems.Components.Colors is
Brightness_Diff : constant Float := abs
(Float(Left.Brightness) - Float(Right.Brightness));
begin
return Percentage (1.0 -
return Percentage (1.0 -
(Hue_Diff / 360.0 + Saturation_Diff + Brightness_Diff) / 3.0);
end Color_Match;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ package body Malef.Systems.Dynamic_Library_Loader is
with Interfaces.C.Strings.Value (dlerror);
end if;


return Handle;

end Load_Library;
Expand Down
8 changes: 2 additions & 6 deletions ada-malef/src-systems/malef-systems-utils.adb
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ package body Malef.Systems.Utils is
:= Library_Handle (System.Null_Address);
begin

Previous_Subsystems := Loaded_Subsystems;
-- We loop through all the libraries and try to load them, if they can be
-- found by default by the linker. Otherwise we let them be just null and
-- we do nothing.
Expand Down Expand Up @@ -169,12 +170,7 @@ package body Malef.Systems.Utils is
begin

-- The last subsystem is None, which can't be freed.
for Subsys in Subsystem_Kind range ANSI .. Subsystem_Kind'Pred(None) loop
if Loaded_Subsystems_Handles (Subsys) /= Null_Handle then
Unload_Library (Loaded_Subsystems_Handles (Subsys));
Loaded_Subsystems (Subsys) := null;
end if;
end loop;
Loaded_Subsystems := Previous_Subsystems;
Loaded_Subsystems_Handles (Choose) := Null_Handle;

end Unload_Libraries;
Expand Down
Loading

0 comments on commit ac29968

Please sign in to comment.