00:00
00:00
ciclopeninja
"I do things, I explode, I engineering code, only for fun"
--Maybe someday it will take me somewhere
--...
-- SKNW.

------- ADA IS MY SWORD and MY GOD ------- - DESTRUCTION IS A FORM OF CREATION - @ciclopeninja

Age 21, π

Language Developer

administration technician

.br

Joined on 7/5/21

Level:
14
Exp Points:
1,906 / 2,180
Exp Rank:
33,323
Vote Power:
5.57 votes
Rank:
Civilian
Global Rank:
81,394
Blams:
0
Saves:
76
B/P Bonus:
0%
Whistle:
Normal
Medals:
23

ADA CLEAR

Posted by ciclopeninja - August 14th, 2024


CLEAR TERMINAL IN ADA


iu_1252374_9521393.webp


Most people don't know how to clear terminal text in a program made in gnat Ada


Ada don't have this

...


This depends on your OS (Win, Linux, Mac, etc...), as in windows the command to clear a terminal is "cls", so for your operating system you need to activate this command, but normally it is not available in Ada, this means you need to import "system" into your project and then use "cls" inside...


If you have some knowledge of Ada, you know you can do this using "Intefaces C" (portable ABI) : Interfaces.C & Interfaces.C.Strings.


then you can make a procedure like this:


  Procedure Clear_Screen is 
    procedure System (Command : Interfaces.C.Strings.chars_ptr);
    pragma Import (C, System, "system");
    CLS : constant Interfaces.C.Strings.chars_ptr := Interfaces.C.Strings.New_String("cls");
  begin
    System (CLS);
    -- if you want to draw somenting after you clear the terminal you can do this here :)
    --Put_Line("The prompt is clear...");
  end Clear_Screen;

this will clear the text in the terminal generate by Ada gnat.


For unix systems it can be more simple in theory, using only Put command:


Put (ASCII.ESC & "[2J"); --clear
Put (ASCII.ESC & "[H"); -- move cursor to the top

I not a Linux user, I use Windows and FreeBsd, if that simple command don't work you can try the first one for the linux too, using "clear" instead "cls":


  Procedure Clear_Screen is 
    procedure System (Command : Interfaces.C.Strings.chars_ptr);
    pragma Import (C, System, "system");
    CLEAR : constant Interfaces.C.Strings.chars_ptr := Interfaces.C.Strings.New_String("clear");
  begin
    System (CLEAR);
    -- if you want to draw somenting after you clear the terminal you can do this here :)
    --Put_Line("The prompt is clear...");
  end Clear_Screen;

At this point you've figured out that for your operating system or the operating system you want to support, the idea is the same.


If anyone has another idea on how to clear the terminal, or any doubts, please comment. <3


The End :P


Tags:

Comments

Comments ain't a thing here.