diff --git a/.gitignore b/.gitignore index 62e79e5..5590c5a 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ build __pycache__ logs danger_zone +tags diff --git a/README.md b/README.md index 3843564..fd70caf 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/VERSION b/VERSION index abd4105..0d91a54 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.2.4 +0.3.0 diff --git a/ada-malef/src-base/malef.ads b/ada-malef/src-base/malef.ads index 5ed63d8..6ec343d 100644 --- a/ada-malef/src-base/malef.ads +++ b/ada-malef/src-base/malef.ads @@ -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 --====-- diff --git a/ada-malef/src-sdk/malef-sdk-message_boxes.adb b/ada-malef/src-sdk/malef-sdk-message_boxes.adb new file mode 100644 index 0000000..b4c9249 --- /dev/null +++ b/ada-malef/src-sdk/malef-sdk-message_boxes.adb @@ -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 . -- +-- -- +------------------------------------------------------------------------------- + +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 --=========================-- +---=======================-------------------------=========================--- diff --git a/ada-malef/src-sdk/malef-sdk-message_boxes.ads b/ada-malef/src-sdk/malef-sdk-message_boxes.ads new file mode 100644 index 0000000..871c4c5 --- /dev/null +++ b/ada-malef/src-sdk/malef-sdk-message_boxes.ads @@ -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 . -- +-- -- +------------------------------------------------------------------------------- + +-- +-- @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 --=========================-- +---=======================-------------------------=========================--- diff --git a/ada-malef/src-sdk/malef-sdk.adb b/ada-malef/src-sdk/malef-sdk.adb new file mode 100644 index 0000000..48d88a0 --- /dev/null +++ b/ada-malef/src-sdk/malef-sdk.adb @@ -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 . -- +-- -- +------------------------------------------------------------------------------- + +--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 --=========================-- +---=======================-------------------------=========================--- diff --git a/ada-malef/src-sdk/malef-sdk.ads b/ada-malef/src-sdk/malef-sdk.ads new file mode 100644 index 0000000..183f3db --- /dev/null +++ b/ada-malef/src-sdk/malef-sdk.ads @@ -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 . -- +-- -- +------------------------------------------------------------------------------- + +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 --=========================-- +---=======================-------------------------=========================--- diff --git a/ada-malef/src-subsystems/components/malef-subsystems-components-colors.adb b/ada-malef/src-subsystems/components/malef-subsystems-components-colors.adb index 1ac7d79..4597826 100644 --- a/ada-malef/src-subsystems/components/malef-subsystems-components-colors.adb +++ b/ada-malef/src-subsystems/components/malef-subsystems-components-colors.adb @@ -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; diff --git a/ada-malef/src-systems/linux/malef-systems-dynamic_library_loader.adb b/ada-malef/src-systems/linux/malef-systems-dynamic_library_loader.adb index b7c1d39..7fdb7b0 100644 --- a/ada-malef/src-systems/linux/malef-systems-dynamic_library_loader.adb +++ b/ada-malef/src-systems/linux/malef-systems-dynamic_library_loader.adb @@ -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; diff --git a/ada-malef/src-systems/malef-systems-utils.adb b/ada-malef/src-systems/malef-systems-utils.adb index e20ead3..e772d02 100644 --- a/ada-malef/src-systems/malef-systems-utils.adb +++ b/ada-malef/src-systems/malef-systems-utils.adb @@ -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. @@ -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; diff --git a/ada-malef/src-systems/malef-systems.ads b/ada-malef/src-systems/malef-systems.ads index 739f9aa..ad81c05 100644 --- a/ada-malef/src-systems/malef-systems.ads +++ b/ada-malef/src-systems/malef-systems.ads @@ -118,14 +118,16 @@ private package Malef.Systems is Loaded_Subsystems_Handles : array (Subsystem_Kind'Range) of Library_Handle :=(others => Library_Handle(System.Null_Address)); - Loaded_Subsystems : array (Subsystem_Kind'Range) - of Malef.Subsystems.Subsystem_Access - := ( + + type Subsystem_Access_Array is array (Subsystem_Kind'Range) + of Malef.Subsystems.Subsystem_Access; + Loaded_Subsystems : Subsystem_Access_Array := ( None => Malef.Subsystems.None.Subsystem_Handler'Access, Choose => Malef.Subsystems.None.Subsystem_Handler'Access, others => null); Current_Subsystem : Subsystem_Kind := Choose; + Previous_Subsystems : Subsystem_Access_Array; Available_Styles : array (Style_Type'Range) of Boolean := (others => False); diff --git a/alire.toml b/alire.toml index a43a34e..01d9611 100644 --- a/alire.toml +++ b/alire.toml @@ -10,7 +10,7 @@ description = "Malef is a terminal handling library." long-description = "Malef is a terminal handling library written in Ada with bindings to other programming languages like C and Python3. It replaces the NCurses library with a more Adaish interface. It uses ANSI Escape Sequences as much as possible, but it can also handle other kinds of terminals/consoles." # The version of the package. -version = "0.2.4" +version = "0.3.0" # The authors, maintainer and maintainers' logins. authors = ["José Antonio Verde Jiménez"] diff --git a/dev-tools/do.py b/dev-tools/do.py index 440a688..8dd8378 100755 --- a/dev-tools/do.py +++ b/dev-tools/do.py @@ -294,6 +294,11 @@ def usage(): print(" *", op) +def system (cmd): + if cmd[:4] == "wine": + cmd = "WINEDEBUG=-all " + cmd + os.system(cmd) + def main(): if len(sys.argv) == 1: usage() @@ -308,12 +313,12 @@ def main(): if isinstance(cmd, str): print("\033[2m%s\033[0m" % cmd) - os.system(cmd) + system(cmd) elif isinstance(cmd, list): for c in cmd: if isinstance(c, str): print("\033[2m%s\033[0m" % c) - os.system(c) + system(c) else: c() else: diff --git a/examples/src-ada/boxes_modes.adb b/examples/src-ada/boxes_modes.adb index d23a884..0e89bf7 100644 --- a/examples/src-ada/boxes_modes.adb +++ b/examples/src-ada/boxes_modes.adb @@ -191,6 +191,13 @@ procedure Boxes_Modes is begin Ada.Text_IO.Get_Immediate (Dummy, Available); return Available and then Dummy = 'q'; + -- Available := Ada.Text_IO.End_Of_File (Ada.Text_IO.Standard_Input); + -- if Available then + -- Ada.Text_IO.Get_Immediate (Dummy); + -- return Dummy = 'q'; + -- else + -- return False; + -- end if; end Quit; use type Malef.Row_Coord, Malef.Col_Coord, Malef.Boxes.Layer_Type; diff --git a/malef.gpr b/malef.gpr index 482244a..791a54c 100644 --- a/malef.gpr +++ b/malef.gpr @@ -41,6 +41,8 @@ project Malef is "malef-cursors.ads", "malef-events.ads", "malef-exceptions.ads", + "malef-sdk.ads", + "malef-sdk-message_boxes.ads", "malef-surfaces.ads", "malef-subsystems.ads", "malef-systems.ads", @@ -52,6 +54,7 @@ project Malef is "malef-wrapper.ads"); Src_Dirs := ("ada-malef/src-base", + "ada-malef/src-sdk", "ada-malef/src-systems", "ada-malef/src-systems/" & Shared.System, "ada-malef/src-subsystems"); diff --git a/shared.gpr b/shared.gpr index 001e88b..ff60fe3 100644 --- a/shared.gpr +++ b/shared.gpr @@ -29,8 +29,8 @@ abstract project Shared is Major_Version := "0"; - Minor_Version := "2"; - Patch_Version := "4"; + Minor_Version := "3"; + Patch_Version := "0"; --====-====------------====-====-- --====-====- EXTERNAL -====-====-- @@ -43,10 +43,12 @@ abstract project Shared is Subsystem : Subsystem_Kind := External ("MALEF_SUBSYSTEM", "ansi"); - type Library_Type_Type is ("relocatable", "static", "static-pic"); - Library_Type : Library_Type_Type := External ("MALEF_LIBRARY_TYPE", - External ("LIBRARY_TYPE", - "relocatable")); + -- XXX: The library currently works only dynamicaly + -- type Library_Type_Type is ("relocatable", "static", "static-pic"); + -- Library_Type : Library_Type_Type := External ("MALEF_LIBRARY_TYPE", + -- External ("LIBRARY_TYPE", + -- "relocatable")); + Library_Type := "relocatable"; type Enabled_Kind is ("enabled", "disabled"); Compile_Checks : Enabled_Kind := External ("MALEF_COMPILE_CHECKS", diff --git a/todo.data b/todo.data index 41b1034..6c38d3b 100644 --- a/todo.data +++ b/todo.data @@ -73,3 +73,4 @@ py_rename Rename everything to be called PyMalef. [DONE] bug_windows_linker When compiling the library with Windows, it will try to search for the libraries it's linked to but won't find them. Compile it statically. [DONE] ada_static Allow static compilation of packages and the posibility to embed certain systems into the Ada compilation. For example if a C user decides they want to release their software you can allow to staticaly link: libMalef.a, libCMalef.a and libMalef_ansi.a into one executable. Theoretically libMalef_ansi.a will be loaded at initialization time without needing to find it. Also keep a copy of loaded subsystems before initialization and restore it a finalization. [TODO] syntax-change Change the syntax so function parameters are in different lines from the original function. [DONE] +bug_static Static compilation doesn't work! [TODO]