• get_immediate echoe character--compiled error?

    From richardthiebaud@21:1/5 to All on Sun Oct 1 22:42:39 2023
    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);

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Keith Thompson@21:1/5 to richardthiebaud on Sun Oct 1 22:48:36 2023
    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 */

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From richardthiebaud@21:1/5 to Keith Thompson on Mon Oct 2 16:07:49 2023
    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);



    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Keith Thompson@21:1/5 to richardthiebaud on Mon Oct 2 15:27:33 2023
    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 */

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From richardthiebaud@21:1/5 to Keith Thompson on Mon Oct 2 18:47:03 2023
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From richardthiebaud@21:1/5 to Keith Thompson on Mon Oct 2 18:41:46 2023
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Niklas Holsti@21:1/5 to richardthiebaud on Tue Oct 3 11:41:05 2023
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Simon Wright@21:1/5 to Niklas Holsti on Tue Oct 3 11:20:40 2023
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From G.B.@21:1/5 to richardthiebaud on Tue Oct 3 23:00:40 2023
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Keith Thompson@21:1/5 to Simon Wright on Tue Oct 3 17:13:17 2023
    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 */

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Simon Wright@21:1/5 to Keith Thompson on Wed Oct 4 09:22:05 2023
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jeffrey R.Carter@21:1/5 to Simon Wright on Wed Oct 4 12:48:41 2023
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Simon Wright@21:1/5 to Jeffrey R.Carter on Wed Oct 4 12:38:51 2023
    "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?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jeffrey R.Carter@21:1/5 to Simon Wright on Wed Oct 4 15:05:03 2023
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Niklas Holsti@21:1/5 to Simon Wright on Wed Oct 4 19:55:51 2023
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Keith Thompson@21:1/5 to Niklas Holsti on Wed Oct 4 12:39:27 2023
    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 */

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jeffrey R.Carter@21:1/5 to richardthiebaud on Wed Oct 4 23:14:11 2023
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Keith Thompson@21:1/5 to Jeffrey R.Carter on Wed Oct 4 15:12:39 2023
    "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 */

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Niklas Holsti@21:1/5 to Keith Thompson on Thu Oct 5 00:20:05 2023
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Randy Brukardt@21:1/5 to Jeffrey R.Carter on Wed Oct 4 19:43:55 2023
    "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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jeffrey R.Carter@21:1/5 to Keith Thompson on Thu Oct 5 11:51:15 2023
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)