From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,FREEMAIL_FROM, INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,c9138bc72eca8fee X-Google-Attributes: gid103376,public From: johnherro@aol.com (John Herro) Subject: Re: Ada Tasks and Keyboard I/O Date: 1997/06/14 Message-ID: <19970614185501.OAA01097@ladder02.news.aol.com>#1/1 X-Deja-AN: 248398430 References: <33A12825.1C80@onlink.net> X-Admin: news@aol.com Organization: AOL http://www.aol.com Newsgroups: comp.lang.ada Date: 1997-06-14T00:00:00+00:00 List-Id: "David H. Haley" 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 . ... 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;