From mboxrd@z Thu Jan 1 00:00:00 1970 Path: eternal-september.org!news.eternal-september.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: get_immediate echoe character--compiled error? Date: Thu, 5 Oct 2023 00:20:05 +0300 Organization: Tidorum Ltd Message-ID: References: <87fs2tr2vf.fsf@nosuchdomain.example.com> <87lecku0bu.fsf@nosuchdomain.example.com> <874jj75joi.fsf@nosuchdomain.example.com> <87v8bm41ow.fsf@nosuchdomain.example.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net E+2iktha7TqLRkp5tqCHOwMEs/SO2D/h+j/jB8zkatBa9EP1n+ Cancel-Lock: sha1:uqFg2Wg56BvyC91gdqygHcJxbg8= sha256:gFFK94md5HWgpQPlbWNRyM6HGdcZ+reQkzaoXzXuT2M= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Content-Language: en-US In-Reply-To: <87v8bm41ow.fsf@nosuchdomain.example.com> Xref: news.eternal-september.org comp.lang.ada:65785 List-Id: On 2023-10-04 22:39, Keith Thompson wrote: > Niklas Holsti writes: >> On 2023-10-04 11:22, Simon Wright wrote: >>> Keith Thompson writes: >>>> Simon Wright 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.