πŸ–₯ OS.IO.Run Entering Runtime Text - JulTob/Ada GitHub Wiki

Okay, you know how to get your application to talk to the operating system, read/write files, and set certain configuration settings at the command line. This is all great, but we are missing something very crucial. The question now is: how can you enter text into your application while it is running? In order to cover this case, you will see how to create a small program that can safely handle a string of any length:

name_entry.adb:
with Ada.Text_IO.Unbounded_IO;
with Ada.Strings.Unbounded;
with Ada.Text_IO;
procedure Name_Entry is
  First_Name : Ada.Strings.Unbounded.Unbounded_String :=
    Ada.Strings.Unbounded.Null_Unbounded_String;
  Last_Name  : Ada.Strings.Unbounded.Unbounded_String :=
    Ada.Strings.Unbounded.Null_Unbounded_String;
begin
  Ada.Text_IO.Put("Hello.  What is your first name => ");
  Ada.Text_IO.Unbounded_IO.Get_Line(First_Name);
  Ada.Text_IO.Put("What is your last name => ");
  Ada.Text_IO.Unbounded_IO.Get_Line(Last_Name);
  Ada.Text_IO.Put("Nice to meet you ");
  Ada.Text_IO.Unbounded_IO.Put(First_Name);
  Ada.Text_IO.Put(" ");
  Ada.Text_IO.Unbounded_IO.Put(Last_Name);
  Ada.Text_IO.Put_Line(".");
end Name_Entry;

The preceding example is very simple, but let’s go through the more difficult parts:

  1. with Ada.Text_IO.Unbounded_IO; – This is a new one. This package is similar to Text_IO, but permits working with unbounded strings directly, without having to convert an unbounded string into a fixed – regular – string. will learn more about unbounded strings in the next chapter.
  2. In the declaration portion of Name_Entry, create two variables for an unbounded string.
  3. Ada.Text_IO.Unbounded_IO.Get_Line(First_Name); – This is where input from the user is obtained. As you can see, with an unbounded string, you can have an input as long as you want, so long as you do not hit the Enter key on your keyboard. When the user hits Enter, the program assumes that it got all of the input that it could ever want and proceeds further.
  4. In the remainder of the application, you are seeing the output of your inputs