hi
the following code :
while Timer < Skip_After loop
Timer := 1.0 + @;
delay 1.0;
ada.text_io.Put(Natural(Skip_After - Timer)'Img);
--USER ENDS THE WAITING PERIOD BEFORE IT'S END ?
TIO.LOOK_AHEAD(ITEM => CHAR,
END_OF_LINE => HIT); >
ada.text_io.GET_IMMEDIATE(ITEM => CHAR,
AVAILABLE => HIT);
IF HIT THEN
RETURN;
END IF;
end loop;
My problem under ubuntu is that get_immediate pauses the program if no key is hit.
Therefore available is not set and this little routine cannot perform as I want.
On my system, Get_Immediate does /not/ use the inputs collected (but not "consumed") by Look_Ahead, but instead checks if there are _new_ input keystrokes. If there are none, Get_Immediate returns "not Available"
(Hit is False) and so the loop continues.
Niklas Holsti schrieb am Mittwoch, 22. Februar 2023 um 18:36:06 UTC+1:False and the value of Item is not specified.
On my system, Get_Immediate does /not/ use the inputs collected (but not "consumed") by Look_Ahead, but instead checks if there are _new_ input keystrokes. If there are none, Get_Immediate returns "not Available"Are you sure? With GNAT Community 2021 (20210519-103) targeting x86_64-w64-mingw32,
(Hit is False) and so the loop continues.
loop
Look_Ahead (Char, EoL); Put ("Look_Ahead: '" & Char & "', End_of_Line => " & EoL'Image); New_Line;
Get_Immediate (Char, Avl); Put ("Get_Immediate: '" & Char & "', Available => " & Avl'Image); New_Line;
end loop;
I get:
ab x<RETRUN>
Look_Ahead: 'a', End_of_Line => FALSE
Get_Immediate: 'a', Available => TRUE
Look_Ahead: 'b', End_of_Line => FALSE
Get_Immediate: 'b', Available => TRUE
Look_Ahead: ' ', End_of_Line => FALSE
Get_Immediate: ' ', Available => TRUE
Look_Ahead: 'x', End_of_Line => FALSE
Get_Immediate: 'x', Available => TRUE
Look_Ahead: '0', End_of_Line => TRUE
Get_Immediate: ' <- This is the EoL
', Available => TRUE
So Get_Immediate returns the next not yet consumed character. This is inline with A.10.7(12/3):
If a character, either control or graphic, is available from the specified File or the default input file, then the character is read; Available is True and Item contains the value of this character. If a character is not available, then Available is
On Thursday, February 23, 2023 at 3:26:09 PM UTC+1, AdaMagica wrote:
Niklas Holsti schrieb am Mittwoch, 22. Februar 2023 um 18:36:06 UTC+1:
Hi,
Many thanks for your time and answers
My problem under ubuntu is that get_immediate pauses the program if no key is hit.
Therefore available is not set and this little routine cannot perform as I want.
Any idea on how i can write such a simple routine that works ??
On 2023-02-23 16:26, AdaMagica wrote:
Niklas Holsti schrieb am Mittwoch, 22. Februar 2023 um 18:36:06 UTC+1:
On my system, Get_Immediate does /not/ use the inputs collected (but not >>> "consumed") by Look_Ahead, but instead checks if there are _new_ input
keystrokes. If there are none, Get_Immediate returns "not Available"
(Hit is False) and so the loop continues.
Are you sure?
That is what I observe.
With GNAT Community 2021 (20210519-103) targeting x86_64-w64-mingw32,
loop
Look_Ahead (Char, EoL); Put ("Look_Ahead: '" & Char & "',
End_of_Line => " & EoL'Image); New_Line;
Get_Immediate (Char, Avl); Put ("Get_Immediate: '" & Char & "', >> Available => " & Avl'Image); New_Line;
end loop;
I get:
ab x<RETRUN>
Look_Ahead: 'a', End_of_Line => FALSE
Get_Immediate: 'a', Available => TRUE
Look_Ahead: 'b', End_of_Line => FALSE
Get_Immediate: 'b', Available => TRUE
Look_Ahead: ' ', End_of_Line => FALSE
Get_Immediate: ' ', Available => TRUE
Look_Ahead: 'x', End_of_Line => FALSE
Get_Immediate: 'x', Available => TRUE
Look_Ahead: '0', End_of_Line => TRUE
Get_Immediate: ' <- This is
the EoL
', Available => TRUE
On my system:
ab x<RETURN>
Look_Ahead: 'a', End_of_Line => FALSE
Get_Immediate: '', Available => FALSE
Look_Ahead: 'a', End_of_Line => FALSE
Get_Immediate: '', Available => FALSE
Look_Ahead: 'a', End_of_Line => FALSE
Get_Immediate: '', Available => FALSE
and so on for ever, with Look_Ahead never waiting for new input.
The behaviour on my system is certainly different from yours. I can see
that both behaviours could be useful, depending on the program's needs. However, I was certainly surprised to see my system's behaviour, and a
priori I expected to get the behaviour you see.
My system is oldish:
GNAT Community 2019 (20190517-83)
macOS 10.14.6 Mojave
This difference appears when mixing Look_Ahead and Get_Immediate,
On 2023-02-23 16:26, AdaMagica wrote:
Niklas Holsti schrieb am Mittwoch, 22. Februar 2023 um 18:36:06 UTC+1:
On my system, Get_Immediate does /not/ use the inputs collected (but not >>> "consumed") by Look_Ahead, but instead checks if there are _new_ input
keystrokes. If there are none, Get_Immediate returns "not Available"
(Hit is False) and so the loop continues.
Are you sure?
That is what I observe.
Niklas Holsti schrieb am Mittwoch, 22. Februar 2023 um 18:36:06 UTC+1:
On my system, Get_Immediate does /not/ use the inputs collected (but not
"consumed") by Look_Ahead, but instead checks if there are _new_ input
keystrokes. If there are none, Get_Immediate returns "not Available"
(Hit is False) and so the loop continues.
Are you sure?
With GNAT Community 2021 (20210519-103) targeting x86_64-w64-mingw32,
loop
Look_Ahead (Char, EoL); Put ("Look_Ahead: '" & Char & "', End_of_Line => " & EoL'Image); New_Line;
Get_Immediate (Char, Avl); Put ("Get_Immediate: '" & Char & "', Available => " & Avl'Image); New_Line;
end loop;
I get:
ab x<RETRUN>
Look_Ahead: 'a', End_of_Line => FALSE
Get_Immediate: 'a', Available => TRUE
Look_Ahead: 'b', End_of_Line => FALSE
Get_Immediate: 'b', Available => TRUE
Look_Ahead: ' ', End_of_Line => FALSE
Get_Immediate: ' ', Available => TRUE
Look_Ahead: 'x', End_of_Line => FALSE
Get_Immediate: 'x', Available => TRUE
Look_Ahead: '0', End_of_Line => TRUE
Get_Immediate: ' <- This is the EoL ', Available => TRUE
On 2023-02-23 20:14, Dmitry A. Kazakov wrote:
On 2023-02-23 18:35, Niklas Holsti wrote:
On 2023-02-23 16:26, AdaMagica wrote:
Niklas Holsti schrieb am Mittwoch, 22. Februar 2023 um 18:36:06 UTC+1: >>>> On my system, Get_Immediate does /not/ use the inputs collected (but >>>> not
"consumed") by Look_Ahead, but instead checks if there are _new_ input >>>> keystrokes. If there are none, Get_Immediate returns "not Available" >>>> (Hit is False) and so the loop continues.
Are you sure?
That is what I observe.
The implementation of Look_Ahead calls getc followed by ungetc. Thus it blocks until an input if there is no buffered. And not just input, butThat seems in order.
for a line or file end.
However, the crux of the question is in Get_Immediate. Do you know how
that is implemented on various systems? It has to disable line buffering
and line editing on the input stream. One question is whether and how
such "tty" configuration changes affect whatever buffers getc/ungetc use.
On my system, if Look_Ahead uses getc and ungetc, it seems Get_Immediate does not use the same buffers, and has no effect on those buffers. That could be desirable behaviour in some cases, undesirable in others.
On AdaMagica's system, it seems that Get_Immediate uses the same buffers
as Look_Ahead (getc/ungetc).
On 2023-02-23 18:35, Niklas Holsti wrote:
On 2023-02-23 16:26, AdaMagica wrote:
Niklas Holsti schrieb am Mittwoch, 22. Februar 2023 um 18:36:06 UTC+1:
On my system, Get_Immediate does /not/ use the inputs collected (but
not
"consumed") by Look_Ahead, but instead checks if there are _new_ input >>>> keystrokes. If there are none, Get_Immediate returns "not Available"
(Hit is False) and so the loop continues.
Are you sure?
That is what I observe.
The implementation of Look_Ahead calls getc followed by ungetc. Thus it blocks until an input if there is no buffered. And not just input, but
for a line or file end.
On Thursday, February 23, 2023 at 7:29:36 PM UTC+1, Niklas Holsti wrote:
On 2023-02-23 20:14, Dmitry A. Kazakov wrote:
On 2023-02-23 18:35, Niklas Holsti wrote:That seems in order.
On 2023-02-23 16:26, AdaMagica wrote:
Niklas Holsti schrieb am Mittwoch, 22. Februar 2023 um 18:36:06 UTC+1: >>>>>> On my system, Get_Immediate does /not/ use the inputs collected (but >>>>>> not
"consumed") by Look_Ahead, but instead checks if there are _new_ input >>>>>> keystrokes. If there are none, Get_Immediate returns "not Available" >>>>>> (Hit is False) and so the loop continues.
Are you sure?
That is what I observe.
The implementation of Look_Ahead calls getc followed by ungetc. Thus it
blocks until an input if there is no buffered. And not just input, but
for a line or file end.
However, the crux of the question is in Get_Immediate. Do you know how
that is implemented on various systems? It has to disable line buffering
and line editing on the input stream. One question is whether and how
such "tty" configuration changes affect whatever buffers getc/ungetc use.
On my system, if Look_Ahead uses getc and ungetc, it seems Get_Immediate
does not use the same buffers, and has no effect on those buffers. That
could be desirable behaviour in some cases, undesirable in others.
On AdaMagica's system, it seems that Get_Immediate uses the same buffers
as Look_Ahead (getc/ungetc).
Hi,
On my ubuntu system the
ada.text_io.GET_IMMEDIATE(ITEM => CHAR, AVAILABLE => HIT);
just pause the program regardless of any key being hit.
I just cannot use a wait (several shorts one in a row) interrupted by a key hit.
Any possibility you may know of ??
Hi,
On my ubuntu system the
ada.text_io.GET_IMMEDIATE(ITEM => CHAR, AVAILABLE => HIT);
just pause the program regardless of any key being hit.
However, the crux of the question is in Get_Immediate. Do you know how
that is implemented on various systems?
It is to expect it to work with the "standard" terminal [emulator].
Anything else is a long shot.
On my system, if Look_Ahead uses getc and ungetc, it seems Get_Immediate
does not use the same buffers, and has no effect on those buffers. That
could be desirable behaviour in some cases, undesirable in others.
On AdaMagica's system, it seems that Get_Immediate uses the same buffers
as Look_Ahead (getc/ungetc).
Dmitry A. Kazakov schrieb am Donnerstag, 23. Februar 2023 um 21:41:16 UTC+1:
It is to expect it to work with the "standard" terminal [emulator].
Anything else is a long shot.
Right, there may be weird file kinds where Get_Immediate fails.
Niklas Holsti schrieb am Donnerstag, 23. Februar 2023 um 19:29:36 UTC+1:
On my system, if Look_Ahead uses getc and ungetc, it seems Get_Immediate
does not use the same buffers, and has no effect on those buffers. That
could be desirable behaviour in some cases, undesirable in others.
On AdaMagica's system, it seems that Get_Immediate uses the same buffers
as Look_Ahead (getc/ungetc).
I further experimented.
loop
Get_Immediate (Char, Avl); Put ("Get_Immediate: '" & Char & "', Available => " & Avl'Image); New_Line;
delay 1.0;
end loop;
Run in GPS, it behaves strangely (seems to be one of Dmitry's weird files)
ab c<return>
Get_Immediate: 'a', Available => TRUE
Get_Immediate: 'b', Available => TRUE
Get_Immediate: ' ', Available => TRUE
Get_Immediate: 'c', Available => TRUE
Get_Immediate: '
', Available => TRUE long pause until:
<return>
Get_Immediate: '
', Available => TRUE
It only reacts after <return> is pressed.
On a terminal window, the same executable reacts as I expect
(this is why the delay statement is there).
Get_Immediate: ' ', Available => FALSE
Get_Immediate: ' ', Available => FALSE
Get_Immediate: ' ', Available => FALSE as long as no <return> is pressed
a note: no <return>
Get_Immediate: 'a', Available => TRUE
Get_Immediate: ' ', Available => FALSE and so on.
Looks to me like the behaviour shown last is the correct one (let
aside weird terminals).
Niklas, your GNAT is two years older than mine. I guess GNAT has been corrected (at least changed) in between.
If we all disagree how it should work, we should post this on Ada
Comment.
the following code :
if Skip_After > 0.0
then
-- KEEP THE USER'S ATTENTION
while Timer < Skip_After loop
Timer := 1.0 + @;
delay 1.0;
ada.text_io.Put(Natural(Skip_After - Timer)'Img);
--USER ENDS THE WAITING PERIOD BEFORE IT'S END ?
TIO.LOOK_AHEAD(ITEM => CHAR,
END_OF_LINE => HIT);
ada.text_io.GET_IMMEDIATE(ITEM => CHAR,
AVAILABLE => HIT);
IF HIT THEN
RETURN;
END IF;
end loop;
-- USER WAITED FOR THE WHOLE WAITING PERIOD
-- LET HIM READ THE ZERO ON THE SCREEN
delay 1.0;
return;
end if;
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 379 |
Nodes: | 16 (2 / 14) |
Uptime: | 41:29:03 |
Calls: | 8,141 |
Calls today: | 4 |
Files: | 13,085 |
Messages: | 5,857,791 |