When I build and run the following program using Gnat 11 in Linux Mint
21.2, the keys I press are echoed on the console. According to the Ada Reference Manual, they should not be echoed. Is this a compiler error?
with ada.text_io; use ada.text_io;
procedure test3 is
c: character;
avail: boolean;
begin
loop
loop
Get_Immediate(c, Avail);
if Avail then
exit;
end if;
delay 0.01;
end loop;
end loop;
end test3;
This does not happen if I call get_immediate without the avail
parameter, i.e. get_immediate(c);
richardthiebaud <thiebauddick2@aol.com> writes:https://www.adaic.org/resources/add_content/standards/05rm/html/RM-A-10-7.html
When I build and run the following program using Gnat 11 in Linux Mint
21.2, the keys I press are echoed on the console. According to the Ada
Reference Manual, they should not be echoed. Is this a compiler error?
Where does the ARM say that?
with ada.text_io; use ada.text_io;
procedure test3 is
c: character;
avail: boolean;
begin
loop
loop
Get_Immediate(c, Avail);
if Avail then
exit;
end if;
delay 0.01;
end loop;
end loop;
end test3;
This does not happen if I call get_immediate without the avail
parameter, i.e. get_immediate(c);
On 10/2/23 01:48, Keith Thompson wrote:
richardthiebaud <thiebauddick2@aol.com> writes:https://www.adaic.org/resources/add_content/standards/05rm/html/RM-A-10-7.html
When I build and run the following program using Gnat 11 in Linux MintWhere does the ARM say that?
21.2, the keys I press are echoed on the console. According to the Ada
Reference Manual, they should not be echoed. Is this a compiler error?
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 False and the value of
Item is not specified. Mode_Error is propagated if the mode of the file
is not In_File. End_Error is propagated if at the end of the file. The current column, line and page numbers for the file are not affected.
richardthiebaud <thiebauddick2@aol.com> writes:
On 10/2/23 01:48, Keith Thompson wrote:
richardthiebaud <thiebauddick2@aol.com> writes:https://www.adaic.org/resources/add_content/standards/05rm/html/RM-A-10-7.html
When I build and run the following program using Gnat 11 in Linux Mint >>>> 21.2, the keys I press are echoed on the console. According to the Ada >>>> Reference Manual, they should not be echoed. Is this a compiler error?Where does the ARM say that?
I don't see anything there about the character being echoed, or not.
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 False and the value of
Item is not specified. Mode_Error is propagated if the mode of the file
is not In_File. End_Error is propagated if at the end of the file. The
current column, line and page numbers for the file are not affected.
Are you assuming that not updating the current column, line, and page
numbers for the file implies that the character is not echoed?
[...]
richardthiebaud <thiebauddick2@aol.com> writes:
On 10/2/23 01:48, Keith Thompson wrote:
richardthiebaud <thiebauddick2@aol.com> writes:https://www.adaic.org/resources/add_content/standards/05rm/html/RM-A-10-7.html
When I build and run the following program using Gnat 11 in Linux Mint >>>> 21.2, the keys I press are echoed on the console. According to the Ada >>>> Reference Manual, they should not be echoed. Is this a compiler error?Where does the ARM say that?
I don't see anything there about the character being echoed, or not.
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 False and the value of
Item is not specified. Mode_Error is propagated if the mode of the file
is not In_File. End_Error is propagated if at the end of the file. The
current column, line and page numbers for the file are not affected.
Are you assuming that not updating the current column, line, and page
numbers for the file implies that the character is not echoed?
[...]
On 10/2/23 18:27, Keith Thompson wrote:
richardthiebaud <thiebauddick2@aol.com> writes:
On 10/2/23 01:48, Keith Thompson wrote:
richardthiebaud <thiebauddick2@aol.com> writes:https://www.adaic.org/resources/add_content/standards/05rm/html/RM-A-10-7.html
When I build and run the following program using Gnat 11 in Linux Mint >>>>> 21.2, the keys I press are echoed on the console. According to the Ada >>>>> Reference Manual, they should not be echoed. Is this a compiler error? >>>> Where does the ARM say that?
I don't see anything there about the character being echoed, or not.
In any case, when it echos the character. it increases the currentIf 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 False and the value of
Item is not specified. Mode_Error is propagated if the mode of the file
is not In_File. End_Error is propagated if at the end of the file. The
current column, line and page numbers for the file are not affected.
Are you assuming that not updating the current column, line, and page
numbers for the file implies that the character is not echoed?
[...]
column by 1, and that does contradict the Ada Reference Manual.
Possibly this is why AdaCore have given different echoing behaviors to
the two forms of Get_Immediate, with and without the "Available"
parameter. If so, this echo difference is unfortunately coupled with
the wait/no-wait behavior difference, and that coupling may be
unwanted.
When I build and run the following program using Gnat 11 in Linux Mint 21.2, the keys I press are echoed on the console.
Niklas Holsti <niklas.holsti@tidorum.invalid> writes:
Possibly this is why AdaCore have given different echoing behaviors to
the two forms of Get_Immediate, with and without the "Available"
parameter. If so, this echo difference is unfortunately coupled with
the wait/no-wait behavior difference, and that coupling may be
unwanted.
The low-level Get_Immediate implementation is in sysdep.c (probably not
in the adainclude/ directory in an installed compiler), in
getc_immediate() and getc_immediate_nowait(), both of which call getc_immediate_common(), and I can't see any difference! ECHO gets
turned off in getc_immediate_common(), regardless of caller - see link.
https://github.com/gcc-mirror/gcc/blob/3ca09d684e496240a87c0327687e2898060c2363/gcc/ada/sysdep.c#L387
Simon Wright <simon@pushface.org> writes:
The low-level Get_Immediate implementation is in sysdep.c (probably
not in the adainclude/ directory in an installed compiler), in
getc_immediate() and getc_immediate_nowait(), both of which call
getc_immediate_common(), and I can't see any difference! ECHO gets
turned off in getc_immediate_common(), regardless of caller - see
link.
https://github.com/gcc-mirror/gcc/blob/3ca09d684e496240a87c0327687e2898060c2363/gcc/ada/sysdep.c#L387
I haven't really looked into this, but I *think* what's happening is
that for the versions with the Available parameter, ECHO hasn't yet been turned off when the user types the character. If you type 'x', it
echoes immediately, because the program has no way of knowing that the character will later be consumed by a call to Get_Immediate. Presumably
if the user hasn't typed anything, causing Available to be set to false, Get_Immediate will turn echoing off and back on again very quickly.
Echoing is disabled only for small fraction of a second it takes for Get_Immediate to be executed.
The Get_Immediate functions without the Available parameter block
until a character is entered. They can disable echoing before the
character is entered. Echoing will typically be disabled for minutes
or seconds, from the time Get_Immediate is called and the time the
user types something.
The only solution I can think of would be to disable echoing (in some non-portable manner; I don't think the standard library provides this)
before the user starts typing. (Perhaps you want to run the
Get_Immediate without the Available parameter in a separate task?)
Or, alternatively, don't turn echoing off at all - what's the use case
for turning it off? After all, the ARM says nothing about it.
On 2023-10-04 10:22, Simon Wright wrote:
Or, alternatively, don't turn echoing off at all - what's the use
case
for turning it off? After all, the ARM says nothing about it.
The use case is inputting passwords and the like. See Password_Line (https://github.com/jrcarter/Encryption-utilities/blob/master/password_line.ads)
for an example. Note that this has identical behavior with GNAT/Linux
and ObjectAda/Windows.
Obviously you need to turn echoing off for password input. But neither
the ARM nor the GNAT RM says anything about Get_Immediate's echoing behaviour, so it's hard to explain why OA does the same thing. Does its manual specify this behaviour?
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
Simon Wright <simon@pushface.org> writes:
The low-level Get_Immediate implementation is in sysdep.c (probably
not in the adainclude/ directory in an installed compiler), in
getc_immediate() and getc_immediate_nowait(), both of which call
getc_immediate_common(), and I can't see any difference! ECHO gets
turned off in getc_immediate_common(), regardless of caller - see
link.
https://github.com/gcc-mirror/gcc/blob/3ca09d684e496240a87c0327687e2898060c2363/gcc/ada/sysdep.c#L387
I haven't really looked into this, but I *think* what's happening is
that for the versions with the Available parameter, ECHO hasn't yet been
turned off when the user types the character. If you type 'x', it
echoes immediately, because the program has no way of knowing that the
character will later be consumed by a call to Get_Immediate. Presumably
if the user hasn't typed anything, causing Available to be set to false,
Get_Immediate will turn echoing off and back on again very quickly.
Echoing is disabled only for small fraction of a second it takes for
Get_Immediate to be executed.
The Get_Immediate functions without the Available parameter block
until a character is entered. They can disable echoing before the
character is entered. Echoing will typically be disabled for minutes
or seconds, from the time Get_Immediate is called and the time the
user types something.
The only solution I can think of would be to disable echoing (in some
non-portable manner; I don't think the standard library provides this)
before the user starts typing. (Perhaps you want to run the
Get_Immediate without the Available parameter in a separate task?)
Great analysis!
On 2023-10-04 11:22, Simon Wright wrote:
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
Simon Wright <simon@pushface.org> writes:Great analysis!
The low-level Get_Immediate implementation is in sysdep.c (probably
not in the adainclude/ directory in an installed compiler), in
getc_immediate() and getc_immediate_nowait(), both of which call
getc_immediate_common(), and I can't see any difference! ECHO gets
turned off in getc_immediate_common(), regardless of caller - see
link.
https://github.com/gcc-mirror/gcc/blob/3ca09d684e496240a87c0327687e2898060c2363/gcc/ada/sysdep.c#L387
I haven't really looked into this, but I *think* what's happening is
that for the versions with the Available parameter, ECHO hasn't yet been >>> turned off when the user types the character. If you type 'x', it
echoes immediately, because the program has no way of knowing that the
character will later be consumed by a call to Get_Immediate. Presumably >>> if the user hasn't typed anything, causing Available to be set to false, >>> Get_Immediate will turn echoing off and back on again very quickly.
Echoing is disabled only for small fraction of a second it takes for
Get_Immediate to be executed.
The Get_Immediate functions without the Available parameter block
until a character is entered. They can disable echoing before the
character is entered. Echoing will typically be disabled for minutes
or seconds, from the time Get_Immediate is called and the time the
user types something.
The only solution I can think of would be to disable echoing (in some
non-portable manner; I don't think the standard library provides this)
before the user starts typing. (Perhaps you want to run the
Get_Immediate without the Available parameter in a separate task?)
Yes indeed.
A possible solution in Text_IO would be for Get_Immediate with
Available not to enable echo when it exits. Get_Immediate with
Available is typically called repeatedly, with no other input from the terminal in between these calls, so it should be ok to keep echo
disabled from one such call to another. Any non-immediate input
operation on the terminal (that is, on this Text_IO file) should start
by re-enabling echo if it was disabled. Possibly the same should apply
also to Get_Immediate without Available, that is, it should leave echo disabled, until some non-immediate input operation re-enables echo.
with ada.text_io; use ada.text_io;
procedure test3 is
c: character;
avail: boolean;
begin
loop
loop
Get_Immediate(c, Avail);
if Avail then
exit;
end if;
delay 0.01;
end loop;
end loop;
end test3;
On 2023-10-02 04:42, richardthiebaud wrote:
with ada.text_io; use ada.text_io;
procedure test3 is
c: character;
avail: boolean;
begin
loop
loop
Get_Immediate(c, Avail);
if Avail then
exit;
end if;
delay 0.01;
end loop;
end loop;
end test3;
I should have checked this earlier, but this does not echo with ObjectAda.
Niklas Holsti <niklas.holsti@tidorum.invalid> writes:
On 2023-10-04 11:22, Simon Wright wrote:
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
Simon Wright <simon@pushface.org> writes:Great analysis!
The low-level Get_Immediate implementation is in sysdep.c (probably
not in the adainclude/ directory in an installed compiler), in
getc_immediate() and getc_immediate_nowait(), both of which call
getc_immediate_common(), and I can't see any difference! ECHO gets
turned off in getc_immediate_common(), regardless of caller - see
link.
https://github.com/gcc-mirror/gcc/blob/3ca09d684e496240a87c0327687e2898060c2363/gcc/ada/sysdep.c#L387
I haven't really looked into this, but I *think* what's happening is
that for the versions with the Available parameter, ECHO hasn't yet been >>>> turned off when the user types the character. If you type 'x', it
echoes immediately, because the program has no way of knowing that the >>>> character will later be consumed by a call to Get_Immediate. Presumably >>>> if the user hasn't typed anything, causing Available to be set to false, >>>> Get_Immediate will turn echoing off and back on again very quickly.
Echoing is disabled only for small fraction of a second it takes for
Get_Immediate to be executed.
The Get_Immediate functions without the Available parameter block
until a character is entered. They can disable echoing before the
character is entered. Echoing will typically be disabled for minutes
or seconds, from the time Get_Immediate is called and the time the
user types something.
The only solution I can think of would be to disable echoing (in some
non-portable manner; I don't think the standard library provides this) >>>> before the user starts typing. (Perhaps you want to run the
Get_Immediate without the Available parameter in a separate task?)
Yes indeed.
A possible solution in Text_IO would be for Get_Immediate with
Available not to enable echo when it exits. Get_Immediate with
Available is typically called repeatedly, with no other input from the
terminal in between these calls, so it should be ok to keep echo
disabled from one such call to another. Any non-immediate input
operation on the terminal (that is, on this Text_IO file) should start
by re-enabling echo if it was disabled. Possibly the same should apply
also to Get_Immediate without Available, that is, it should leave echo
disabled, until some non-immediate input operation re-enables echo.
The *first* character typed would still echo.
I suggest that what's needed is a way to turn echoing on and off.
Meanwhile, would calling Get_Immediate *without* the Available parameter (which blocks and turns echoing off until after a character is typed) in
a separate task work? I haven't tried it.
Of course you'd need to be careful not to have I/O calls from
separate tasks interfere with each other.
On 2023-10-04 13:38, Simon Wright wrote:
Obviously you need to turn echoing off for password input. But neither
the ARM nor the GNAT RM says anything about Get_Immediate's echoing
behaviour, so it's hard to explain why OA does the same thing. Does its
manual specify this behaviour?
Unfortunately, Ada does not provide a standard way to turn off echo.
I agree that the ARM says nothing about echo for any of its operations on Standard_Input, but clearly there is a broad consensus of Ada.Text_IO
writers and users who think this is desirable behavior.
"Jeffrey R.Carter" <spam.jrcarter.not@spam.acm.org.not> writes:
I should have checked this earlier, but this does not echo with ObjectAda.
On what target system?
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 379 |
Nodes: | 16 (2 / 14) |
Uptime: | 83:49:23 |
Calls: | 8,091 |
Files: | 13,069 |
Messages: | 5,851,128 |