comp.lang.ada
 help / color / mirror / Atom feed
From: johnherro@aol.com (John Herro)
Subject: Re: Ada Tasks and Keyboard I/O
Date: 1997/06/14
Date: 1997-06-14T00:00:00+00:00	[thread overview]
Message-ID: <19970614185501.OAA01097@ladder02.news.aol.com> (raw)
In-Reply-To: 33A12825.1C80@onlink.net


"David H. Haley" <dhaley@onlink.net> writes:
> I have developed a software package in Ada and
> thought it would be nice to have the time perodically
> updated on the screen while waiting for the user to
> input a value from the keyboard.
> This "sounds" easy enough to do using tasks;
> however, once the program reaches the Get(My_Number)
> statement, all other tasks come to a grinding halt waiting
> for this keyboard I/O to occur <grr>. ... I am using 
> Meridian OpenAda Dos ver 4.1.4, an Ada 83 compiler.

You can use Meridian's TTY.Char_Ready function, and get one
character at a time only when each character is ready.  The
following program, which doesn't even use tasking, continually
displays the time while checking for keyboard character ready.

You could optionally improve the program by displaying the
time only if the number of seconds has changed since the last
display, making the display less busy.  

The program could also be improved by using a user-defined type
instead of Long_Integer in Show_Time, but the use of the package
TTY makes this program non-portable anyway.

Also, the program will have to be enhanced if you want to process
backspace characters, etc.

- John Herro
Software Innovations Technology
http://members.aol.com/AdaTutor
ftp://members.aol.com/AdaTutor

with TTY; use TTY;
procedure Test is
   C       : Character := '*';
      -- Char. typed by the user.
   Number  : String(1 .. 40);
   Num_Len : Integer := 0;
   procedure Show_Time is separate;
begin
   Clear_Screen;
   Put(Row  => 5, Column => 1,
       Item => "Type a number:");
   while C /= ASCII.CR loop
      Show_Time;
      if Char_Ready then
         -- Get the character:
         C := Get(No_Echo => True);
         -- Store the character:
         Num_Len := Num_Len + 1;
         Number(Num_Len) := C;
         if C /= ASCII.CR then
            -- Echo the character:
            Put(Row    => 6,
                Column => Num_Len,
                Item   => C);
         end if;
      end if;
   end loop;
   Put(Row  => 8, Column => 1,
       Item => "Your number is " &
               Number(1 .. Num_Len));
end Test;

with Calendar; use Calendar;
separate (Test)
procedure Show_Time is
   Year, Month, Day     : Integer;
   Seconds              : Duration;
   Temp, Hour, Min, Sec : Long_Integer;
begin
   Split(Clock, Year, Month, Day, Seconds);
   -- Convert seconds since midnight to
   -- hours, minutes, seconds:
   Temp := Long_Integer(Seconds);
   Hour := Temp/3600;
   Temp := Temp - 3600*Hour;
   Min  := Temp/60;
   Sec  := Temp - 60*Min;
   -- Display 2 digits, forcing
   -- leading 0 if necessary:
   Put(Row  => 1, Column => 1,
       Item => Long_Integer'Image(
       100 + Hour)(3 .. 4) & ":");
   Put(Row  => 1, Column => 4,
       Item => Long_Integer'Image(
       100 + Min)(3 .. 4) & ":");
   Put(Row  => 1, Column => 7,
       Item => Long_Integer'Image(
       100 + Sec)(3 .. 4));
end Show_Time;




      parent reply	other threads:[~1997-06-14  0:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-06-13  0:00 Ada Tasks and Keyboard I/O David H. Haley
1997-06-14  0:00 ` Robert Dewar
1997-06-14  0:00 ` Dale Stanbrough
1997-06-14  0:00 ` Larry Kilgallen
1997-06-14  0:00   ` Robert Dewar
1997-06-14  0:00 ` John Herro [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox