comp.lang.ada
 help / color / mirror / Atom feed
* get_immediate echoe character--compiled error?
@ 2023-10-02  2:42 richardthiebaud
  2023-10-02  5:48 ` Keith Thompson
                   ` (2 more replies)
  0 siblings, 3 replies; 21+ messages in thread
From: richardthiebaud @ 2023-10-02  2:42 UTC (permalink / raw)


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);

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: get_immediate echoe character--compiled error?
  2023-10-02  2:42 get_immediate echoe character--compiled error? richardthiebaud
@ 2023-10-02  5:48 ` Keith Thompson
  2023-10-02 20:07   ` richardthiebaud
  2023-10-03 21:00 ` G.B.
  2023-10-04 21:14 ` Jeffrey R.Carter
  2 siblings, 1 reply; 21+ messages in thread
From: Keith Thompson @ 2023-10-02  5:48 UTC (permalink / raw)


richardthiebaud <thiebauddick2@aol.com> writes:
> 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);
>

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: get_immediate echoe character--compiled error?
  2023-10-02  5:48 ` Keith Thompson
@ 2023-10-02 20:07   ` richardthiebaud
  2023-10-02 22:27     ` Keith Thompson
  0 siblings, 1 reply; 21+ messages in thread
From: richardthiebaud @ 2023-10-02 20:07 UTC (permalink / raw)


On 10/2/23 01:48, Keith Thompson wrote:
> richardthiebaud <thiebauddick2@aol.com> writes:
>> 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?
https://www.adaic.org/resources/add_content/standards/05rm/html/RM-A-10-7.html

> 
>> 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);
>>
> 

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: get_immediate echoe character--compiled error?
  2023-10-02 20:07   ` richardthiebaud
@ 2023-10-02 22:27     ` Keith Thompson
  2023-10-02 22:41       ` richardthiebaud
  2023-10-02 22:47       ` richardthiebaud
  0 siblings, 2 replies; 21+ messages in thread
From: Keith Thompson @ 2023-10-02 22:27 UTC (permalink / raw)


richardthiebaud <thiebauddick2@aol.com> writes:
> On 10/2/23 01:48, Keith Thompson wrote:
>> richardthiebaud <thiebauddick2@aol.com> writes:
>>> 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?
> https://www.adaic.org/resources/add_content/standards/05rm/html/RM-A-10-7.html

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?

[...]

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: get_immediate echoe character--compiled error?
  2023-10-02 22:27     ` Keith Thompson
@ 2023-10-02 22:41       ` richardthiebaud
  2023-10-02 22:47       ` richardthiebaud
  1 sibling, 0 replies; 21+ messages in thread
From: richardthiebaud @ 2023-10-02 22:41 UTC (permalink / raw)


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:
>>>> 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?
>> https://www.adaic.org/resources/add_content/standards/05rm/html/RM-A-10-7.html
> 
> 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?
> 
> [...]
> 
Yes.

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: get_immediate echoe character--compiled error?
  2023-10-02 22:27     ` Keith Thompson
  2023-10-02 22:41       ` richardthiebaud
@ 2023-10-02 22:47       ` richardthiebaud
  2023-10-03  8:41         ` Niklas Holsti
  1 sibling, 1 reply; 21+ messages in thread
From: richardthiebaud @ 2023-10-02 22:47 UTC (permalink / raw)


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:
>>>> 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?
>> https://www.adaic.org/resources/add_content/standards/05rm/html/RM-A-10-7.html
> 
> 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?
> 
> [...]
> 
In any case, when it echos the character. it increases the current 
column by 1, and that does contradict the Ada Reference Manual.

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: get_immediate echoe character--compiled error?
  2023-10-02 22:47       ` richardthiebaud
@ 2023-10-03  8:41         ` Niklas Holsti
  2023-10-03 10:20           ` Simon Wright
  0 siblings, 1 reply; 21+ messages in thread
From: Niklas Holsti @ 2023-10-03  8:41 UTC (permalink / raw)


On 2023-10-03 1:47, richardthiebaud wrote:
> 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:
>>>>> 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?
>>> https://www.adaic.org/resources/add_content/standards/05rm/html/RM-A-10-7.html
>>
>> I don't see anything there about the character being echoed, or not.


Nor do I. But perhaps there should be something, since "not echoing" is 
useful behavior and the program can itself echo characters if that is 
desired.

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.

There are (or have been) computer terminals with local echo, where the 
program cannot prevent the display of each keystroke. So the "no echo" 
behavior cannot be an absolute requirement in the Ada manual, but it 
could be Implementation Advice.


>>> 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?
>>
>> [...]
>>
> In any case, when it echos the character. it increases the current 
> column by 1, and that does contradict the Ada Reference Manual.

You are assuming that "current column" in the Ada Reference Manual means 
the same as the "current column position of the terminal/screen cursor", 
which is not the case, so there is no formal contradiction. The Ada 
"current column" refers to an internal state of the file.

For an unknown type of terminal/screen, deducing the current cursor 
column from the stream of input characters and output characters is not 
feasible, because it depends on the device's interpretation of 
formatting control characters such as TABs and on the width of the 
screen or terminal window.

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: get_immediate echoe character--compiled error?
  2023-10-03  8:41         ` Niklas Holsti
@ 2023-10-03 10:20           ` Simon Wright
  2023-10-04  0:13             ` Keith Thompson
  0 siblings, 1 reply; 21+ messages in thread
From: Simon Wright @ 2023-10-03 10:20 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: get_immediate echoe character--compiled error?
  2023-10-02  2:42 get_immediate echoe character--compiled error? richardthiebaud
  2023-10-02  5:48 ` Keith Thompson
@ 2023-10-03 21:00 ` G.B.
  2023-10-04 21:14 ` Jeffrey R.Carter
  2 siblings, 0 replies; 21+ messages in thread
From: G.B. @ 2023-10-03 21:00 UTC (permalink / raw)


On 02.10.23 04:42, richardthiebaud wrote:
> 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. 

Which console?

Can you try to run a C program in the same console
that tests for it to be y TTY? See Simon Wright's link
to GNAT's implementation. The C program would be
calling isatty(0) or isatty(fileno(your_stream));

Some IDEs have a console window that is not
a TTY in the sense of termios(4)/tcsetattr(3).
Echoing is different, then.

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: get_immediate echoe character--compiled error?
  2023-10-03 10:20           ` Simon Wright
@ 2023-10-04  0:13             ` Keith Thompson
  2023-10-04  8:22               ` Simon Wright
  0 siblings, 1 reply; 21+ messages in thread
From: Keith Thompson @ 2023-10-04  0:13 UTC (permalink / raw)


Simon Wright <simon@pushface.org> writes:
> 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

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?)

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: get_immediate echoe character--compiled error?
  2023-10-04  0:13             ` Keith Thompson
@ 2023-10-04  8:22               ` Simon Wright
  2023-10-04 10:48                 ` Jeffrey R.Carter
  2023-10-04 16:55                 ` Niklas Holsti
  0 siblings, 2 replies; 21+ messages in thread
From: Simon Wright @ 2023-10-04  8:22 UTC (permalink / raw)


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! Is this worth raising a PR on GCC Bugzilla? (maybe only
on the documentation?)

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.

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: get_immediate echoe character--compiled error?
  2023-10-04  8:22               ` Simon Wright
@ 2023-10-04 10:48                 ` Jeffrey R.Carter
  2023-10-04 11:38                   ` Simon Wright
  2023-10-04 16:55                 ` Niklas Holsti
  1 sibling, 1 reply; 21+ messages in thread
From: Jeffrey R.Carter @ 2023-10-04 10:48 UTC (permalink / raw)


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.

-- 
Jeff Carter
“[A]bout half the patterns in the 'Gang of Four'
book only exist because of defects in C++ ...”
Brian Drummond
174

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: get_immediate echoe character--compiled error?
  2023-10-04 10:48                 ` Jeffrey R.Carter
@ 2023-10-04 11:38                   ` Simon Wright
  2023-10-04 13:05                     ` Jeffrey R.Carter
  0 siblings, 1 reply; 21+ messages in thread
From: Simon Wright @ 2023-10-04 11:38 UTC (permalink / raw)


"Jeffrey R.Carter" <spam.jrcarter.not@spam.acm.org.not> writes:

> 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?

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: get_immediate echoe character--compiled error?
  2023-10-04 11:38                   ` Simon Wright
@ 2023-10-04 13:05                     ` Jeffrey R.Carter
  2023-10-05  0:43                       ` Randy Brukardt
  0 siblings, 1 reply; 21+ messages in thread
From: Jeffrey R.Carter @ 2023-10-04 13:05 UTC (permalink / raw)


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.

-- 
Jeff Carter
“[A]bout half the patterns in the 'Gang of Four'
book only exist because of defects in C++ ...”
Brian Drummond
174

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: get_immediate echoe character--compiled error?
  2023-10-04  8:22               ` Simon Wright
  2023-10-04 10:48                 ` Jeffrey R.Carter
@ 2023-10-04 16:55                 ` Niklas Holsti
  2023-10-04 19:39                   ` Keith Thompson
  1 sibling, 1 reply; 21+ messages in thread
From: Niklas Holsti @ 2023-10-04 16:55 UTC (permalink / raw)


On 2023-10-04 11:22, Simon Wright wrote:
> 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! 


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.

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: get_immediate echoe character--compiled error?
  2023-10-04 16:55                 ` Niklas Holsti
@ 2023-10-04 19:39                   ` Keith Thompson
  2023-10-04 21:20                     ` Niklas Holsti
  0 siblings, 1 reply; 21+ messages in thread
From: Keith Thompson @ 2023-10-04 19:39 UTC (permalink / raw)


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:
>>>> 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! 
>
>
> 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.

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: get_immediate echoe character--compiled error?
  2023-10-02  2:42 get_immediate echoe character--compiled error? richardthiebaud
  2023-10-02  5:48 ` Keith Thompson
  2023-10-03 21:00 ` G.B.
@ 2023-10-04 21:14 ` Jeffrey R.Carter
  2023-10-04 22:12   ` Keith Thompson
  2 siblings, 1 reply; 21+ messages in thread
From: Jeffrey R.Carter @ 2023-10-04 21:14 UTC (permalink / raw)


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.

-- 
Jeff Carter
“[A]bout half the patterns in the 'Gang of Four'
book only exist because of defects in C++ ...”
Brian Drummond
174

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: get_immediate echoe character--compiled error?
  2023-10-04 19:39                   ` Keith Thompson
@ 2023-10-04 21:20                     ` Niklas Holsti
  0 siblings, 0 replies; 21+ messages in thread
From: Niklas Holsti @ 2023-10-04 21:20 UTC (permalink / raw)


On 2023-10-04 22:39, Keith Thompson wrote:
> 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:
>>>>> 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!
>>
>>
>> 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.


Only if the user is quick enough to type it before the first call of 
Get_Immediate.

If Get_Immediate is called for example to enter a password, usually the 
program will first prompt the user to "Enter password:" and then at once 
call Get_Immediate. Only a user who starts typing before the prompt is 
visible would have time to type something before the (first) call of 
Get_Immediate.


> I suggest that what's needed is a way to turn echoing on and off.


The user could still be quick enough to type characters before the echo 
is turned off, so they would echo.


> 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. 


That should work, provided that the Ada run-time system does not block 
the whole program when one task blocks on an I/O request. There have 
been, and perhaps still are, Ada programming systems where the whole Ada 
program appears to the OS as a single OS thread so that one Ada task 
waiting on a blocking OS call blocks all other tasks in the program.


> Of course you'd need to be careful not to have I/O calls from
> separate tasks interfere with each other.

Yes, but other tasks should be able to output text through 
Standard_Output even while one task is reading Standard_Input using a 
blocking I/O call. Except under a one-thread run-time system.

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: get_immediate echoe character--compiled error?
  2023-10-04 21:14 ` Jeffrey R.Carter
@ 2023-10-04 22:12   ` Keith Thompson
  2023-10-05  9:51     ` Jeffrey R.Carter
  0 siblings, 1 reply; 21+ messages in thread
From: Keith Thompson @ 2023-10-04 22:12 UTC (permalink / raw)


"Jeffrey R.Carter" <spam.jrcarter.not@spam.acm.org.not> writes:
> 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.

On what target system?

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: get_immediate echoe character--compiled error?
  2023-10-04 13:05                     ` Jeffrey R.Carter
@ 2023-10-05  0:43                       ` Randy Brukardt
  0 siblings, 0 replies; 21+ messages in thread
From: Randy Brukardt @ 2023-10-05  0:43 UTC (permalink / raw)


"Jeffrey R.Carter" <spam.jrcarter.not@spam.acm.org.not> wrote in message 
news:ufjnu0$62ki$1@dont-email.me...
> 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.

For what it's worth, Janus/Ada turns off echoing, and that was decided 
without referring to any other implementation's choice in the matter. 
Rather, it was done to provide a way using standard calls to provide 
functionality that had always been available in Janus/Ada in a non-standard 
way.

Specifically, Janus/Ada has always had a predefined file name "KBD:" (or 
"/dev/kbd" on Unix), which provides raw access to the keyboard device (or 
standard input on more modern systems). This did not echo (or do any line 
editing) on CP/M and MS-DOS, and we carried that same behavior over into 
more modern systems.

For instance, the "Continue or Abort?" question in the compiler uses KBD: to 
take and discard input immediately without any waiting (usual standard input 
is line buffered and usually input is not processed until "enter" or similar 
is pressed). It seemed to us that the Get_Immediate function was intending 
the same sorts of uses. Note that implementing it this way makes it hard to 
get meaningful results if Get_Immediate is mixed with other input on the 
same file. (That's why we treated it as a special file in the beginning, but 
even that gets confused if someone else reads from Standard_Input.)

                                  Randy. 


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: get_immediate echoe character--compiled error?
  2023-10-04 22:12   ` Keith Thompson
@ 2023-10-05  9:51     ` Jeffrey R.Carter
  0 siblings, 0 replies; 21+ messages in thread
From: Jeffrey R.Carter @ 2023-10-05  9:51 UTC (permalink / raw)


On 2023-10-05 00:12, Keith Thompson wrote:
> "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?

Windows.

-- 
Jeff Carter
"You cheesy lot of second-hand electric donkey-bottom biters."
Monty Python & the Holy Grail
14

^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2023-10-05  9:51 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-02  2:42 get_immediate echoe character--compiled error? richardthiebaud
2023-10-02  5:48 ` Keith Thompson
2023-10-02 20:07   ` richardthiebaud
2023-10-02 22:27     ` Keith Thompson
2023-10-02 22:41       ` richardthiebaud
2023-10-02 22:47       ` richardthiebaud
2023-10-03  8:41         ` Niklas Holsti
2023-10-03 10:20           ` Simon Wright
2023-10-04  0:13             ` Keith Thompson
2023-10-04  8:22               ` Simon Wright
2023-10-04 10:48                 ` Jeffrey R.Carter
2023-10-04 11:38                   ` Simon Wright
2023-10-04 13:05                     ` Jeffrey R.Carter
2023-10-05  0:43                       ` Randy Brukardt
2023-10-04 16:55                 ` Niklas Holsti
2023-10-04 19:39                   ` Keith Thompson
2023-10-04 21:20                     ` Niklas Holsti
2023-10-03 21:00 ` G.B.
2023-10-04 21:14 ` Jeffrey R.Carter
2023-10-04 22:12   ` Keith Thompson
2023-10-05  9:51     ` Jeffrey R.Carter

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